Skip to content

Commit f2113be

Browse files
committed
Merge branch 'master' into zb/multiblock-active-mode-mui2
2 parents d728ebd + 11c1647 commit f2113be

38 files changed

+733
-251
lines changed

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: 6 additions & 1 deletion
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;
@@ -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
@@ -601,6 +604,8 @@ public void readNBTShareTag(ItemStack stack, NBTTagCompound nbt) {
601604
stack.setTagCompound(nbt == null ? null : (nbt.hasKey("NBT") ? nbt.getCompoundTag("NBT") : null));
602605
}
603606

607+
protected static final ToolStackHandler FALLBACK = new ToolStackHandler(0);
608+
604609
protected static class ToolStackHandler extends ItemStackHandler {
605610

606611
private static final Set<String> EMPTY = ImmutableSet.of();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import gregtech.api.recipes.RecipeMaps;
1111
import gregtech.api.unification.OreDictUnifier;
1212
import gregtech.api.unification.material.Material;
13+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1314
import gregtech.api.unification.material.properties.PropertyKey;
14-
import gregtech.api.unification.material.properties.ToolProperty;
1515
import gregtech.api.unification.ore.OrePrefix;
1616
import gregtech.api.util.GTUtility;
1717
import gregtech.api.util.function.QuintFunction;
@@ -230,11 +230,11 @@ public static ItemStack getAndSetToolData(IGTTool tool, Material material, int m
230230
toolTag.setInteger(HARVEST_LEVEL_KEY, harvestLevel);
231231
toolTag.setFloat(TOOL_SPEED_KEY, toolSpeed);
232232
toolTag.setFloat(ATTACK_DAMAGE_KEY, attackDamage);
233-
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);
234-
if (toolProperty != null) {
235-
toolProperty.getEnchantments().forEach((enchantment, level) -> {
233+
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
234+
if (materialToolProperty != null) {
235+
materialToolProperty.getEnchantments().forEach((enchantment, level) -> {
236236
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
237-
stack.addEnchantment(enchantment, level.getLevel(toolProperty.getToolHarvestLevel()));
237+
stack.addEnchantment(enchantment, level.getLevel(materialToolProperty.getToolHarvestLevel()));
238238
}
239239
});
240240
}

src/main/java/gregtech/api/mui/GTGuis.java

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,82 @@ public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
7272
return createPanel(valueItem.unlocalizedName);
7373
}
7474

75-
public static ModularPanel createPopupPanel(String name, int width, int height) {
76-
return createPopupPanel(name, width, height, false, false);
75+
public static PopupPanel createPopupPanel(String name, int width, int height) {
76+
return defaultPopupPanel(name)
77+
.size(width, height);
7778
}
7879

79-
public static ModularPanel createPopupPanel(String name, int width, int height, boolean disableBelow,
80-
boolean closeOnOutsideClick) {
81-
return new PopupPanel(name, width, height, disableBelow, closeOnOutsideClick);
80+
public static PopupPanel createPopupPanel(String name, int width, int height, boolean deleteCachedPanel) {
81+
return createPopupPanel(name, width, height)
82+
.deleteCachedPanel(deleteCachedPanel);
8283
}
8384

84-
public static ModularPanel defaultPopupPanel(String name) {
85-
return defaultPopupPanel(name, false, false);
85+
public static PopupPanel defaultPopupPanel(String name) {
86+
return new PopupPanel(name)
87+
.size(DEFAULT_WIDTH, DEFAULT_HIEGHT);
8688
}
8789

88-
public static ModularPanel defaultPopupPanel(String name, boolean disableBelow,
89-
boolean closeOnOutsideClick) {
90-
return new PopupPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT, disableBelow, closeOnOutsideClick);
90+
public static PopupPanel defaultPopupPanel(String name, boolean disableBelow,
91+
boolean closeOnOutsideClick, boolean deleteCachedPanel) {
92+
return defaultPopupPanel(name)
93+
.disablePanelsBelow(disableBelow)
94+
.closeOnOutOfBoundsClick(closeOnOutsideClick)
95+
.deleteCachedPanel(deleteCachedPanel);
9196
}
9297

93-
private static class PopupPanel extends ModularPanel {
98+
public static class PopupPanel extends ModularPanel {
9499

95-
private final boolean disableBelow;
96-
private final boolean closeOnOutsideClick;
100+
private boolean disableBelow;
101+
private boolean closeOnOutsideClick;
102+
private boolean deleteCachedPanel;
97103

98-
public PopupPanel(@NotNull String name, int width, int height, boolean disableBelow,
99-
boolean closeOnOutsideClick) {
104+
private PopupPanel(@NotNull String name) {
100105
super(name);
101-
size(width, height).align(Alignment.Center);
106+
align(Alignment.Center);
102107
background(GTGuiTextures.BACKGROUND_POPUP);
103108
child(ButtonWidget.panelCloseButton().top(5).right(5)
104109
.onMousePressed(mouseButton -> {
105110
if (mouseButton == 0 || mouseButton == 1) {
106111
this.closeIfOpen(true);
107-
if (isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
108-
handler.deleteCachedPanel();
109-
}
110112
return true;
111113
}
112114
return false;
113115
}));
116+
}
117+
118+
@Override
119+
public void onClose() {
120+
super.onClose();
121+
if (deleteCachedPanel && isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
122+
handler.deleteCachedPanel();
123+
}
124+
}
125+
126+
public PopupPanel disablePanelsBelow(boolean disableBelow) {
114127
this.disableBelow = disableBelow;
128+
return this;
129+
}
130+
131+
public PopupPanel closeOnOutOfBoundsClick(boolean closeOnOutsideClick) {
115132
this.closeOnOutsideClick = closeOnOutsideClick;
133+
return this;
134+
}
135+
136+
public PopupPanel deleteCachedPanel(boolean deleteCachedPanel) {
137+
this.deleteCachedPanel = deleteCachedPanel;
138+
return this;
139+
}
140+
141+
@Override
142+
public PopupPanel size(int w, int h) {
143+
super.size(w, h);
144+
return this;
145+
}
146+
147+
@Override
148+
public PopupPanel size(int val) {
149+
super.size(val);
150+
return this;
116151
}
117152

118153
@Override

src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static class ResearchRecipeEntry {
155155
private final ItemStack dataStack;
156156
private final boolean ignoreNBT;
157157
private final int duration;
158-
private final int EUt;
158+
private final long EUt;
159159
private final int CWUt;
160160

161161
/**
@@ -167,10 +167,10 @@ public static class ResearchRecipeEntry {
167167
* @param CWUt how much computation per tick this recipe needs if in Research Station
168168
* <p>
169169
* By default, will ignore NBT on researchStack input. If NBT matching is desired, see
170-
* {@link #ResearchRecipeEntry(String, ItemStack, ItemStack, boolean, int, int, int)}
170+
* {@link #ResearchRecipeEntry(String, ItemStack, ItemStack, boolean, int, long, int)}
171171
*/
172172
public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack researchStack,
173-
@NotNull ItemStack dataStack, int duration, int EUt, int CWUt) {
173+
@NotNull ItemStack dataStack, int duration, long EUt, int CWUt) {
174174
this.researchId = researchId;
175175
this.researchStack = researchStack;
176176
this.dataStack = dataStack;
@@ -189,7 +189,7 @@ public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack resear
189189
* @param CWUt how much computation per tick this recipe needs if in Research Station
190190
*/
191191
public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack researchStack,
192-
@NotNull ItemStack dataStack, boolean ignoreNBT, int duration, int EUt, int CWUt) {
192+
@NotNull ItemStack dataStack, boolean ignoreNBT, int duration, long EUt, int CWUt) {
193193
this.researchId = researchId;
194194
this.researchStack = researchStack;
195195
this.dataStack = dataStack;
@@ -222,7 +222,7 @@ public int getDuration() {
222222
return duration;
223223
}
224224

225-
public int getEUt() {
225+
public long getEUt() {
226226
return EUt;
227227
}
228228

src/main/java/gregtech/api/recipes/builders/ResearchRecipeBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class ResearchRecipeBuilder<T extends ResearchRecipeBuilder<T>>
1717
protected ItemStack dataStack;
1818
protected boolean ignoreNBT;
1919
protected String researchId;
20-
protected int eut;
20+
protected long eut;
2121

2222
public T researchStack(@NotNull ItemStack researchStack) {
2323
if (!researchStack.isEmpty()) {
@@ -47,7 +47,7 @@ public T researchId(String researchId) {
4747
return (T) this;
4848
}
4949

50-
public T EUt(int eut) {
50+
public T EUt(long eut) {
5151
this.eut = eut;
5252
return (T) this;
5353
}

0 commit comments

Comments
 (0)