Skip to content

Commit 93cdecb

Browse files
authored
Scantool resource list feature (#803)
1 parent 544605c commit 93cdecb

27 files changed

+1045
-558
lines changed

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

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

3+
import net.minecraft.network.FriendlyByteBuf;
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 FriendlyByteBuf buf)
98+
{
99+
this.stack = buf.readItem();
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
{
@@ -190,4 +214,16 @@ public int getDamageValue()
190214
{
191215
return stack.getDamageValue();
192216
}
217+
218+
/**
219+
* Serialize itemstorage to buffer
220+
* @param buf
221+
*/
222+
public void serialize(final FriendlyByteBuf buf)
223+
{
224+
buf.writeItem(getItemStack());
225+
buf.writeBoolean(ignoreDamageValue());
226+
buf.writeBoolean(ignoreNBTValue());
227+
buf.writeInt(getAmount());
228+
}
193229
}

src/api/java/com/ldtteam/structurize/api/util/constant/WindowConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ public final class WindowConstants
317317
*/
318318
public static final String REMOVE_FILTERED = "removefiltered";
319319

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

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
import com.ldtteam.blockui.Color;
66
import com.ldtteam.blockui.Pane;
77
import com.ldtteam.blockui.PaneBuilders;
8-
import com.ldtteam.blockui.controls.ButtonImage;
9-
import com.ldtteam.blockui.controls.Gradient;
10-
import com.ldtteam.blockui.controls.Image;
11-
import com.ldtteam.blockui.controls.ImageRepeatable;
12-
import com.ldtteam.blockui.controls.Text;
13-
import com.ldtteam.blockui.controls.TextFieldVanilla;
14-
import com.ldtteam.blockui.controls.TextField.Filter;
8+
import com.ldtteam.blockui.controls.*;
159
import com.ldtteam.blockui.views.ScrollingList;
1610
import com.ldtteam.blockui.views.View;
1711
import com.ldtteam.structurize.Structurize;
@@ -30,7 +24,7 @@
3024
import net.minecraft.ChatFormatting;
3125
import net.minecraft.client.Minecraft;
3226
import net.minecraft.core.BlockPos;
33-
import net.minecraft.network.chat.*;
27+
import net.minecraft.network.chat.Component;
3428
import net.minecraft.network.chat.contents.TranslatableContents;
3529
import net.minecraft.resources.ResourceLocation;
3630
import net.minecraft.util.Tuple;
@@ -42,11 +36,14 @@
4236
import org.jetbrains.annotations.NotNull;
4337
import org.jetbrains.annotations.Nullable;
4438

45-
import java.util.*;
39+
import java.util.ArrayList;
40+
import java.util.List;
41+
import java.util.Optional;
4642

4743
import static com.ldtteam.structurize.api.util.constant.Constants.*;
4844
import static com.ldtteam.structurize.api.util.constant.GUIConstants.*;
4945
import static com.ldtteam.structurize.api.util.constant.WindowConstants.*;
46+
import static com.ldtteam.structurize.client.gui.util.InputFilters.ONLY_NUMBERS;
5047

5148
/**
5249
* BuildTool window.
@@ -391,20 +388,7 @@ else if (setting.get() instanceof final Number value)
391388
buttonImage.off();
392389
inputField.on();
393390
inputField.setText(typedSetting.get().toString());
394-
inputField.setFilter(new Filter()
395-
{
396-
@Override
397-
public String filter(final String s)
398-
{
399-
return s;
400-
}
401-
402-
@Override
403-
public boolean isAllowedCharacter(final char c)
404-
{
405-
return Character.isDigit(c) || c == '-' || c == '.';
406-
}
407-
});
391+
inputField.setFilter(ONLY_NUMBERS);
408392
inputField.setHandler(a -> {
409393
if (inputField.getText().isBlank())
410394
{

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.util.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
*

0 commit comments

Comments
 (0)