Skip to content

Commit 684bda3

Browse files
committed
Scantool resource list feature (#803)
1 parent 3c8231a commit 684bda3

29 files changed

+1144
-565
lines changed

src/main/java/com/ldtteam/structurize/api/ItemStackUtils.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.core.component.DataComponentType;
88
import net.minecraft.core.component.DataComponents;
99
import net.minecraft.nbt.CompoundTag;
10+
import net.minecraft.network.RegistryFriendlyByteBuf;
1011
import net.minecraft.world.Container;
1112
import net.minecraft.world.entity.Entity;
1213
import net.minecraft.world.entity.decoration.ItemFrame;
@@ -21,7 +22,11 @@
2122
import net.neoforged.neoforge.items.IItemHandler;
2223
import net.neoforged.neoforge.items.wrapper.InvWrapper;
2324
import org.jetbrains.annotations.Nullable;
24-
import java.util.*;
25+
26+
import java.util.ArrayList;
27+
import java.util.HashSet;
28+
import java.util.List;
29+
import java.util.Set;
2530
import java.util.function.Consumer;
2631

2732
/**
@@ -379,4 +384,34 @@ public static boolean compareItemStacksIgnoreStackSize(
379384
}
380385
return false;
381386
}
387+
388+
/**
389+
* Item serializer helper, including air
390+
*
391+
* @param stack
392+
* @param buf
393+
*/
394+
public static void serializeToBuffer(final ItemStack stack, RegistryFriendlyByteBuf buf)
395+
{
396+
buf.writeBoolean(stack.isEmpty());
397+
if (!stack.isEmpty())
398+
{
399+
ItemStack.STREAM_CODEC.encode(buf, stack);
400+
}
401+
}
402+
403+
/**
404+
* Item deserializer helper, including air. Must be serialized with the above util
405+
*
406+
* @param buf
407+
*/
408+
public static ItemStack deserializeFromBuffer(RegistryFriendlyByteBuf buf)
409+
{
410+
if (!buf.readBoolean())
411+
{
412+
return ItemStack.STREAM_CODEC.decode(buf);
413+
}
414+
415+
return ItemStack.EMPTY;
416+
}
382417
}

src/main/java/com/ldtteam/structurize/api/ItemStorage.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ldtteam.structurize.api;
22

3+
import net.minecraft.network.RegistryFriendlyByteBuf;
34
import net.minecraft.world.item.Item;
45
import net.minecraft.world.item.ItemStack;
56

@@ -39,11 +40,11 @@ public class ItemStorage
3940
* @param amount the amount.
4041
* @param ignoreDamageValue should the damage value be ignored?
4142
*/
42-
public ItemStorage(final ItemStack stack, final int amount, final boolean ignoreDamageValue)
43+
public ItemStorage(final ItemStack stack, final int amount, final boolean ignoreDamageValue, final boolean shouldIgnoreNBTValue)
4344
{
4445
this.stack = stack;
4546
this.shouldIgnoreDamageValue = ignoreDamageValue;
46-
this.shouldIgnoreNBTValue = ignoreDamageValue;
47+
this.shouldIgnoreNBTValue = shouldIgnoreNBTValue;
4748
this.amount = amount;
4849
}
4950

@@ -88,6 +89,19 @@ public ItemStorage(final ItemStack stack)
8889
this.amount = ItemStackUtils.getSize(stack);
8990
}
9091

92+
/**
93+
* Reads an itemstorage from a buffer
94+
*
95+
* @param buf
96+
*/
97+
public ItemStorage(final RegistryFriendlyByteBuf buf)
98+
{
99+
this.stack = ItemStackUtils.deserializeFromBuffer(buf);
100+
this.shouldIgnoreDamageValue = buf.readBoolean();
101+
this.shouldIgnoreNBTValue = buf.readBoolean();
102+
this.amount = buf.readInt();
103+
}
104+
91105
/**
92106
* Check a list for an ItemStack matching a predicate.
93107
*
@@ -147,6 +161,16 @@ public boolean ignoreDamageValue()
147161
return shouldIgnoreDamageValue;
148162
}
149163

164+
/**
165+
* Getter for the should ignore nbt.
166+
*
167+
* @return true if should ignore.
168+
*/
169+
public boolean ignoreNBTValue()
170+
{
171+
return shouldIgnoreNBTValue;
172+
}
173+
150174
@Override
151175
public int hashCode()
152176
{
@@ -191,6 +215,19 @@ public int getDamageValue()
191215
return stack.getDamageValue();
192216
}
193217

218+
/**
219+
* Serialize itemstorage to buffer
220+
*
221+
* @param buf
222+
*/
223+
public void serialize(final RegistryFriendlyByteBuf buf)
224+
{
225+
ItemStackUtils.serializeToBuffer(getItemStack(), buf);
226+
buf.writeBoolean(ignoreDamageValue());
227+
buf.writeBoolean(ignoreNBTValue());
228+
buf.writeInt(getAmount());
229+
}
230+
194231
/**
195232
* Adder for the quantity.
196233
*

src/main/java/com/ldtteam/structurize/api/constants/WindowConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,21 @@ public final class WindowConstants
319319

320320
public static final String BUTTON_CONTENTS = "contents";
321321

322+
/**
323+
* Display visible blocks checkbox
324+
*/
325+
public static final String VISIBLE_CHECKBOX = "showvisisble";
326+
327+
/**
328+
* Display hidden blocks checkbox
329+
*/
330+
public static final String HIDDEN_CHECKBOX = "showhidden";
331+
332+
/**
333+
* Shows the block in the world button
334+
*/
335+
public static final String BUTTON_SHOWBLOCK = "showBlock";
336+
322337
/**
323338
* public constructor to hide implicit public one.
324339
*/

src/main/java/com/ldtteam/structurize/client/gui/AbstractBlueprintManipulationWindow.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.ldtteam.blockui.controls.Image;
88
import com.ldtteam.blockui.controls.Text;
99
import com.ldtteam.blockui.controls.TextFieldVanilla;
10-
import com.ldtteam.blockui.controls.TextField.Filter;
1110
import com.ldtteam.blockui.views.BOWindow;
1211
import com.ldtteam.blockui.views.ScrollingList;
1312
import com.ldtteam.structurize.Structurize;
@@ -26,7 +25,7 @@
2625
import net.minecraft.ChatFormatting;
2726
import net.minecraft.client.Minecraft;
2827
import net.minecraft.core.BlockPos;
29-
import net.minecraft.network.chat.*;
28+
import net.minecraft.network.chat.Component;
3029
import net.minecraft.network.chat.contents.TranslatableContents;
3130
import net.minecraft.util.Tuple;
3231
import net.minecraft.world.level.block.Mirror;
@@ -37,11 +36,13 @@
3736
import org.jetbrains.annotations.NotNull;
3837
import org.jetbrains.annotations.Nullable;
3938

40-
import java.util.*;
39+
import java.util.ArrayList;
40+
import java.util.List;
4141

4242
import static com.ldtteam.structurize.api.constants.Constants.*;
4343
import static com.ldtteam.structurize.api.constants.GUIConstants.*;
4444
import static com.ldtteam.structurize.api.constants.WindowConstants.*;
45+
import static com.ldtteam.structurize.client.gui.util.InputFilters.ONLY_NUMBERS;
4546

4647
/**
4748
* BuildTool window.
@@ -379,20 +380,7 @@ else if (setting.get() instanceof Number)
379380
buttonImage.off();
380381
inputField.on();
381382
inputField.setText(typedSetting.get().toString());
382-
inputField.setFilter(new Filter()
383-
{
384-
@Override
385-
public String filter(final String s)
386-
{
387-
return s;
388-
}
389-
390-
@Override
391-
public boolean isAllowedCharacter(final char c)
392-
{
393-
return Character.isDigit(c) || c == '-' || c == '.';
394-
}
395-
});
383+
inputField.setFilter(ONLY_NUMBERS);
396384
inputField.setHandler(a -> {
397385
if (inputField.getText().isBlank())
398386
{

src/main/java/com/ldtteam/structurize/client/gui/AbstractWindowSkeleton.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ldtteam.structurize.client.gui;
22

3-
import com.ldtteam.blockui.controls.*;
3+
import com.ldtteam.blockui.controls.Button;
4+
import com.ldtteam.blockui.controls.ButtonHandler;
45
import com.ldtteam.blockui.views.BOWindow;
56
import com.ldtteam.structurize.api.Log;
67
import net.minecraft.resources.ResourceLocation;
@@ -26,6 +27,17 @@ public AbstractWindowSkeleton(final String resource)
2627
buttons = new HashMap<>();
2728
}
2829

30+
/**
31+
* Constructor for the skeleton class of the windows.
32+
*
33+
* @param resource Resource location
34+
*/
35+
public AbstractWindowSkeleton(final ResourceLocation resource)
36+
{
37+
super(resource);
38+
buttons = new HashMap<>();
39+
}
40+
2941
/**
3042
* Register a button on the window.
3143
*

src/main/java/com/ldtteam/structurize/client/gui/WindowBlockGetterContents.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
import net.minecraft.world.level.block.entity.BlockEntity;
2222
import net.minecraft.world.level.block.state.BlockState;
2323
import org.jetbrains.annotations.Nullable;
24-
import java.util.ArrayList;
25-
import java.util.Collection;
26-
import java.util.Comparator;
27-
import java.util.HashMap;
28-
import java.util.List;
29-
import java.util.Map;
24+
25+
import java.util.*;
3026

3127
/**
3228
* Computes as exact as possible contents of given AABB. This should be used as base for item related analysis
@@ -117,7 +113,7 @@ private void addAmountToMap(final Map<Item, ItemStorage> itemSet, @Nullable fina
117113
{
118114
if (blockAsItem != null)
119115
{
120-
itemSet.computeIfAbsent(blockAsItem.getItem(), i -> new ItemStorage(blockAsItem.copyWithCount(1), 0, true))
116+
itemSet.computeIfAbsent(blockAsItem.getItem(), i -> new ItemStorage(blockAsItem.copyWithCount(1), 0, true, true))
121117
.addAmount(Math.max(1, blockAsItem.getCount()));
122118
}
123119
}

0 commit comments

Comments
 (0)