Skip to content

Commit 7026131

Browse files
committed
Merge branch 'master' into zb/multiblock-active-mode-mui2
2 parents e6bfb31 + 012de01 commit 7026131

File tree

84 files changed

+3186
-1714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3186
-1714
lines changed

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies {
4242
api("codechicken:codechickenlib:3.2.3.358")
4343
api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false }
4444
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
45+
api("curse.maven:inventory-bogosorter-632327:4951607-deobf-4951608-sources-4951609")
4546
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")
4647
api("appeng:ae2-uel:v0.56.4") { transitive = false }
4748
api rfg.deobf("curse.maven:ctm-267602:2915363") // CTM 1.0.2.31

src/main/java/gregtech/api/capability/GregtechDataCodes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public static int assignId() {
4646
// Misc TEs (Transformer, World Accelerator)
4747
public static final int SYNC_TILE_MODE = assignId();
4848

49+
// Crafting Station
50+
public static final int UPDATE_CLIENT_HANDLER = assignId();
51+
4952
// Clipboard
5053
public static final int CREATE_FAKE_UI = assignId();
5154
public static final int MOUSE_POSITION = assignId();

src/main/java/gregtech/api/capability/IQuantumController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public interface IQuantumController extends ICapabilityProvider {
3030

3131
long getTypeEnergy(IQuantumStorage<?> storage);
3232

33-
void updateHandler();
33+
void onHandlerUpdate();
3434
}

src/main/java/gregtech/api/capability/impl/ItemHandlerList.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
88
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
9+
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
10+
import it.unimi.dsi.fastutil.objects.Object2IntMap;
911
import org.jetbrains.annotations.NotNull;
1012

1113
import java.util.*;
@@ -16,7 +18,7 @@
1618
public class ItemHandlerList implements IItemHandlerModifiable {
1719

1820
private final Int2ObjectMap<IItemHandler> handlerBySlotIndex = new Int2ObjectOpenHashMap<>();
19-
private final Map<IItemHandler, Integer> baseIndexOffset = new IdentityHashMap<>();
21+
private final Object2IntMap<IItemHandler> baseIndexOffset = new Object2IntArrayMap<>();
2022

2123
public ItemHandlerList(List<? extends IItemHandler> itemHandlerList) {
2224
int currentSlotIndex = 0;
@@ -33,43 +35,55 @@ public ItemHandlerList(List<? extends IItemHandler> itemHandlerList) {
3335
}
3436
}
3537

38+
public int getIndexOffset(IItemHandler handler) {
39+
return baseIndexOffset.getOrDefault(handler, -1);
40+
}
41+
3642
@Override
3743
public int getSlots() {
3844
return handlerBySlotIndex.size();
3945
}
4046

4147
@Override
4248
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
49+
if (invalidSlot(slot)) return;
4350
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
44-
if (!(itemHandler instanceof IItemHandlerModifiable))
45-
throw new UnsupportedOperationException("Handler " + itemHandler + " does not support this method");
46-
((IItemHandlerModifiable) itemHandler).setStackInSlot(slot - baseIndexOffset.get(itemHandler), stack);
51+
int actualSlot = slot - baseIndexOffset.get(itemHandler);
52+
if (itemHandler instanceof IItemHandlerModifiable modifiable) {
53+
modifiable.setStackInSlot(actualSlot, stack);
54+
} else {
55+
itemHandler.extractItem(actualSlot, Integer.MAX_VALUE, false);
56+
itemHandler.insertItem(actualSlot, stack, false);
57+
}
4758
}
4859

4960
@NotNull
5061
@Override
5162
public ItemStack getStackInSlot(int slot) {
63+
if (invalidSlot(slot)) return ItemStack.EMPTY;
5264
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
53-
int realSlot = slot - baseIndexOffset.get(itemHandler);
5465
return itemHandler.getStackInSlot(slot - baseIndexOffset.get(itemHandler));
5566
}
5667

5768
@Override
5869
public int getSlotLimit(int slot) {
70+
if (invalidSlot(slot)) return 0;
5971
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
6072
return itemHandler.getSlotLimit(slot - baseIndexOffset.get(itemHandler));
6173
}
6274

6375
@NotNull
6476
@Override
6577
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
78+
if (invalidSlot(slot)) return stack;
6679
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
6780
return itemHandler.insertItem(slot - baseIndexOffset.get(itemHandler), stack, simulate);
6881
}
6982

7083
@NotNull
7184
@Override
7285
public ItemStack extractItem(int slot, int amount, boolean simulate) {
86+
if (invalidSlot(slot)) return ItemStack.EMPTY;
7387
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
7488
return itemHandler.extractItem(slot - baseIndexOffset.get(itemHandler), amount, simulate);
7589
}
@@ -78,4 +92,8 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
7892
public Collection<IItemHandler> getBackingHandlers() {
7993
return Collections.unmodifiableCollection(handlerBySlotIndex.values());
8094
}
95+
96+
private boolean invalidSlot(int slot) {
97+
return slot < 0 && slot >= this.getSlots();
98+
}
8199
}

src/main/java/gregtech/api/gui/widgets/CraftingStationInputWidgetGroup.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/gregtech/api/items/itemhandlers/GTItemStackHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ public GTItemStackHandler(MetaTileEntity metaTileEntity, NonNullList<ItemStack>
2525
this.metaTileEntity = metaTileEntity;
2626
}
2727

28+
@Override
29+
public void setStackInSlot(int slot, ItemStack stack) {
30+
if (ItemStack.areItemStacksEqual(stack, getStackInSlot(slot)))
31+
return;
32+
33+
super.setStackInSlot(slot, stack);
34+
}
35+
2836
@Override
2937
public void onContentsChanged(int slot) {
30-
super.onContentsChanged(slot);
3138
metaTileEntity.markDirty();
3239
}
3340
}

src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import gregtech.api.unification.material.Materials;
1010
import gregtech.api.unification.material.info.MaterialIconSet;
1111
import gregtech.api.unification.material.properties.DustProperty;
12+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1213
import gregtech.api.unification.material.properties.PropertyKey;
13-
import gregtech.api.unification.material.properties.ToolProperty;
1414
import gregtech.api.unification.material.registry.MaterialRegistry;
1515
import gregtech.api.unification.ore.OrePrefix;
1616
import gregtech.api.unification.stack.UnificationEntry;
@@ -235,7 +235,7 @@ public int getItemBurnTime(@NotNull ItemStack itemStack) {
235235
public boolean isBeaconPayment(@NotNull ItemStack stack) {
236236
Material material = getMaterial(stack);
237237
if (material != null && this.prefix != OrePrefix.ingot && this.prefix != OrePrefix.gem) {
238-
ToolProperty property = material.getProperty(PropertyKey.TOOL);
238+
MaterialToolProperty property = material.getProperty(PropertyKey.TOOL);
239239
return property != null && property.getToolHarvestLevel() >= 2;
240240
}
241241
return false;

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import gregtech.api.unification.material.Material;
1717
import gregtech.api.unification.material.Materials;
1818
import gregtech.api.unification.material.properties.DustProperty;
19+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1920
import gregtech.api.unification.material.properties.PropertyKey;
2021
import gregtech.api.unification.material.properties.ToolProperty;
2122
import gregtech.api.unification.ore.OrePrefix;
@@ -158,6 +159,10 @@ default ItemStack getRaw() {
158159
return stack;
159160
}
160161

162+
/**
163+
* @return A tool made from the given material. The tool property (at least overriding) for the material must be
164+
* set.
165+
*/
161166
default ItemStack get(Material material) {
162167
ItemStack stack = new ItemStack(get());
163168

@@ -178,35 +183,38 @@ default ItemStack get(Material material) {
178183
AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack);
179184

180185
// Set other tool stats (durability)
181-
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);
182-
186+
ToolProperty finalToolProperty = getToolProperty(material);
183187
// Durability formula we are working with:
184188
// Final Durability = (material durability * material durability multiplier) + (tool definition durability *
185189
// definition durability multiplier) - 1
186190
// Subtracts 1 internally since Minecraft treats "0" as a valid durability, but we don't want to display this.
187191

188-
int durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier();
192+
// Tool material modifiers.
193+
int durability = finalToolProperty.getToolDurability() * finalToolProperty.getDurabilityMultiplier();
189194

195+
// Tool type modifiers.
190196
// Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So
191197
// apply the multiplier to the material durability if that would happen
192198
if (toolStats.getBaseDurability(stack) == 0) {
193-
durability *= toolStats.getDurabilityMultiplier(stack);
199+
durability = (int) (durability * toolStats.getDurabilityMultiplier(stack));
194200
} else {
195-
durability += toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack);
201+
durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack));
196202
}
197203

198-
toolTag.setInteger(MAX_DURABILITY_KEY, durability - 1);
204+
durability -= 1; // Finally adjust for MC
205+
toolTag.setInteger(MAX_DURABILITY_KEY, durability);
199206
toolTag.setInteger(DURABILITY_KEY, 0);
200-
if (toolProperty.getUnbreakable()) {
207+
208+
if (finalToolProperty.getUnbreakable()) {
201209
stackCompound.setBoolean(UNBREAKABLE_KEY, true);
202210
}
203211

204212
// Set tool and material enchantments
205213
Object2IntMap<Enchantment> enchantments = new Object2IntOpenHashMap<>();
206-
toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
207-
level.getLevel(toolProperty.getToolHarvestLevel())));
214+
finalToolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
215+
level.getLevel(finalToolProperty.getToolHarvestLevel())));
208216
toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment,
209-
level.getLevel(toolProperty.getToolHarvestLevel())));
217+
level.getLevel(finalToolProperty.getToolHarvestLevel())));
210218
enchantments.forEach((enchantment, level) -> {
211219
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
212220
stack.addEnchantment(enchantment, level);
@@ -226,7 +234,7 @@ default ItemStack get(Material material) {
226234
behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer);
227235
}
228236

229-
if (toolProperty.isMagnetic()) {
237+
if (finalToolProperty.isMagnetic()) {
230238
behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true);
231239
}
232240

@@ -260,9 +268,24 @@ default Material getToolMaterial(ItemStack stack) {
260268
return material;
261269
}
262270

271+
@Nullable
272+
default ToolProperty getToolProperty(Material material) {
273+
ToolProperty finalToolProperty;
274+
{
275+
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
276+
if (material.hasProperty(PropertyKey.EXTRATOOL)) {
277+
finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL)
278+
.getOverriddenResult(this.getToolId(), materialToolProperty);
279+
} else {
280+
finalToolProperty = materialToolProperty;
281+
}
282+
}
283+
return finalToolProperty;
284+
}
285+
263286
@Nullable
264287
default ToolProperty getToolProperty(ItemStack stack) {
265-
return getToolMaterial(stack).getProperty(PropertyKey.TOOL);
288+
return getToolProperty(getToolMaterial(stack));
266289
}
267290

268291
@Nullable

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import net.minecraftforge.fml.relauncher.Side;
4444
import net.minecraftforge.fml.relauncher.SideOnly;
4545
import net.minecraftforge.items.CapabilityItemHandler;
46+
import net.minecraftforge.items.IItemHandler;
4647
import net.minecraftforge.items.ItemStackHandler;
4748
import net.minecraftforge.oredict.OreDictionary;
4849
import net.minecraftforge.oredict.OreIngredient;
@@ -115,7 +116,7 @@ public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager
115116

116117
int heightBonus = (handler.getSlots() / 9) * 18;
117118

118-
SlotGroup group = new SlotGroup("toolbelt_inventory", 9);
119+
SlotGroup group = new SlotGroup("toolbelt_inventory", Math.min(handler.getSlots(), 9));
119120
guiSyncManager.registerSlotGroup(group);
120121

121122
List<ItemSlot> slots = new ArrayList<>();
@@ -410,7 +411,9 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) {
410411
}
411412

412413
private ToolStackHandler getHandler(ItemStack stack) {
413-
return (ToolStackHandler) stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
414+
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
415+
if (handler instanceof ToolStackHandler h) return h;
416+
else return FALLBACK;
414417
}
415418

416419
@Override
@@ -448,13 +451,14 @@ public void setSelectedTool(int slot, ItemStack stack) {
448451
@Override
449452
public @NotNull String getItemStackDisplayName(@NotNull ItemStack stack) {
450453
ItemStack tool = getHandler(stack).getSelectedStack();
451-
String selectedToolDisplay = "";
454+
getHandler(stack).disablePassthrough();
455+
String name;
452456
if (!tool.isEmpty()) {
453-
selectedToolDisplay = " (" + tool.getDisplayName() + ")";
457+
name = LocalizationUtils.format(getTranslationKey() + ".select", getToolMaterial(stack).getLocalizedName(),
458+
tool.getDisplayName());
459+
} else {
460+
name = LocalizationUtils.format(getTranslationKey(), getToolMaterial(stack).getLocalizedName());
454461
}
455-
getHandler(stack).disablePassthrough();
456-
String name = LocalizationUtils.format(getTranslationKey(), getToolMaterial(stack).getLocalizedName(),
457-
selectedToolDisplay);
458462
getHandler(stack).enablePassthrough();
459463
return name;
460464
}
@@ -601,6 +605,8 @@ public void readNBTShareTag(ItemStack stack, NBTTagCompound nbt) {
601605
stack.setTagCompound(nbt == null ? null : (nbt.hasKey("NBT") ? nbt.getCompoundTag("NBT") : null));
602606
}
603607

608+
protected static final ToolStackHandler FALLBACK = new ToolStackHandler(0);
609+
604610
protected static class ToolStackHandler extends ItemStackHandler {
605611

606612
private static final Set<String> EMPTY = ImmutableSet.of();
@@ -669,7 +675,6 @@ public boolean isItemValid(int slot, @NotNull ItemStack stack) {
669675

670676
@Override
671677
protected void onContentsChanged(int slot) {
672-
if (this.selectedSlot == slot) this.selectedSlot = -1;
673678
this.updateSlot(slot);
674679
this.update();
675680

0 commit comments

Comments
 (0)