Skip to content

Commit

Permalink
gear transformer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooy1 committed Jan 1, 2021
1 parent c1969ca commit 8f04914
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 105 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
</relocation>
<relocation>
<pattern>io.github.mooy1.infinitylib</pattern>
<shadedPattern>io.github.mooy1.slimegrid.infinitylib</shadedPattern>
<shadedPattern>io.github.mooy1.infinityexpansion.infinitylib</shadedPattern>
</relocation>
</relocations>
<filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public class AdvancedAnvil extends AbstractContainer implements EnergyNetCompone

public AdvancedAnvil() {
super(Categories.MAIN_MATERIALS, Items.ADVANCED_ANVIL, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{
Items.ADAMANTITE, Items.ADAMANTITE, Items.ADAMANTITE,
Items.MAGNONIUM, new ItemStack(Material.ANVIL), Items.MAGNONIUM,
Items.MACHINE_PLATE, Items.MACHINE_PLATE, Items.MACHINE_PLATE,
Items.MACHINE_PLATE, new ItemStack(Material.ANVIL), Items.MACHINE_PLATE,
Items.MACHINE_CIRCUIT, Items.MACHINE_CORE, Items.MACHINE_CIRCUIT
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.mooy1.infinityexpansion.lists.Categories;
import io.github.mooy1.infinityexpansion.lists.Items;
import io.github.mooy1.infinitylib.items.StackUtils;
import io.github.mooy1.infinitylib.objects.AbstractContainer;
import io.github.mooy1.infinitylib.player.MessageUtils;
import io.github.mooy1.infinitylib.presets.MenuPreset;
Expand All @@ -14,7 +15,7 @@
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.cscorelib2.inventory.ItemUtils;
import me.mrCookieSlime.Slimefun.cscorelib2.collections.Pair;
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -24,6 +25,8 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
* Machine that changes the material of gear and tools
*
Expand Down Expand Up @@ -52,7 +55,7 @@ public class GearTransformer extends AbstractContainer implements EnergyNetCompo
private static final int STATUS_SLOT = MenuPreset.slot2;

public GearTransformer() {
super(Categories.ADVANCED_MACHINES, Items.GEAR_TRANSFORMER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{
super(Categories.ADVANCED_MACHINES, Items.GEAR_TRANSFORMER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {
Items.MAGSTEEL_PLATE, Items.MACHINE_CIRCUIT, Items.MAGSTEEL_PLATE,
Items.MACHINE_CIRCUIT, new ItemStack(Material.SMITHING_TABLE), Items.MACHINE_CIRCUIT,
Items.MAGSTEEL_PLATE, Items.MACHINE_CIRCUIT, Items.MAGSTEEL_PLATE
Expand Down Expand Up @@ -85,29 +88,23 @@ public void tick(@Nonnull Block b, @Nonnull BlockMenu inv) {

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

inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BLUE_STAINED_GLASS_PANE, "&9Input a tool"));
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.BLUE_STAINED_GLASS_PANE, "&9Input a tool or piece of gear"));
return;

}

String inputToolType;

if (getToolType(inputItem) != null) {
inputToolType = getToolType(inputItem);
} else {
inputToolType = getArmorType(inputItem);

if (StackUtils.getItemID(inputItem, false) != null) {
inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.RED_STAINED_GLASS_PANE, "&cSlimefun items may not have their material changed!"));
return;
}

String inputToolType = getType(inputItem);

if (inputToolType == null) { //invalid input

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

/*if (inv.getItemInSlot(OUTPUT_SLOTS[0]) == null) {
inv.pushItem(inputItem, OUTPUT_SLOTS);
inv.consumeItem(INPUT_SLOT1, inputItem.getAmount());
}*/

}

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

}

Material outputMaterial = getOutput(inputMaterial, inputToolType);
Pair<Material, Integer> pair = getOutput(inputMaterial, inputToolType);

if (outputMaterial == null) { //invalid material
if (pair == null) { //invalid material

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

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

inputItem.setType(outputMaterial);
inputItem.setType(pair.getFirstValue());
inv.pushItem(inputItem, OUTPUT_SLOTS);

inv.consumeItem(INPUT_SLOT1);
inv.consumeItem(INPUT_SLOT2, getAmount(inputMaterial, inputToolType));
inv.replaceExistingItem(INPUT_SLOT1, null);
inv.consumeItem(INPUT_SLOT2, pair.getSecondValue());

inv.replaceExistingItem(STATUS_SLOT, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&aTool Transformed!"));
}
Expand Down Expand Up @@ -181,97 +178,65 @@ public int[] getTransportSlots(@Nonnull ItemTransportFlow flow) {
return new int[0];
}
}

/**
* This method gets the output from the input material and input tool
*
*
* @param inputMaterial material
* @param inputToolType tools type
*
* @return output if any
*/
@Nullable
private Material getOutput(ItemStack inputMaterial, String inputToolType) {
private Pair<Material, Integer> getOutput(ItemStack inputMaterial, String inputToolType) {

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

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

if (inputMaterial.getType() == recipe.getType() && inputMaterial.getAmount() >= recipe.getAmount()) {
return Material.getMaterial(TOOL_MATERIALS[i] + toolType);

return new Pair<>(Material.getMaterial(TOOL_MATERIALS[i] + toolType), recipe.getAmount());
}
}

break;
}
}

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

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

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

return Material.getMaterial(ARMOR_MATERIALS[i] + armorType);
return new Pair<>(Material.getMaterial(ARMOR_MATERIALS[i] + armorType), recipe.getAmount());
}
}

break;
}
}

return null;
}

/**
* This method gets the amount of material required to transform and item
*
* @param inputMaterial material input type
* @param inputToolType tool input type
* @return amount needed
*/
private int getAmount(ItemStack inputMaterial, String inputToolType) {

for (String toolType : TOOL_TYPES) {

if (inputToolType.equals(toolType)) {

for (ItemStack input : TOOL_RECIPE) {

if (inputMaterial.getType() == input.getType() && inputMaterial.getAmount() >= input.getAmount()) {

return input.getAmount();
}
}
}
}
@Nullable
private String getType(ItemStack item) {
Material material = item.getType();

for (String armorType : ARMOR_TYPES) {

if (inputToolType.equals(armorType)) {

for (ItemStack input : ARMOR_RECIPE) {

if (inputMaterial.getType() == input.getType() && inputMaterial.getAmount() >= input.getAmount()) {
for (String armorMaterial : ARMOR_MATERIALS) {

return input.getAmount();
}
}
if (material == Material.getMaterial(armorMaterial + armorType)) return armorType;
}
}

return 0;
}

/**
* This method gets the type of tool that an item is
*
* @param item item to check
* @return type of tool if any
*/
@Nullable
private String getToolType(ItemStack item) {
Material material = item.getType();

for (String toolType : TOOL_TYPES) {

for (String toolMaterial : TOOL_MATERIALS) {
Expand All @@ -280,26 +245,7 @@ private String getToolType(ItemStack item) {
}
}
return null;
}

/**
* This method gets the type of armor that an item is
*
* @param item item to check
* @return type of armor if any
*/
@Nullable
private String getArmorType(ItemStack item) {
Material material = item.getType();

for (String armorType : ARMOR_TYPES) {

for (String armorMaterial : ARMOR_MATERIALS) {

if (material == Material.getMaterial(armorMaterial + armorType)) return armorType;
}
}
return null;
}

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

items.add(new CustomItem(Material.DIAMOND_PICKAXE, "&7For Tools >>>"));
items.add(new CustomItem(Material.DIAMOND_CHESTPLATE, "&7For Armor >>>"));

for (int i = 0; i < TOOL_RECIPE.length; i++) {
for (int i = 0 ; i < TOOL_RECIPE.length ; i++) {
items.add(TOOL_RECIPE[i]);
items.add(ARMOR_RECIPE[i]);
}
Expand All @@ -376,4 +319,5 @@ public List<ItemStack> getDisplayRecipes() {
new ItemStack(Material.DIAMOND, 9),
new ItemStack(Material.NETHERITE_INGOT, 2)
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ public final class Categories {
);

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

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

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

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

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

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public final class Items {
"GEAR_TRANSFORMER",
Material.EMERALD_BLOCK,
"&7Gear Transformer",
"&7Changes the material of tools and gear",
"&7Changes the material of vanilla tools and gear",
"",
LorePreset.energy(GearTransformer.ENERGY) + "Per Use"
);
Expand Down

0 comments on commit 8f04914

Please sign in to comment.