Skip to content

Commit 65b9ff8

Browse files
committed
address review
1 parent 33bd4f8 commit 65b9ff8

File tree

7 files changed

+26
-40
lines changed

7 files changed

+26
-40
lines changed

src/main/java/gregtech/api/items/IDyeableItem.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616

1717
public interface IDyeableItem {
1818

19+
String COLOR_KEY = "gt_color";
20+
1921
default boolean hasColor(ItemStack stack) {
2022
NBTTagCompound nbttagcompound = stack.getTagCompound();
21-
return nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT);
23+
return nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY, Constants.NBT.TAG_INT);
2224
}
2325

2426
default int getColor(ItemStack stack) {
2527
NBTTagCompound nbttagcompound = stack.getTagCompound();
26-
if (nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT)) {
27-
return nbttagcompound.getInteger("color");
28+
if (nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY, Constants.NBT.TAG_INT)) {
29+
return nbttagcompound.getInteger(COLOR_KEY);
2830
}
2931
return getDefaultColor(stack);
3032
}
@@ -35,8 +37,8 @@ default int getDefaultColor(ItemStack stack) {
3537

3638
default void removeColor(ItemStack stack) {
3739
NBTTagCompound nbttagcompound = stack.getTagCompound();
38-
if (nbttagcompound != null && nbttagcompound.hasKey("color")) {
39-
nbttagcompound.removeTag("color");
40+
if (nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY)) {
41+
nbttagcompound.removeTag(COLOR_KEY);
4042
}
4143
}
4244

@@ -46,7 +48,7 @@ default void setColor(ItemStack stack, int color) {
4648
nbttagcompound = new NBTTagCompound();
4749
stack.setTagCompound(nbttagcompound);
4850
}
49-
nbttagcompound.setInteger("color", color);
51+
nbttagcompound.setInteger(COLOR_KEY, color);
5052
}
5153

5254
default @NotNull EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,

src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@
5858
import com.google.common.collect.ImmutableSet;
5959
import com.google.common.collect.Multimap;
6060
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
61+
import org.jetbrains.annotations.ApiStatus;
6162
import org.jetbrains.annotations.NotNull;
6263
import org.jetbrains.annotations.Nullable;
6364
import org.jetbrains.annotations.Range;
6465

6566
import java.util.ArrayList;
66-
import java.util.Arrays;
6767
import java.util.Collections;
6868
import java.util.HashSet;
6969
import java.util.List;
70-
import java.util.Objects;
7170
import java.util.Set;
7271
import java.util.function.IntSupplier;
7372
import java.util.function.Supplier;
@@ -76,8 +75,6 @@
7675

7776
public class ItemGTToolbelt extends ItemGTTool implements IDyeableItem {
7877

79-
protected final static Set<String> VALID_OREDICTS = new ObjectOpenHashSet<>();
80-
8178
public ItemGTToolbelt(String domain, String id, Supplier<ItemStack> markerItem, IToolBehavior... behaviors) {
8279
super(domain, id, -1,
8380
new ToolDefinitionBuilder().behaviors(behaviors).cannotAttack().attackSpeed(-2.4F).build(),
@@ -153,14 +150,6 @@ else if (selected.getItem() instanceof IGTTool tool) {
153150
} else return Collections.emptyList();
154151
}
155152

156-
public static boolean isToolbeltableOredict(String oredict) {
157-
return VALID_OREDICTS.contains(oredict);
158-
}
159-
160-
public void registerValidOredict(String oredict) {
161-
VALID_OREDICTS.add(oredict);
162-
}
163-
164153
@Override
165154
public float getDestroySpeed(@NotNull ItemStack stack, @NotNull IBlockState state) {
166155
ItemStack selected = getHandler(stack).getSelectedStack();
@@ -220,7 +209,7 @@ public int getHarvestLevel(@NotNull ItemStack stack, @NotNull String toolClass,
220209
ItemStack selected = getHandler(stack).getSelectedStack();
221210
if (!selected.isEmpty()) {
222211
return selected.getItem().getHarvestLevel(stack, toolClass, player, blockState);
223-
} else return super.getHarvestLevel(stack, toolClass, player, blockState);
212+
} else return definition$getHarvestLevel(stack, toolClass, player, blockState);
224213
}
225214

226215
@NotNull
@@ -283,7 +272,7 @@ public int getDamage(@NotNull ItemStack stack) {
283272
ItemStack selected = getHandler(stack).getSelectedStack();
284273
if (!selected.isEmpty()) {
285274
return selected.getItem().getDamage(selected);
286-
} else return super.getDamage(stack);
275+
} else return definition$getDamage(stack);
287276
}
288277

289278
@Override
@@ -299,7 +288,7 @@ public void setDamage(@NotNull ItemStack stack, int damage) {
299288
ItemStack selected = getHandler(stack).getSelectedStack();
300289
if (!selected.isEmpty()) {
301290
selected.getItem().setDamage(selected, damage);
302-
} else super.setDamage(stack, damage);
291+
} else definition$setDamage(stack, damage);
303292
}
304293

305294
@Override
@@ -442,6 +431,10 @@ public void changeSelectedToolHotkey(int slot, ItemStack stack) {
442431
new PacketToolbeltSelectionChange(handler.selectedSlot));
443432
}
444433

434+
/**
435+
* For use by {@link PacketToolbeltSelectionChange} only!
436+
*/
437+
@ApiStatus.Internal
445438
public void setSelectedTool(int slot, ItemStack stack) {
446439
ToolStackHandler handler = getHandler(stack);
447440
if (slot < 0 || slot >= handler.getSlots())
@@ -471,7 +464,8 @@ public void setSelectedTool(int slot, ItemStack stack) {
471464
if (result == EnumActionResult.PASS) {
472465
ItemStack stack = player.getHeldItem(hand);
473466
ToolStackHandler handler = getHandler(stack);
474-
if (handler.getSelectedSlot() == -1 && world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
467+
if (handler.getSelectedStack().isEmpty() &&
468+
world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
475469
holder.getMetaTileEntity() instanceof MetaTileEntityMaintenanceHatch maintenance) {
476470
maintenance.fixMaintenanceProblemsWithToolbelt(player, this, stack);
477471
return EnumActionResult.SUCCESS;
@@ -573,10 +567,8 @@ public NBTTagCompound serializeNBT() {
573567

574568
@Override
575569
public void deserializeNBT(NBTTagCompound nbt) {
576-
// make sure we can load all the slots, no matter what we're supposed to be limited to.
577-
int minsize = nbt.hasKey("Size") ? nbt.getInteger("Size") : 0;
578570
// .copy() prevents double damage ticks in singleplayer
579-
this.getHandler(minsize).deserializeNBT(nbt.copy());
571+
this.getHandler(slotCountSupplier.getAsInt()).deserializeNBT(nbt.copy());
580572
}
581573

582574
protected ToolStackHandler getHandler(int minsize) {
@@ -611,7 +603,6 @@ protected static class ToolStackHandler extends ItemStackHandler {
611603
protected final ItemTool[] tools = new ItemTool[this.getSlots()];
612604
protected final IGTTool[] gtTools = new IGTTool[this.getSlots()];
613605
protected final Set<String> toolClasses = new ObjectOpenHashSet<>();
614-
public final Set<String> oreDicts = new ObjectOpenHashSet<>();
615606

616607
private boolean passthrough = true;
617608

@@ -646,7 +637,7 @@ public void disablePassthrough() {
646637

647638
public @NotNull ItemStack getSelectedStack() {
648639
if (getSelectedSlot() == -1) return ItemStack.EMPTY;
649-
else return this.stacks.get(getSelectedSlot());
640+
else return this.getStackInSlot(getSelectedSlot());
650641
}
651642

652643
public Set<String> getToolClasses(boolean defaultEmpty) {
@@ -715,14 +706,6 @@ protected void updateSlot(int slot) {
715706
}
716707

717708
protected void update() {
718-
this.oreDicts.clear();
719-
Arrays.stream(gtTools).filter(Objects::nonNull).map(igtTool -> {
720-
Set<String> set = new ObjectOpenHashSet<>(igtTool.getSecondaryOreDicts());
721-
set.add(igtTool.getOreDictName());
722-
return set;
723-
}).forEach(this.oreDicts::addAll);
724-
this.oreDicts.retainAll(VALID_OREDICTS);
725-
726709
this.toolClasses.clear();
727710
for (int i = 0; i < this.getSlots(); i++) {
728711
if (tools[i] != null) this.toolClasses.addAll(tools[i].getToolClasses(stacks.get(i)));

src/main/java/gregtech/client/ClientProxy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ public static void onMouseEvent(@NotNull MouseEvent event) {
354354
if (event.getDwheel() != 0 && player.isSneaking()) {
355355
ItemStack stack = player.getHeldItemMainhand();
356356
if (stack.getItem() instanceof ItemGTToolbelt toolbelt) {
357+
// vanilla code in GuiIngame line 1235 does not copy the stack before storing it in the highlighting
358+
// item stack, so unless we copy the stack the tool highlight will not refresh.
357359
stack = stack.copy();
358360
toolbelt.changeSelectedToolMousewheel(event.getDwheel(), stack);
359361
InventoryPlayer inv = Minecraft.getMinecraft().player.inventory;

src/main/java/gregtech/common/crafting/DyeableRecipes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public boolean matches(InventoryCrafting inv, @NotNull World worldIn) {
120120
k1 = (int) ((float) k1 * f3 / f4);
121121
int k2 = (i1 << 8) + j1;
122122
k2 = (k2 << 8) + k1;
123+
// prevent consuming dye when the color would not change
124+
if (dyeable.hasColor(itemstack) && dyeable.getColor(itemstack) == k2) return ItemStack.EMPTY;
123125
dyeable.setColor(itemstack, k2);
124126
return itemstack;
125127
}

src/main/java/gregtech/common/crafting/GTShapedOreRecipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ else if (obj instanceof String str) {
166166
if (isClearing) {
167167
return NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
168168
} else {
169-
return net.minecraftforge.common.ForgeHooks.defaultRecipeGetRemainingItems(inv);
169+
return super.getRemainingItems(inv);
170170
}
171171
}
172172
}

src/main/java/gregtech/common/crafting/GTShapelessOreRecipe.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.minecraft.item.crafting.Ingredient;
66
import net.minecraft.util.NonNullList;
77
import net.minecraft.util.ResourceLocation;
8-
import net.minecraftforge.common.ForgeHooks;
98
import net.minecraftforge.oredict.ShapelessOreRecipe;
109

1110
import org.jetbrains.annotations.NotNull;
@@ -39,7 +38,7 @@ public GTShapelessOreRecipe(boolean isClearing, ResourceLocation group, @NotNull
3938
if (isClearing) {
4039
return NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
4140
} else {
42-
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
41+
return super.getRemainingItems(inv);
4342
}
4443
}
4544
}

src/main/java/gregtech/common/items/ToolItems.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,9 @@ public static void registerOreDict() {
393393
final ItemStack stack = new ItemStack(tool.get(), 1, GTValues.W);
394394
if (tool.getOreDictName() != null) {
395395
OreDictUnifier.registerOre(stack, tool.getOreDictName());
396-
TOOLBELT.registerValidOredict(tool.getOreDictName());
397396
}
398397
tool.getSecondaryOreDicts().forEach(oreDict -> {
399398
OreDictUnifier.registerOre(stack, oreDict);
400-
TOOLBELT.registerValidOredict(oreDict);
401399
});
402400
});
403401
}

0 commit comments

Comments
 (0)