Skip to content

Commit 8f04914

Browse files
committed
gear transformer fix
1 parent c1969ca commit 8f04914

File tree

5 files changed

+49
-105
lines changed

5 files changed

+49
-105
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</relocation>
133133
<relocation>
134134
<pattern>io.github.mooy1.infinitylib</pattern>
135-
<shadedPattern>io.github.mooy1.slimegrid.infinitylib</shadedPattern>
135+
<shadedPattern>io.github.mooy1.infinityexpansion.infinitylib</shadedPattern>
136136
</relocation>
137137
</relocations>
138138
<filters>

src/main/java/io/github/mooy1/infinityexpansion/implementation/blocks/AdvancedAnvil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class AdvancedAnvil extends AbstractContainer implements EnergyNetCompone
7272

7373
public AdvancedAnvil() {
7474
super(Categories.MAIN_MATERIALS, Items.ADVANCED_ANVIL, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{
75-
Items.ADAMANTITE, Items.ADAMANTITE, Items.ADAMANTITE,
76-
Items.MAGNONIUM, new ItemStack(Material.ANVIL), Items.MAGNONIUM,
75+
Items.MACHINE_PLATE, Items.MACHINE_PLATE, Items.MACHINE_PLATE,
76+
Items.MACHINE_PLATE, new ItemStack(Material.ANVIL), Items.MACHINE_PLATE,
7777
Items.MACHINE_CIRCUIT, Items.MACHINE_CORE, Items.MACHINE_CIRCUIT
7878
});
7979

src/main/java/io/github/mooy1/infinityexpansion/implementation/machines/GearTransformer.java

Lines changed: 39 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.mooy1.infinityexpansion.lists.Categories;
44
import io.github.mooy1.infinityexpansion.lists.Items;
5+
import io.github.mooy1.infinitylib.items.StackUtils;
56
import io.github.mooy1.infinitylib.objects.AbstractContainer;
67
import io.github.mooy1.infinitylib.player.MessageUtils;
78
import io.github.mooy1.infinitylib.presets.MenuPreset;
@@ -14,7 +15,7 @@
1415
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
1516
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
1617
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
17-
import me.mrCookieSlime.Slimefun.cscorelib2.inventory.ItemUtils;
18+
import me.mrCookieSlime.Slimefun.cscorelib2.collections.Pair;
1819
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
1920
import org.bukkit.Material;
2021
import org.bukkit.block.Block;
@@ -24,6 +25,8 @@
2425
import javax.annotation.Nullable;
2526
import java.util.ArrayList;
2627
import java.util.List;
28+
import java.util.Locale;
29+
2730
/**
2831
* Machine that changes the material of gear and tools
2932
*
@@ -52,7 +55,7 @@ public class GearTransformer extends AbstractContainer implements EnergyNetCompo
5255
private static final int STATUS_SLOT = MenuPreset.slot2;
5356

5457
public GearTransformer() {
55-
super(Categories.ADVANCED_MACHINES, Items.GEAR_TRANSFORMER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{
58+
super(Categories.ADVANCED_MACHINES, Items.GEAR_TRANSFORMER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {
5659
Items.MAGSTEEL_PLATE, Items.MACHINE_CIRCUIT, Items.MAGSTEEL_PLATE,
5760
Items.MACHINE_CIRCUIT, new ItemStack(Material.SMITHING_TABLE), Items.MACHINE_CIRCUIT,
5861
Items.MAGSTEEL_PLATE, Items.MACHINE_CIRCUIT, Items.MAGSTEEL_PLATE
@@ -85,29 +88,23 @@ public void tick(@Nonnull Block b, @Nonnull BlockMenu inv) {
8588

8689
if (inputItem == null) { //no input
8790

88-
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BLUE_STAINED_GLASS_PANE, "&9Input a tool"));
91+
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BLUE_STAINED_GLASS_PANE, "&9Input a tool or piece of gear"));
8992
return;
9093

9194
}
92-
93-
String inputToolType;
94-
95-
if (getToolType(inputItem) != null) {
96-
inputToolType = getToolType(inputItem);
97-
} else {
98-
inputToolType = getArmorType(inputItem);
95+
96+
if (StackUtils.getItemID(inputItem, false) != null) {
97+
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.RED_STAINED_GLASS_PANE, "&cSlimefun items may not have their material changed!"));
98+
return;
9999
}
100100

101+
String inputToolType = getType(inputItem);
102+
101103
if (inputToolType == null) { //invalid input
102104

103-
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BARRIER, "&cNot a tool or armor!"));
105+
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BARRIER, "&cNot a tool or piece of gear!"));
104106
return;
105107

106-
/*if (inv.getItemInSlot(OUTPUT_SLOTS[0]) == null) {
107-
inv.pushItem(inputItem, OUTPUT_SLOTS);
108-
inv.consumeItem(INPUT_SLOT1, inputItem.getAmount());
109-
}*/
110-
111108
}
112109

113110
ItemStack inputMaterial = inv.getItemInSlot(INPUT_SLOT2);
@@ -119,9 +116,9 @@ public void tick(@Nonnull Block b, @Nonnull BlockMenu inv) {
119116

120117
}
121118

122-
Material outputMaterial = getOutput(inputMaterial, inputToolType);
119+
Pair<Material, Integer> pair = getOutput(inputMaterial, inputToolType);
123120

124-
if (outputMaterial == null) { //invalid material
121+
if (pair == null) { //invalid material
125122

126123
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BARRIER, "&cInvalid Materials!"));
127124
return;
@@ -138,13 +135,13 @@ public void tick(@Nonnull Block b, @Nonnull BlockMenu inv) {
138135
//output
139136
removeCharge(b.getLocation(), ENERGY);
140137

141-
MessageUtils.messagePlayersInInv(inv, "Transformed into: " + ItemUtils.getItemName(new ItemStack(outputMaterial)));
138+
MessageUtils.messagePlayersInInv(inv, "Transformed into: " + pair.getFirstValue().toString().toUpperCase(Locale.ROOT));
142139

143-
inputItem.setType(outputMaterial);
140+
inputItem.setType(pair.getFirstValue());
144141
inv.pushItem(inputItem, OUTPUT_SLOTS);
145142

146-
inv.consumeItem(INPUT_SLOT1);
147-
inv.consumeItem(INPUT_SLOT2, getAmount(inputMaterial, inputToolType));
143+
inv.replaceExistingItem(INPUT_SLOT1, null);
144+
inv.consumeItem(INPUT_SLOT2, pair.getSecondValue());
148145

149146
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&aTool Transformed!"));
150147
}
@@ -181,97 +178,65 @@ public int[] getTransportSlots(@Nonnull ItemTransportFlow flow) {
181178
return new int[0];
182179
}
183180
}
184-
181+
185182
/**
186183
* This method gets the output from the input material and input tool
187-
*
184+
*
188185
* @param inputMaterial material
189186
* @param inputToolType tools type
187+
*
190188
* @return output if any
191189
*/
192190
@Nullable
193-
private Material getOutput(ItemStack inputMaterial, String inputToolType) {
191+
private Pair<Material, Integer> getOutput(ItemStack inputMaterial, String inputToolType) {
194192

195193
for (String toolType : TOOL_TYPES) {
196194
if (inputToolType.equals(toolType)) { //make sure its a tool
197195

198-
for (int i = 0; i < TOOL_RECIPE.length; i++) { //compare to each recipe
196+
for (int i = 0 ; i < TOOL_RECIPE.length ; i++) { //compare to each recipe
199197
ItemStack recipe = TOOL_RECIPE[i];
200198

201199
if (inputMaterial.getType() == recipe.getType() && inputMaterial.getAmount() >= recipe.getAmount()) {
202-
return Material.getMaterial(TOOL_MATERIALS[i] + toolType);
200+
201+
return new Pair<>(Material.getMaterial(TOOL_MATERIALS[i] + toolType), recipe.getAmount());
203202
}
204203
}
204+
205+
break;
205206
}
206207
}
207208

208209
for (String armorType : ARMOR_TYPES) {
209210
if (inputToolType.equals(armorType)) { //make sure its a armor
210211

211-
for (int i = 0; i < ARMOR_RECIPE.length; i++) { //compare to each recipe
212+
for (int i = 0 ; i < ARMOR_RECIPE.length ; i++) { //compare to each recipe
212213
ItemStack recipe = ARMOR_RECIPE[i];
213214

214215
if (inputMaterial.getType() == recipe.getType() && inputMaterial.getAmount() >= recipe.getAmount()) {
215216

216-
return Material.getMaterial(ARMOR_MATERIALS[i] + armorType);
217+
return new Pair<>(Material.getMaterial(ARMOR_MATERIALS[i] + armorType), recipe.getAmount());
217218
}
218219
}
220+
221+
break;
219222
}
220223
}
221224

222225
return null;
223226
}
224227

225-
/**
226-
* This method gets the amount of material required to transform and item
227-
*
228-
* @param inputMaterial material input type
229-
* @param inputToolType tool input type
230-
* @return amount needed
231-
*/
232-
private int getAmount(ItemStack inputMaterial, String inputToolType) {
233-
234-
for (String toolType : TOOL_TYPES) {
235-
236-
if (inputToolType.equals(toolType)) {
237-
238-
for (ItemStack input : TOOL_RECIPE) {
239-
240-
if (inputMaterial.getType() == input.getType() && inputMaterial.getAmount() >= input.getAmount()) {
241-
242-
return input.getAmount();
243-
}
244-
}
245-
}
246-
}
228+
@Nullable
229+
private String getType(ItemStack item) {
230+
Material material = item.getType();
247231

248232
for (String armorType : ARMOR_TYPES) {
249233

250-
if (inputToolType.equals(armorType)) {
251-
252-
for (ItemStack input : ARMOR_RECIPE) {
253-
254-
if (inputMaterial.getType() == input.getType() && inputMaterial.getAmount() >= input.getAmount()) {
234+
for (String armorMaterial : ARMOR_MATERIALS) {
255235

256-
return input.getAmount();
257-
}
258-
}
236+
if (material == Material.getMaterial(armorMaterial + armorType)) return armorType;
259237
}
260238
}
261239

262-
return 0;
263-
}
264-
265-
/**
266-
* This method gets the type of tool that an item is
267-
*
268-
* @param item item to check
269-
* @return type of tool if any
270-
*/
271-
@Nullable
272-
private String getToolType(ItemStack item) {
273-
Material material = item.getType();
274-
275240
for (String toolType : TOOL_TYPES) {
276241

277242
for (String toolMaterial : TOOL_MATERIALS) {
@@ -280,26 +245,7 @@ private String getToolType(ItemStack item) {
280245
}
281246
}
282247
return null;
283-
}
284-
285-
/**
286-
* This method gets the type of armor that an item is
287-
*
288-
* @param item item to check
289-
* @return type of armor if any
290-
*/
291-
@Nullable
292-
private String getArmorType(ItemStack item) {
293-
Material material = item.getType();
294-
295-
for (String armorType : ARMOR_TYPES) {
296-
297-
for (String armorMaterial : ARMOR_MATERIALS) {
298248

299-
if (material == Material.getMaterial(armorMaterial + armorType)) return armorType;
300-
}
301-
}
302-
return null;
303249
}
304250

305251
private static final String[] ARMOR_TYPES = {
@@ -348,10 +294,7 @@ public int getCapacity() {
348294
public List<ItemStack> getDisplayRecipes() {
349295
List<ItemStack> items = new ArrayList<>();
350296

351-
items.add(new CustomItem(Material.DIAMOND_PICKAXE, "&7For Tools >>>"));
352-
items.add(new CustomItem(Material.DIAMOND_CHESTPLATE, "&7For Armor >>>"));
353-
354-
for (int i = 0; i < TOOL_RECIPE.length; i++) {
297+
for (int i = 0 ; i < TOOL_RECIPE.length ; i++) {
355298
items.add(TOOL_RECIPE[i]);
356299
items.add(ARMOR_RECIPE[i]);
357300
}
@@ -376,4 +319,5 @@ public List<ItemStack> getDisplayRecipes() {
376319
new ItemStack(Material.DIAMOND, 9),
377320
new ItemStack(Material.NETHERITE_INGOT, 2)
378321
};
322+
379323
}

src/main/java/io/github/mooy1/infinityexpansion/lists/Categories.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ public final class Categories {
2727
);
2828

2929
public static final Category BASIC_MACHINES = new SubCategory(new NamespacedKey(instance, "basic_machines"),
30-
new CustomItem(Material.LOOM, "&9Basic &7Powered Machines"), 2
30+
new CustomItem(Material.LOOM, "&9Basic &7Machines"), 2
3131
);
3232

3333
public static final Category ADVANCED_MACHINES = new SubCategory(new NamespacedKey(instance, "advanced_machines"),
34-
new CustomItem(Material.BLAST_FURNACE, "&cAdvanced &7Powered Machines"), 2
34+
new CustomItem(Material.BLAST_FURNACE, "&cAdvanced &7Machines"), 2
3535
);
3636

3737
public static final Category STORAGE_TRANSPORT = new SubCategory(new NamespacedKey(instance, "storage_transport"),
38-
new CustomItem(Material.ENDER_CHEST, "&6Storage and Transport"), 2
38+
new CustomItem(Material.BEEHIVE, "&6Storage"), 2
3939
);
4040

4141
public static final Category MOB_SIMULATION = new SubCategory(new NamespacedKey(instance, "mob_simulation"),
42-
new CustomItem(Material.SPAWNER, "&bMob Simulation"), 2
42+
new CustomItem(Material.BEACON, "&bMob Simulation"), 2
4343
);
4444

4545
public static final Category INFINITY_MATERIALS = new SubCategory(new NamespacedKey(instance, "infinity_materials"),
4646
new CustomItem(Material.NETHERITE_BLOCK, "&bInfinity &aMaterials"), 2
4747
);
4848

4949
public static final Category INFINITY_RECIPES = new InfinityCategory(new NamespacedKey(instance, "infinity_recipes"),
50-
new CustomItem(Material.SMITHING_TABLE, "&bInfinity &7Recipes"), 2
50+
new CustomItem(Material.RESPAWN_ANCHOR, "&bInfinity &7Recipes"), 2
5151
);
5252

5353
public static final Category INFINITY_CHEAT = new SubCategory(new NamespacedKey(instance, "infinity_cheat"),
54-
new CustomItem(Material.SMITHING_TABLE, "&bInfinity &7Recipes &c- NOT REAL RECIPES"), 2
54+
new CustomItem(Material.RESPAWN_ANCHOR, "&bInfinity &7Recipes &c- INCORRECT RECIPE"), 2
5555
);
5656

5757
}

src/main/java/io/github/mooy1/infinityexpansion/lists/Items.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public final class Items {
466466
"GEAR_TRANSFORMER",
467467
Material.EMERALD_BLOCK,
468468
"&7Gear Transformer",
469-
"&7Changes the material of tools and gear",
469+
"&7Changes the material of vanilla tools and gear",
470470
"",
471471
LorePreset.energy(GearTransformer.ENERGY) + "Per Use"
472472
);

0 commit comments

Comments
 (0)