Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public WindowReplaceBlock(
super(origin,
Component.translatable("com.ldtteam.structurize.gui.replaceblock.info"),
toReplace.itemStorage.getItemStack(),
ItemUtil.getAllItems(),
ItemUtil.getAllItemsInlcudingInventory(),
((stack, integer) -> {}),
true,
Component.translatable("com.ldtteam.structurize.gui.scan.replace.pct"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,15 @@ private void updateResources()

if (filter.isEmpty())
{
displayedItems.sort(Comparator.comparing(s1 -> s1.getHoverName().getString()));
displayedItems.sort(Comparator.comparing(s -> mc.player.getInventory().contains((ItemStack) s))
.reversed()
.thenComparing((s1 -> ((ItemStack) s1).getHoverName().getString())));
}
else
{
displayedItems.sort(Comparator.comparingInt(s1 -> StringUtils.getLevenshteinDistance(s1.getHoverName().getString(), filter)));
displayedItems.sort(Comparator.comparing(s -> mc.player.getInventory().contains((ItemStack) s))
.reversed()
.thenComparingInt(s1 -> StringUtils.getLevenshteinDistance(((ItemStack) s1).getHoverName().getString(), filter)));
}
this.updateResourceList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,27 @@ else if (shape != Shape.WAVE && shape != Shape.WAVE_3D)
*/
private void pickMainBlock()
{
new WindowSelectRes(this, Component.literal("Select the main block"), mainBlock, ItemUtil.getAllItems(), (s, c) -> updateBlock(s, true), false, null).open();
new WindowSelectRes(this,
Component.literal("Select the main block"),
mainBlock,
ItemUtil.getAllItemsInlcudingInventory(),
(s, c) -> updateBlock(s, true),
false,
null).open();
}

/**
* Opens the block picker window.
*/
private void pickFillBlock()
{
new WindowSelectRes(this, Component.literal("Select the main block"), secondaryBlock, ItemUtil.getAllItems(), (s, c) -> updateBlock(s, false), false, null).open();
new WindowSelectRes(this,
Component.literal("Select the main block"),
secondaryBlock,
ItemUtil.getAllItemsInlcudingInventory(),
(s, c) -> updateBlock(s, false),
false,
null).open();
}

private void adjust(final TextField input, final int value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.ldtteam.structurize.client.gui.util;

import com.google.common.collect.ImmutableList;
import net.minecraft.world.item.AirItem;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.ItemStack;
import com.ldtteam.structurize.api.util.ItemStorage;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.*;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
* Client-side Item utility class
*/
public class ItemUtil
{
/**
Expand All @@ -29,4 +29,42 @@ public static List<ItemStack> getAllItems()
.map(ItemStack::new)
.collect(Collectors.toList()));
}

/**
* Creates a list of all items that can be picked inlcuding player items
* Client-side
*
* @return
*/
public static List<ItemStack> getAllItemsInlcudingInventory()
{
final Set<ItemStorage> items = new HashSet<>();
for (final Item item : ForgeRegistries.ITEMS)
{
if (item instanceof AirItem || item instanceof BlockItem || (item instanceof BucketItem
&& ((BucketItem) item).getFluid() != Fluids.EMPTY))
{
items.add(new ItemStorage(new ItemStack(item)));
}
}

for (final ItemStack stack : Minecraft.getInstance().player.getInventory().items)
{
final Item item = stack.getItem();
if (item instanceof AirItem || item instanceof BlockItem || (item instanceof BucketItem
&& ((BucketItem) item).getFluid() != Fluids.EMPTY))
{
items.add(new ItemStorage(stack.copy()));
}
}

final List<ItemStack> stackList = new ArrayList<>(items.size());

for (final ItemStorage storage : items)
{
stackList.add(storage.getItemStack());
}

return stackList;
}
}