diff options
| author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
| commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
| tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter | |
| parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
| download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip | |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter')
2 files changed, 160 insertions, 175 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java index 29dabaf084..165941b1d2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java @@ -1,5 +1,6 @@ package gtPlusPlus.xmod.gregtech.common.helpers.autocrafter; +import gtPlusPlus.api.objects.Logger; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.*; @@ -7,112 +8,98 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.world.World; -import gtPlusPlus.api.objects.Logger; +public class AC_Helper_Container extends Container { + /** The crafting matrix inventory (3x3). */ + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + + public IInventory craftResult = new InventoryCraftResult(); + private World worldObj; + + public InventoryCrafting getMatrix() { + return this.craftMatrix; + } + + public boolean putItemsIntoGrid(ItemStack[] inputs) { + if (inputs.length < 9) { + return false; + } + for (int i = 0; i < 9; i++) { + this.putStackInSlot(i, inputs[i]); + } + this.onCraftMatrixChanged(this.craftMatrix); + return true; + } + + public AC_Helper_Container(InventoryPlayer playerInventory, World world, int x, int y, int z) { + this.worldObj = world; + this.addSlotToContainer( + new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35)); + int l; + int i1; + + for (l = 0; l < 3; ++l) { + for (i1 = 0; i1 < 3; ++i1) { + this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18)); + } + } + + for (l = 0; l < 3; ++l) { + for (i1 = 0; i1 < 9; ++i1) { + this.addSlotToContainer(new Slot(playerInventory, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18)); + } + } + + for (l = 0; l < 9; ++l) { + this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142)); + } + + this.onCraftMatrixChanged(this.craftMatrix); + } + + /** + * Callback for when the crafting matrix is changed. + */ + @Override + public void onCraftMatrixChanged(IInventory p_75130_1_) { + this.craftResult.setInventorySlotContents( + 0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + Logger.INFO("Crafted " + this.craftResult.getStackInSlot(0)); + } + + /** + * Called when the container is closed. + */ + @Override + public void onContainerClosed(EntityPlayer p_75134_1_) { + super.onContainerClosed(p_75134_1_); + + if (!this.worldObj.isRemote) { + for (int i = 0; i < 9; ++i) { + ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); + + if (itemstack != null) { + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + } + } + + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + + /** + * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. + */ + @Override + public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) { + ItemStack itemstack = null; + return itemstack; + } -public class AC_Helper_Container extends Container -{ - /** The crafting matrix inventory (3x3). */ - public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); - public IInventory craftResult = new InventoryCraftResult(); - private World worldObj; - - public InventoryCrafting getMatrix(){ - return this.craftMatrix; - } - - public boolean putItemsIntoGrid(ItemStack[] inputs){ - if (inputs.length < 9){ - return false; - } - for (int i=0;i<9;i++){ - this.putStackInSlot(i, inputs[i]); - } - this.onCraftMatrixChanged(this.craftMatrix); - return true; - } - - public AC_Helper_Container(InventoryPlayer playerInventory, World world, int x, int y, int z) - { - this.worldObj = world; - this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35)); - int l; - int i1; - - for (l = 0; l < 3; ++l) - { - for (i1 = 0; i1 < 3; ++i1) - { - this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18)); - } - } - - for (l = 0; l < 3; ++l) - { - for (i1 = 0; i1 < 9; ++i1) - { - this.addSlotToContainer(new Slot(playerInventory, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18)); - } - } - - for (l = 0; l < 9; ++l) - { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142)); - } - - this.onCraftMatrixChanged(this.craftMatrix); - } - - /** - * Callback for when the crafting matrix is changed. - */ - @Override - public void onCraftMatrixChanged(IInventory p_75130_1_) - { - this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); - Logger.INFO("Crafted "+this.craftResult.getStackInSlot(0)); - - } - - /** - * Called when the container is closed. - */ - @Override - public void onContainerClosed(EntityPlayer p_75134_1_) - { - super.onContainerClosed(p_75134_1_); - - if (!this.worldObj.isRemote) - { - for (int i = 0; i < 9; ++i) - { - ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); - - if (itemstack != null) - { - p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); - } - } - } - } - - @Override - public boolean canInteractWith(EntityPlayer p_75145_1_) - { - return true; - } - - /** - * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. - */ - @Override - public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_){ - ItemStack itemstack = null; - return itemstack; - } - - @Override - public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_) - { - return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_); - } -}
\ No newline at end of file + @Override + public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_) { + return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java index 772ece96aa..6b8452eeed 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java @@ -1,80 +1,78 @@ package gtPlusPlus.xmod.gregtech.common.helpers.autocrafter; -import java.util.*; -import java.util.Map.Entry; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GT4Entity_AutoCrafter; +import java.util.*; +import java.util.Map.Entry; public class AC_Helper_Utils { - //AC maps - public static final Map<Integer, GT4Entity_AutoCrafter> sAutocrafterMap = new HashMap<Integer, GT4Entity_AutoCrafter>(); - - //Add Crafter - public final static int addCrafter(GT4Entity_AutoCrafter AC) { - if (!sAutocrafterMap.containsValue(AC)){ - int increase = sAutocrafterMap.size()+1; - sAutocrafterMap.put(increase, AC); - Logger.INFO("[A-C] "+"Added Auto-Crafter to index on position "+increase+"."); - return increase; - } - else { - Logger.INFO("[A-C] Tried adding an Auto-Crafter to Index, but found one already there."); - } - return 0; - } + // AC maps + public static final Map<Integer, GT4Entity_AutoCrafter> sAutocrafterMap = + new HashMap<Integer, GT4Entity_AutoCrafter>(); - //Remove Crafter - public final static boolean removeCrafter(int frequency) { - if (!sAutocrafterMap.isEmpty()){ - if (sAutocrafterMap.containsKey(frequency)){ - sAutocrafterMap.remove(frequency); - return true; - } - } - return false; - } + // Add Crafter + public static final int addCrafter(GT4Entity_AutoCrafter AC) { + if (!sAutocrafterMap.containsValue(AC)) { + int increase = sAutocrafterMap.size() + 1; + sAutocrafterMap.put(increase, AC); + Logger.INFO("[A-C] " + "Added Auto-Crafter to index on position " + increase + "."); + return increase; + } else { + Logger.INFO("[A-C] Tried adding an Auto-Crafter to Index, but found one already there."); + } + return 0; + } - public final static boolean removeCrafter(GT4Entity_AutoCrafter AC) { - if (!sAutocrafterMap.isEmpty()){ - if (sAutocrafterMap.containsValue(AC)){ - sAutocrafterMap.remove(getIDByCrafter(AC)); - return true; - } - } - return false; - } + // Remove Crafter + public static final boolean removeCrafter(int frequency) { + if (!sAutocrafterMap.isEmpty()) { + if (sAutocrafterMap.containsKey(frequency)) { + sAutocrafterMap.remove(frequency); + return true; + } + } + return false; + } - //Get Crafter - public final static GT4Entity_AutoCrafter getCrafterByID(int ID) { - if (!sAutocrafterMap.isEmpty()) { - Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet(); - Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator(); - while (i.hasNext()) { - Entry<Integer, GT4Entity_AutoCrafter> current = i.next(); - if (current.getKey().equals(ID)) { - return current.getValue(); - } - } - } - Logger.WARNING("Failed. [getCrafterByID]"); - return null; - } + public static final boolean removeCrafter(GT4Entity_AutoCrafter AC) { + if (!sAutocrafterMap.isEmpty()) { + if (sAutocrafterMap.containsValue(AC)) { + sAutocrafterMap.remove(getIDByCrafter(AC)); + return true; + } + } + return false; + } - public final static int getIDByCrafter(GT4Entity_AutoCrafter AC) { - if (!sAutocrafterMap.isEmpty()) { - Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet(); - Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator(); - while (i.hasNext()) { - Entry<Integer, GT4Entity_AutoCrafter> current = i.next(); - if (current.getValue().equals(AC)) { - return current.getKey(); - } - } - } - Logger.WARNING("Failed. [getIDByCrafter]"); - return 0; - } + // Get Crafter + public static final GT4Entity_AutoCrafter getCrafterByID(int ID) { + if (!sAutocrafterMap.isEmpty()) { + Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet(); + Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator(); + while (i.hasNext()) { + Entry<Integer, GT4Entity_AutoCrafter> current = i.next(); + if (current.getKey().equals(ID)) { + return current.getValue(); + } + } + } + Logger.WARNING("Failed. [getCrafterByID]"); + return null; + } + public static final int getIDByCrafter(GT4Entity_AutoCrafter AC) { + if (!sAutocrafterMap.isEmpty()) { + Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet(); + Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator(); + while (i.hasNext()) { + Entry<Integer, GT4Entity_AutoCrafter> current = i.next(); + if (current.getValue().equals(AC)) { + return current.getKey(); + } + } + } + Logger.WARNING("Failed. [getIDByCrafter]"); + return 0; + } } |
