From 4b5de3267e92e0d9d56afa8e1103ba97eb8dab26 Mon Sep 17 00:00:00 2001 From: Discreater Date: Sun, 28 Feb 2021 19:24:07 +0800 Subject: [PATCH] Chore: reformat code --- .../jecalculation/JustEnoughCalculation.java | 34 +- .../jecalculation/core/Calculator.java | 28 +- .../jecalculation/core/CostRecord.java | 106 +++--- .../jecalculation/core/ItemRecord.java | 50 +-- .../jecalculation/core/ItemStackWrapper.java | 310 +++++++++--------- .../me/towdium/jecalculation/core/Recipe.java | 157 ++++----- .../jecalculation/event/GuiEventHandler.java | 6 +- .../event/PlayerEventHandler.java | 17 +- .../towdium/jecalculation/gui/GuiHandler.java | 21 +- .../gui/commom/GuiJustEnoughCalculation.java | 41 ++- .../gui/commom/GuiTooltipScreen.java | 145 ++++---- .../gui/commom/recipe/ContainerRecipe.java | 62 ++-- .../gui/commom/recipe/GuiRecipe.java | 78 +++-- .../guis/calculator/ContainerCalculator.java | 26 +- .../gui/guis/calculator/GuiCalculator.java | 295 +++++++++-------- .../guis/calculator/InventoryCalculator.java | 2 +- .../guis/recipeEditor/GuiRecipeEditor.java | 36 +- .../guis/recipePicker/GuiRecipePicker.java | 34 +- .../recipeViewer/ContainerRecipeViewer.java | 14 +- .../guis/recipeViewer/GuiRecipeViewer.java | 88 ++--- .../network/PlayerHandlerClient.java | 66 ++-- .../network/PlayerHandlerServer.java | 6 +- .../jecalculation/network/ProxyServer.java | 2 +- .../packets/PacketCalculatorUpdate.java | 13 +- .../network/packets/PacketRecipeUpdate.java | 13 +- .../network/packets/PacketSyncRecord.java | 19 +- .../plugin/MyOverlayHandler.java | 10 +- .../plugin/NEICalculatorConfig.java | 7 +- 28 files changed, 872 insertions(+), 814 deletions(-) diff --git a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java index 9d31332..a1371f5 100644 --- a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java +++ b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java @@ -35,8 +35,7 @@ import java.util.ArrayList; dependencies = "after:NotEnoughItems") public class JustEnoughCalculation { public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator") - .setTextureName(Reference.MODID + ":" + - "itemCalculator"); + .setTextureName(Reference.MODID + ":" + "itemCalculator"); public static SimpleNetworkWrapper networkWrapper; public static Logger log = LogManager.getLogger(Reference.MODID); @@ -53,15 +52,10 @@ public class JustEnoughCalculation { JECConfig.preInit(event); GameRegistry.registerItem(itemCalculator, itemCalculator.getUnlocalizedName().substring(5)); networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID); - networkWrapper - .registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1, - Side.SERVER); - networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2, - Side.SERVER); - networkWrapper - .registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT); - networkWrapper - .registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER); + networkWrapper.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1, Side.SERVER); + networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2, Side.SERVER); + networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT); + networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER); } @Mod.EventHandler @@ -70,9 +64,8 @@ public class JustEnoughCalculation { Minecraft.getMinecraft().getRenderItem().getItemModelMesher(). register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory")); }*/ - ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(itemCalculator), "SIS", "SRS", - "SOS", 'S', "stone", 'I', "dyeBlack", 'R', - "dustRedstone", 'O', "ingotIron") { + ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(itemCalculator), "SIS", "SRS", "SOS", 'S', "stone", + 'I', "dyeBlack", 'R', "dustRedstone", 'O', "ingotIron") { { try { Field f = ShapedOreRecipe.class.getDeclaredField("input"); @@ -169,11 +162,11 @@ public class JustEnoughCalculation { if (type != null) { switch (this.getType()) { case Boolean: - return config.get(this.getCategory(), this.getName(), - (Boolean) this.getDefault(), this.getComment()); + return config.get(this.getCategory(), this.getName(), (Boolean) this.getDefault(), + this.getComment()); case ListString: - return config.get(this.getCategory(), this.getName(), - (String[]) this.getDefault(), this.getComment()); + return config.get(this.getCategory(), this.getName(), (String[]) this.getDefault(), + this.getComment()); } config.getCategory(EnumCategory.General.toString()).get(this.getName()); } @@ -204,8 +197,7 @@ public class JustEnoughCalculation { public static Object empty; public static void preInit(FMLPreInitializationEvent event) { - config = new Configuration(new File(event.getModConfigurationDirectory(), - "JustEnoughCalculation" + ".cfg"), + config = new Configuration(new File(event.getModConfigurationDirectory(), "JustEnoughCalculation" + ".cfg"), Reference.VERSION); config.load(); handleFormerVersion(); @@ -231,6 +223,6 @@ public class JustEnoughCalculation { public static class Reference { public static final String MODID = "jecalculation"; public static final String MODNAME = "Just Enough Calculation"; - public static final String VERSION = "@VERSION@"; + public static final String VERSION = "0.4.0"; } } diff --git a/src/main/java/me/towdium/jecalculation/core/Calculator.java b/src/main/java/me/towdium/jecalculation/core/Calculator.java index 9e0e009..04c0d32 100644 --- a/src/main/java/me/towdium/jecalculation/core/Calculator.java +++ b/src/main/java/me/towdium/jecalculation/core/Calculator.java @@ -15,28 +15,30 @@ import java.util.List; public class Calculator { List costRecords; - - public Calculator(ItemStack itemStack, long amount){ + + public Calculator(ItemStack itemStack, long amount) { int count = 0; costRecords = new ArrayList<>(); costRecords.add(new CostRecord(new ItemRecord(itemStack, amount, false))); List cancellableItems = costRecords.get(0).getCancellableItems(); LOOP2: - while(cancellableItems.size() != 0){ + while (cancellableItems.size() != 0) { if (count > 100) { return; } // all the items possible tp cancel - for(ItemRecord itemRecord : cancellableItems){ + for (ItemRecord itemRecord : cancellableItems) { // all the recipes for one item LOOP1: - for(Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(itemRecord.toItemStack(), null)){ + for (Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler() + .getAllRecipeOf(itemRecord.toItemStack(), null)) { long times = getCount(itemRecord, recipe); ItemRecord buffer = itemRecord.copy(); - buffer.amount = recipe.getOutputAmount(buffer.toItemStack())*times; - CostRecord record = new CostRecord(costRecords.get(costRecords.size()-1), new CostRecord(recipe, times, itemRecord.approx, buffer)); - for(CostRecord costRecord : costRecords){ - if(costRecord.equals(record)){ + buffer.amount = recipe.getOutputAmount(buffer.toItemStack()) * times; + CostRecord record = new CostRecord(costRecords.get(costRecords.size() - 1), + new CostRecord(recipe, times, itemRecord.approx, buffer)); + for (CostRecord costRecord : costRecords) { + if (costRecord.equals(record)) { continue LOOP1; } costRecords.add(record); @@ -50,12 +52,12 @@ public class Calculator { } } - public CostRecord getCost(){ - return costRecords.get(costRecords.size()-1); + public CostRecord getCost() { + return costRecords.get(costRecords.size() - 1); } - protected long getCount(ItemRecord itemRecord, Recipe recipe){ + protected long getCount(ItemRecord itemRecord, Recipe recipe) { long a = recipe.getOutputAmount(itemRecord.toItemStack()); - return (long)Math.ceil(itemRecord.amount/(double)a); + return (long) Math.ceil(itemRecord.amount / (double) a); } } diff --git a/src/main/java/me/towdium/jecalculation/core/CostRecord.java b/src/main/java/me/towdium/jecalculation/core/CostRecord.java index d9d722c..f36bf72 100644 --- a/src/main/java/me/towdium/jecalculation/core/CostRecord.java +++ b/src/main/java/me/towdium/jecalculation/core/CostRecord.java @@ -10,13 +10,13 @@ import java.util.List; /** * @author Towdium */ -public class CostRecord{ +public class CostRecord { private List output; private List input; private List catalyst; private List procedure; - public CostRecord(ItemRecord itemRecord){ + public CostRecord(ItemRecord itemRecord) { output = new ArrayList<>(); input = new ArrayList<>(); catalyst = new LinkedList<>(); @@ -24,21 +24,21 @@ public class CostRecord{ input.add(itemRecord); } - public CostRecord(Recipe recipe, long count, boolean approx, ItemRecord dest){ + public CostRecord(Recipe recipe, long count, boolean approx, ItemRecord dest) { output = new ArrayList<>(); input = new ArrayList<>(); catalyst = new LinkedList<>(); procedure = new ArrayList<>(); boolean b = recipe.isApprox() || approx; - for(ItemStack itemStack : recipe.output){ - if(itemStack != null){ + for (ItemStack itemStack : recipe.output) { + if (itemStack != null) { ItemRecord record = new ItemRecord(itemStack, count); record.approx = b; output.add(record); } } - for(ItemStack itemStack : recipe.input){ - if(itemStack != null){ + for (ItemStack itemStack : recipe.input) { + if (itemStack != null) { ItemRecord record = new ItemRecord(itemStack, count); record.approx = b; input.add(record); @@ -54,31 +54,31 @@ public class CostRecord{ * Generate CostRecord merging two CostRecords * ItemRecord with amount 0 may be left there */ - public CostRecord(CostRecord costRecord1, CostRecord costRecord2){ + public CostRecord(CostRecord costRecord1, CostRecord costRecord2) { output = new ArrayList<>(); - for (ItemRecord record : costRecord1.output){ + for (ItemRecord record : costRecord1.output) { output.add(record.copy()); } input = new ArrayList<>(); - for (ItemRecord record : costRecord1.input){ + for (ItemRecord record : costRecord1.input) { input.add(record.copy()); } catalyst = new LinkedList<>(); - for (ItemRecord record : costRecord1.catalyst){ + for (ItemRecord record : costRecord1.catalyst) { catalyst.add(record.copy()); } procedure = new ArrayList<>(); - for (ItemRecord record : costRecord1.procedure){ + for (ItemRecord record : costRecord1.procedure) { procedure.add(record.copy()); } - for (ItemRecord record : costRecord2.procedure){ + for (ItemRecord record : costRecord2.procedure) { procedure.add(record.copy()); } // merge output LOOP: - for(ItemRecord itemRecordAdd : costRecord2.output){ - for(ItemRecord itemRecordExt : output){ - if(itemRecordAdd.isSameType(itemRecordExt)){ + for (ItemRecord itemRecordAdd : costRecord2.output) { + for (ItemRecord itemRecordExt : output) { + if (itemRecordAdd.isSameType(itemRecordExt)) { itemRecordExt.add(itemRecordAdd); continue LOOP; } @@ -87,9 +87,9 @@ public class CostRecord{ } // merge input LOOP: - for(ItemRecord itemRecordAdd : costRecord2.input){ - for(ItemRecord itemRecordExt : input){ - if(itemRecordAdd.isSameType(itemRecordExt)){ + for (ItemRecord itemRecordAdd : costRecord2.input) { + for (ItemRecord itemRecordExt : input) { + if (itemRecordAdd.isSameType(itemRecordExt)) { itemRecordExt.add(itemRecordAdd); continue LOOP; } @@ -98,13 +98,13 @@ public class CostRecord{ } // cancel catalyst by output LOOP: - for(ItemRecord itemRecordAdd : costRecord2.output){ + for (ItemRecord itemRecordAdd : costRecord2.output) { for (int i = 0; i < catalyst.size(); i++) { ItemRecord itemRecordExt = catalyst.get(i); if (itemRecordAdd.isSameType(itemRecordExt) && itemRecordExt.amount <= itemRecordAdd.amount) { catalyst.remove(i); continue LOOP; - }else if(itemRecordAdd.isSameType(itemRecordExt)) { + } else if (itemRecordAdd.isSameType(itemRecordExt)) { itemRecordExt.minus(itemRecordAdd); continue LOOP; } @@ -112,7 +112,7 @@ public class CostRecord{ } // merge catalyst LOOP: - for(ItemRecord itemRecordAdd : costRecord2.catalyst){ + for (ItemRecord itemRecordAdd : costRecord2.catalyst) { for (ItemRecord itemRecordExt : catalyst) { if (itemRecordAdd.isSameType(itemRecordExt)) { itemRecordExt.add(itemRecordAdd); @@ -122,38 +122,38 @@ public class CostRecord{ catalyst.add(itemRecordAdd.copy()); } // cancel input and output - for(ItemRecord itemRecordIn : input){ - for(ItemRecord itemRecordOut : output){ - if(itemRecordIn.isSameType(itemRecordOut)){ + for (ItemRecord itemRecordIn : input) { + for (ItemRecord itemRecordOut : output) { + if (itemRecordIn.isSameType(itemRecordOut)) { itemRecordIn.cancel(itemRecordOut); } } } } - ImmutableList getCancellableItems(){ + ImmutableList getCancellableItems() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(ItemRecord itemRecord : input){ - if(!itemRecord.isLocked() && itemRecord.amount != 0){ + for (ItemRecord itemRecord : input) { + if (!itemRecord.isLocked() && itemRecord.amount != 0) { builder.add(itemRecord); } } return builder.build(); } - public ImmutableList getOutputStack(){ + public ImmutableList getOutputStack() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(ItemRecord itemRecord : output){ - if(itemRecord.amount != 0){ + for (ItemRecord itemRecord : output) { + if (itemRecord.amount != 0) { builder.add(itemRecord.toItemStack()); } } return builder.build(); } - public ImmutableList getProcedureStack(){ + public ImmutableList getProcedureStack() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (int i = procedure.size()-1; i >=0; i--) { + for (int i = procedure.size() - 1; i >= 0; i--) { ItemRecord itemRecord = procedure.get(i); if (itemRecord.amount != 0) { builder.add(itemRecord.toItemStack()); @@ -162,23 +162,23 @@ public class CostRecord{ return builder.build(); } - public ImmutableList getInputStack(){ + public ImmutableList getInputStack() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(ItemRecord itemRecord : input){ - if(itemRecord.amount != 0){ + for (ItemRecord itemRecord : input) { + if (itemRecord.amount != 0) { builder.add(itemRecord.toItemStack()); } } return builder.build(); } - public ImmutableList getCatalystStack(){ + public ImmutableList getCatalystStack() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); LOOP: - for(ItemRecord itemRecord : catalyst){ - if(itemRecord.amount != 0){ - for(ItemRecord record : input){ - if(itemRecord.isSameType(record) && record.amount != 0){ + for (ItemRecord itemRecord : catalyst) { + if (itemRecord.amount != 0) { + for (ItemRecord record : input) { + if (itemRecord.isSameType(record) && record.amount != 0) { continue LOOP; } } @@ -198,10 +198,10 @@ public class CostRecord{ LOOP: for (ItemRecord itemRecordIn : output) { for (ItemRecord itemRecordExt : ((CostRecord) obj).output) { - if(itemRecordExt.isSameType(itemRecordIn)){ - if(itemRecordExt.amount != itemRecordIn.amount){ + if (itemRecordExt.isSameType(itemRecordIn)) { + if (itemRecordExt.amount != itemRecordIn.amount) { return false; - }else { + } else { continue LOOP; } } @@ -211,10 +211,10 @@ public class CostRecord{ LOOP: for (ItemRecord itemRecordIn : input) { for (ItemRecord itemRecordExt : ((CostRecord) obj).input) { - if(itemRecordExt.isSameType(itemRecordIn)){ - if(itemRecordExt.amount != itemRecordIn.amount){ + if (itemRecordExt.isSameType(itemRecordIn)) { + if (itemRecordExt.amount != itemRecordIn.amount) { return false; - }else { + } else { continue LOOP; } } @@ -224,10 +224,10 @@ public class CostRecord{ LOOP: for (ItemRecord itemRecordIn : ((CostRecord) obj).output) { for (ItemRecord itemRecordExt : output) { - if(itemRecordExt.isSameType(itemRecordIn)){ - if(itemRecordExt.amount != itemRecordIn.amount){ + if (itemRecordExt.isSameType(itemRecordIn)) { + if (itemRecordExt.amount != itemRecordIn.amount) { return false; - }else { + } else { continue LOOP; } } @@ -237,10 +237,10 @@ public class CostRecord{ LOOP: for (ItemRecord itemRecordIn : ((CostRecord) obj).input) { for (ItemRecord itemRecordExt : input) { - if(itemRecordExt.isSameType(itemRecordIn)){ - if(itemRecordExt.amount != itemRecordIn.amount){ + if (itemRecordExt.isSameType(itemRecordIn)) { + if (itemRecordExt.amount != itemRecordIn.amount) { return false; - }else { + } else { continue LOOP; } } diff --git a/src/main/java/me/towdium/jecalculation/core/ItemRecord.java b/src/main/java/me/towdium/jecalculation/core/ItemRecord.java index df6ad66..f4f4791 100644 --- a/src/main/java/me/towdium/jecalculation/core/ItemRecord.java +++ b/src/main/java/me/towdium/jecalculation/core/ItemRecord.java @@ -7,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound; /** * @author Towdium */ -public class ItemRecord{ +public class ItemRecord { Item item; int meta; long amount; @@ -17,21 +17,21 @@ public class ItemRecord{ /** * Generate ItemRecord based on the ItemStack and multiply the amount */ - public ItemRecord(ItemStack itemStack, long multiplier){ + public ItemRecord(ItemStack itemStack, long multiplier) { item = itemStack.getItem(); meta = itemStack.getItemDamage(); amount = ItemStackWrapper.getUnifiedAmount(itemStack) * multiplier; approx = itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("percentage"); } - public ItemRecord(ItemStack itemStack){ + public ItemRecord(ItemStack itemStack) { this(itemStack, 1); } /** * Generate ItemRecord with customized amount */ - public ItemRecord(ItemStack itemStack, long amount, boolean approx){ + public ItemRecord(ItemStack itemStack, long amount, boolean approx) { item = itemStack.getItem(); meta = itemStack.getItemDamage(); this.amount = amount; @@ -50,62 +50,62 @@ public class ItemRecord{ return "itemRecord:" + item.getUnlocalizedName() + " x " + amount; } - protected int getOutputAmount(Recipe recipe){ - for(int i = 0; i<4; i++){ - if(recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta){ + protected int getOutputAmount(Recipe recipe) { + for (int i = 0; i < 4; i++) { + if (recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta) { return ItemStackWrapper.getUnifiedAmount(recipe.output[i]); } } return 0; } - public boolean isSameType(ItemRecord record){ + public boolean isSameType(ItemRecord record) { return item == record.item && meta == record.meta; } - public boolean add(ItemRecord record){ - if (isSameType(record)){ + public boolean add(ItemRecord record) { + if (isSameType(record)) { amount += record.amount; approx = approx || record.approx; return true; - }else { + } else { return false; } } - public boolean minus(ItemRecord record){ - if (isSameType(record)){ + public boolean minus(ItemRecord record) { + if (isSameType(record)) { amount -= record.amount; return true; - }else { + } else { return false; } } - public boolean cancel(ItemRecord record){ - if (isSameType(record)){ - long i = amount>record.amount ? record.amount : amount; + public boolean cancel(ItemRecord record) { + if (isSameType(record)) { + long i = amount > record.amount ? record.amount : amount; amount -= i; record.amount -= i; - if(approx || record.approx){ + if (approx || record.approx) { approx = true; record.approx = true; } - return i!=0; - }else { + return i != 0; + } else { return false; } } - public ItemRecord copy(){ + public ItemRecord copy() { return new ItemRecord(item, meta, amount, approx); } - public ItemStack toItemStack(){ + public ItemStack toItemStack() { ItemStack itemStack = new ItemStack(item, 1, meta); NBTTagCompound tagCompound = new NBTTagCompound(); tagCompound.setLong("amount", amount); - if(approx){ + if (approx) { tagCompound.setBoolean("approx", true); } itemStack.setTagCompound(tagCompound); @@ -122,10 +122,10 @@ public class ItemRecord{ @Override public boolean equals(Object obj) { - if(obj instanceof ItemRecord){ + if (obj instanceof ItemRecord) { ItemRecord record = ((ItemRecord) obj); return record.approx == approx && record.item == item && record.amount == amount && record.meta == meta; - }else { + } else { return false; } } diff --git a/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java b/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java index 3490797..a2c2628 100644 --- a/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java +++ b/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java @@ -9,66 +9,69 @@ import net.minecraft.nbt.NBTTagCompound; */ public class ItemStackWrapper { - public static boolean isTypeEqual(ItemStack one, ItemStack two){ - return one != null && two != null && one.getItem() == two.getItem() && one.getItemDamage() == two.getItemDamage(); + public static boolean isTypeEqual(ItemStack one, ItemStack two) { + return one != null && two != null && one.getItem() == two.getItem() && + one.getItemDamage() == two.getItemDamage(); } - public static boolean isStackEqual(ItemStack one, ItemStack two){ + public static boolean isStackEqual(ItemStack one, ItemStack two) { return ItemStack.areItemStacksEqual(one, two); } - public static int getUnifiedAmount(ItemStack itemStack){ - if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){ + public static int getUnifiedAmount(ItemStack itemStack) { + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { return itemStack.getTagCompound().getInteger("percentage"); - }else { - return itemStack.stackSize*100; + } else { + return itemStack.stackSize * 100; } } - public static String getDisplayAmount(ItemStack itemStack){ - if(itemStack != null){ - if(itemStack.getTagCompound() != null){ - if(itemStack.getTagCompound().getBoolean("mark")){ + public static String getDisplayAmount(ItemStack itemStack) { + if (itemStack != null) { + if (itemStack.getTagCompound() != null) { + if (itemStack.getTagCompound().getBoolean("mark")) { return ""; } - long l = itemStack.getTagCompound().hasKey("amount") ? itemStack.getTagCompound().getLong("amount") : -1; - if(l == 0 && itemStack.stackSize == 0){ + long l = itemStack.getTagCompound().hasKey("amount") ? + itemStack.getTagCompound().getLong("amount") : + -1; + if (l == 0 && itemStack.stackSize == 0) { return ""; } int i = itemStack.getTagCompound().getInteger("percentage"); - if(i != 0){ + if (i != 0) { return i + "%"; - }else{ - if(l==-1){ + } else { + if (l == -1) { return String.valueOf(itemStack.stackSize); } - return getSimplifiedString((l+99)/100, itemStack.getTagCompound().getBoolean("approx")); + return getSimplifiedString((l + 99) / 100, itemStack.getTagCompound().getBoolean("approx")); } - }else { + } else { return String.valueOf(itemStack.stackSize); } - } - else return ""; + } else + return ""; } - public static ItemStack toPercentage(ItemStack itemStack){ - if(itemStack == null){ + public static ItemStack toPercentage(ItemStack itemStack) { + if (itemStack == null) { return null; } - NBT.setInt(itemStack, "percentage", itemStack.stackSize*100); + NBT.setInt(itemStack, "percentage", itemStack.stackSize * 100); itemStack.stackSize = 1; return itemStack; } - public static ItemStack toNormal(ItemStack itemStack){ - if(itemStack == null){ + public static ItemStack toNormal(ItemStack itemStack) { + if (itemStack == null) { return null; } - if(itemStack.hasTagCompound()){ + if (itemStack.hasTagCompound()) { int i = itemStack.getTagCompound().getInteger("percentage"); - itemStack.stackSize = (i+99)/100; + itemStack.stackSize = (i + 99) / 100; itemStack.setTagCompound(null); - }else { + } else { itemStack.stackSize = 1; } itemStack.setTagCompound(null); @@ -76,174 +79,175 @@ public class ItemStackWrapper { return itemStack; } - public static String getSimplifiedString(long l, boolean approx){ + public static String getSimplifiedString(long l, boolean approx) { String s; - if(approx){ - if(l<999){ + if (approx) { + if (l < 999) { s = String.valueOf(l); - }else if(l<9999){ - s = String.format("≈%.1fK", (double)l/1000); - }else if(l<99999){ - s = String.format("≈%.0fK", (double)l/1000); - }else if(l<999999){ - s = String.format("≈%.1fM", (double)l/1000000); - }else if(l<9999999){ - s = String.format("≈%.1fM", (double)l/1000000); - }else if(l<99999999){ - s = String.format("≈%.0fM", (double)l/1000000); - }else if(l<999999999){ - s = String.format("≈%.1fB", (double)l/1000000000); - }else if(l<9999999999L){ - s = String.format("≈%.1fB", (double)l/1000000000); - }else if(l<99999999999L){ - s = String.format("≈%.0fB", (double)l/1000000000); - }else if(l<999999999999L){ - s = String.format("≈%.1fT", (double)l/1000000000000L); - }else if(l<9999999999999L){ - s = String.format("≈%.1fT", (double)l/1000000000000L); - }else if(l<99999999999999L){ - s = String.format("≈%.0fT", (double)l/1000000000000L); - }else if(l<999999999999999L){ - s = String.format("≈%.1fG", (double)l/1000000000000000L); - }else if(l<9999999999999999L){ - s = String.format("≈%.1fG", (double)l/1000000000000000L); - }else { - s = String.format("≈%.0fG", (double)l/1000000000000000L); + } else if (l < 9999) { + s = String.format("≈%.1fK", (double) l / 1000); + } else if (l < 99999) { + s = String.format("≈%.0fK", (double) l / 1000); + } else if (l < 999999) { + s = String.format("≈%.1fM", (double) l / 1000000); + } else if (l < 9999999) { + s = String.format("≈%.1fM", (double) l / 1000000); + } else if (l < 99999999) { + s = String.format("≈%.0fM", (double) l / 1000000); + } else if (l < 999999999) { + s = String.format("≈%.1fB", (double) l / 1000000000); + } else if (l < 9999999999L) { + s = String.format("≈%.1fB", (double) l / 1000000000); + } else if (l < 99999999999L) { + s = String.format("≈%.0fB", (double) l / 1000000000); + } else if (l < 999999999999L) { + s = String.format("≈%.1fT", (double) l / 1000000000000L); + } else if (l < 9999999999999L) { + s = String.format("≈%.1fT", (double) l / 1000000000000L); + } else if (l < 99999999999999L) { + s = String.format("≈%.0fT", (double) l / 1000000000000L); + } else if (l < 999999999999999L) { + s = String.format("≈%.1fG", (double) l / 1000000000000000L); + } else if (l < 9999999999999999L) { + s = String.format("≈%.1fG", (double) l / 1000000000000000L); + } else { + s = String.format("≈%.0fG", (double) l / 1000000000000000L); } - }else { - if(l<999){ + } else { + if (l < 999) { s = String.valueOf(l); - }else if(l<9999){ - s = String.format("%.2fK", (double)l/1000); - }else if(l<99999){ - s = String.format("%.1fK", (double)l/1000); - }else if(l<999999){ - s = String.format("%.0fK", (double)l/1000); - }else if(l<9999999){ - s = String.format("%.2fM", (double)l/1000000); - }else if(l<99999999){ - s = String.format("%.1fM", (double)l/1000000); - }else if(l<999999999){ - s = String.format("%.0fB", (double)l/1000000); - }else if(l<9999999999L){ - s = String.format("%.2fB", (double)l/1000000000); - }else if(l<99999999999L){ - s = String.format("%.1fB", (double)l/1000000000); - }else if(l<999999999999L){ - s = String.format("%.0fT", (double)l/1000000000); - }else if(l<9999999999999L){ - s = String.format("%.2fT", (double)l/1000000000000L); - }else if(l<99999999999999L){ - s = String.format("%.1fT", (double)l/1000000000000L); - }else if(l<999999999999999L){ - s = String.format("%.0fG", (double)l/1000000000000L); - }else if(l<9999999999999999L){ - s = String.format("%.2fG", (double)l/1000000000000000L); - }else if(l<99999999999990999L){ - s = String.format("%.1fG", (double)l/1000000000000000L); - }else { - s = String.format("%.0fG", (double)l/1000000000000000L); + } else if (l < 9999) { + s = String.format("%.2fK", (double) l / 1000); + } else if (l < 99999) { + s = String.format("%.1fK", (double) l / 1000); + } else if (l < 999999) { + s = String.format("%.0fK", (double) l / 1000); + } else if (l < 9999999) { + s = String.format("%.2fM", (double) l / 1000000); + } else if (l < 99999999) { + s = String.format("%.1fM", (double) l / 1000000); + } else if (l < 999999999) { + s = String.format("%.0fB", (double) l / 1000000); + } else if (l < 9999999999L) { + s = String.format("%.2fB", (double) l / 1000000000); + } else if (l < 99999999999L) { + s = String.format("%.1fB", (double) l / 1000000000); + } else if (l < 999999999999L) { + s = String.format("%.0fT", (double) l / 1000000000); + } else if (l < 9999999999999L) { + s = String.format("%.2fT", (double) l / 1000000000000L); + } else if (l < 99999999999999L) { + s = String.format("%.1fT", (double) l / 1000000000000L); + } else if (l < 999999999999999L) { + s = String.format("%.0fG", (double) l / 1000000000000L); + } else if (l < 9999999999999999L) { + s = String.format("%.2fG", (double) l / 1000000000000000L); + } else if (l < 99999999999990999L) { + s = String.format("%.1fG", (double) l / 1000000000000000L); + } else { + s = String.format("%.0fG", (double) l / 1000000000000000L); } } return s; } - public static long getGhostItemAmount(ItemStack itemStack){ - if (itemStack.hasTagCompound()){ + public static long getGhostItemAmount(ItemStack itemStack) { + if (itemStack.hasTagCompound()) { long l = itemStack.getTagCompound().getLong("amount"); - return (l+99)/100; - }else { + return (l + 99) / 100; + } else { return 0; } } public static class NBT { - public static void initNBT(ItemStack itemStack){ - if(!itemStack.hasTagCompound()){ + public static void initNBT(ItemStack itemStack) { + if (!itemStack.hasTagCompound()) { itemStack.setTagCompound(new NBTTagCompound()); } } - public static void setItem(ItemStack dest, String key, ItemStack content){ + public static void setItem(ItemStack dest, String key, ItemStack content) { initNBT(dest); NBTTagCompound buffer = new NBTTagCompound(); - if (content != null){ + if (content != null) { content.writeToNBT(buffer); dest.getTagCompound().setTag(key, buffer); - }else { + } else { dest.getTagCompound().removeTag(key); } } - public static ItemStack getItem(ItemStack itemStack, String key){ + public static ItemStack getItem(ItemStack itemStack, String key) { NBTTagCompound tagCompound = itemStack.getTagCompound(); - if(tagCompound == null){ + if (tagCompound == null) { return null; } NBTTagCompound itemTagCompound = tagCompound.getCompoundTag(key); - if(itemTagCompound == null){ + if (itemTagCompound == null) { return null; } return ItemStack.loadItemStackFromNBT(itemTagCompound); } - public static void setString(ItemStack dest, String key, String value){ + public static void setString(ItemStack dest, String key, String value) { initNBT(dest); dest.getTagCompound().setString(key, value); } - public static void setInt(ItemStack dest, String key, int value){ + public static void setInt(ItemStack dest, String key, int value) { initNBT(dest); dest.getTagCompound().setInteger(key, value); } - public static void setBool(ItemStack dest, String key, boolean value){ + public static void setBool(ItemStack dest, String key, boolean value) { initNBT(dest); dest.getTagCompound().setBoolean(key, value); } - public static void setLong(ItemStack dest, String key, long value){ + public static void setLong(ItemStack dest, String key, long value) { initNBT(dest); dest.getTagCompound().setLong(key, value); } - public static String getString(ItemStack dest, String key){ - if(dest.getTagCompound() != null){ + public static String getString(ItemStack dest, String key) { + if (dest.getTagCompound() != null) { return dest.getTagCompound().getString(key); - } - else return ""; + } else + return ""; } public static boolean getBool(ItemStack dest, String key) { return dest.getTagCompound() != null && dest.getTagCompound().getBoolean(key); } - public static int getInt(ItemStack dest, String key){ - if(dest.getTagCompound() != null){ + public static int getInt(ItemStack dest, String key) { + if (dest.getTagCompound() != null) { return dest.getTagCompound().getInteger(key); - } - else return 0; + } else + return 0; } - public static long getLong(ItemStack dest, String key){ - if(dest.getTagCompound() != null){ + public static long getLong(ItemStack dest, String key) { + if (dest.getTagCompound() != null) { return dest.getTagCompound().getLong(key); - } - else return 0; + } else + return 0; } } public static class Click { - public static boolean leftClick(ItemStack itemStack, boolean doChange){ - if(itemStack == null || itemStack.stackSize>=64){ + public static boolean leftClick(ItemStack itemStack, boolean doChange) { + if (itemStack == null || itemStack.stackSize >= 64) { return false; - }else { - if(doChange){ - if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){ - itemStack.getTagCompound().setInteger("percentage", itemStack.getTagCompound().getInteger("percentage")+1); - }else { + } else { + if (doChange) { + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { + itemStack.getTagCompound() + .setInteger("percentage", itemStack.getTagCompound().getInteger("percentage") + 1); + } else { itemStack.stackSize += 1; } } @@ -251,20 +255,20 @@ public class ItemStackWrapper { } } - public static boolean leftShift(ItemStack itemStack, boolean doChange){ - if(itemStack == null || itemStack.stackSize>=64){ + public static boolean leftShift(ItemStack itemStack, boolean doChange) { + if (itemStack == null || itemStack.stackSize >= 64) { return false; - }else { - if(doChange){ - if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){ + } else { + if (doChange) { + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { int i = itemStack.getTagCompound().getInteger("percentage"); - itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i+10); - }else { - if(itemStack.stackSize == 1){ + itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i + 10); + } else { + if (itemStack.stackSize == 1) { itemStack.stackSize = 10; - }else if(itemStack.stackSize <= 54){ + } else if (itemStack.stackSize <= 54) { itemStack.stackSize += 10; - }else { + } else { itemStack.stackSize = 64; } } @@ -273,19 +277,19 @@ public class ItemStackWrapper { } } - public static boolean rightClick(ItemStack itemStack, boolean doChange){ - if(itemStack == null){ + public static boolean rightClick(ItemStack itemStack, boolean doChange) { + if (itemStack == null) { return false; - }else { - if(doChange){ - if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){ + } else { + if (doChange) { + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { int i = itemStack.getTagCompound().getInteger("percentage"); - if(i == 1 || i == 0){ + if (i == 1 || i == 0) { itemStack.stackSize = 0; return true; } itemStack.getTagCompound().setInteger("percentage", --i); - }else { + } else { itemStack.stackSize -= 1; } } @@ -293,22 +297,22 @@ public class ItemStackWrapper { } } - public static boolean rightShift(ItemStack itemStack, boolean doChange){ - if(itemStack == null){ + public static boolean rightShift(ItemStack itemStack, boolean doChange) { + if (itemStack == null) { return false; - }else { - if(doChange){ - if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){ + } else { + if (doChange) { + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { int i = itemStack.getTagCompound().getInteger("percentage"); - if(i == 0 || i == 1){ + if (i == 0 || i == 1) { itemStack.stackSize = 0; return true; } - itemStack.getTagCompound().setInteger("percentage", i <= 10 ? 1 : i-10); - }else { - if(itemStack.stackSize == 1){ + itemStack.getTagCompound().setInteger("percentage", i <= 10 ? 1 : i - 10); + } else { + if (itemStack.stackSize == 1) { itemStack.stackSize = 0; - }else if(itemStack.stackSize <= 10){ + } else if (itemStack.stackSize <= 10) { itemStack.stackSize = 1; } else { itemStack.stackSize -= 10; diff --git a/src/main/java/me/towdium/jecalculation/core/Recipe.java b/src/main/java/me/towdium/jecalculation/core/Recipe.java index 2384ddc..0d89e44 100644 --- a/src/main/java/me/towdium/jecalculation/core/Recipe.java +++ b/src/main/java/me/towdium/jecalculation/core/Recipe.java @@ -14,13 +14,13 @@ public class Recipe { ItemStack[] input; public Recipe(ItemStack[] output, ItemStack[] input) { - if(output.length != 4 || input.length != 12){ + if (output.length != 4 || input.length != 12) { throw new IllegalArgumentException("Incorrect array size"); } this.output = new ItemStack[4]; for (int i = 0; i < 4; i++) { ItemStack itemstack = output[i]; - if(itemstack != null){ + if (itemstack != null) { boolean flag = false; for (int j = 0; j < i; j++) { if (this.output[j] != null && ItemStackWrapper.isTypeEqual(this.output[j], itemstack)) { @@ -36,12 +36,12 @@ public class Recipe { } this.input = new ItemStack[12]; for (ItemStack itemstack : input) { - if(itemstack != null){ - for(int i=0; i<12; i++){ - if(ItemStackWrapper.isTypeEqual(this.input[i], itemstack)){ + if (itemstack != null) { + for (int i = 0; i < 12; i++) { + if (ItemStackWrapper.isTypeEqual(this.input[i], itemstack)) { this.input[i].stackSize += itemstack.stackSize; break; - } else if (this.input[i] == null){ + } else if (this.input[i] == null) { this.input[i] = itemstack.copy(); break; } @@ -50,20 +50,21 @@ public class Recipe { } } - public ItemStack getOutput(ItemStack itemStack){ - for(int i = 0; i<4; i++){ - if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){ + public ItemStack getOutput(ItemStack itemStack) { + for (int i = 0; i < 4; i++) { + if (ItemStackWrapper.isTypeEqual(output[i], itemStack)) { return output[i]; } } return null; } - public int getOutputIndex(ItemStack itemStack){ - for(int i = 0; i<4; i++){ - if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){ - for(ItemStack buffer : input){ - if(ItemStackWrapper.isTypeEqual(buffer, output[i]) && ItemStackWrapper.getUnifiedAmount(output[i]) getOutput(){ + public ImmutableList getOutput() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(ItemStack itemStack : output){ - if(itemStack != null){ + for (ItemStack itemStack : output) { + if (itemStack != null) { builder.add(itemStack.copy()); } } return builder.build(); } - public ImmutableList getInput(){ + public ImmutableList getInput() { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for(ItemStack itemStack : input){ - if(itemStack != null){ + for (ItemStack itemStack : input) { + if (itemStack != null) { builder.add(itemStack.copy()); } } return builder.build(); } - public boolean isApprox(){ - for(ItemStack itemstack : input){ - if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){ + public boolean isApprox() { + for (ItemStack itemstack : input) { + if (itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")) { return true; } } - for(ItemStack itemstack : output){ - if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){ + for (ItemStack itemstack : output) { + if (itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")) { return true; } } return false; } - public static class ByteBufUtl{ - public static Recipe fromByte(ByteBuf buf){ + public static class ByteBufUtl { + public static Recipe fromByte(ByteBuf buf) { short a = buf.readShort(); - if(a == 0){ + if (a == 0) { return null; } short b = buf.readShort(); ItemStack[] output = new ItemStack[4]; ItemStack[] input = new ItemStack[12]; - for(int i=0; i 999){ + public void onTooltip(ItemTooltipEvent event) { + if (event.entityPlayer.openContainer instanceof ContainerCalculator) { + long l = event.itemStack.hasTagCompound() ? + (event.itemStack.getTagCompound().getLong("amount") + 99) / 100 : + 0; + if (l > 999) { event.toolTip.add("Amount: " + l); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java b/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java index 1434a0a..9f375c5 100644 --- a/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java +++ b/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java @@ -2,23 +2,23 @@ package me.towdium.jecalculation.gui; import cpw.mods.fml.common.network.IGuiHandler; import me.towdium.jecalculation.JustEnoughCalculation; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; +import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; import me.towdium.jecalculation.gui.guis.calculator.ContainerCalculator; import me.towdium.jecalculation.gui.guis.calculator.GuiCalculator; -import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor; import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor; import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker; import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer; import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; /** * @author Towdium */ public class GuiHandler implements IGuiHandler { - public static final class GuiId{ + public static final class GuiId { public static final int CALCULATOR = 0; public static final int RECIPE_VIEWER = 1; public static final int RECIPE_EDITOR = 2; @@ -33,10 +33,15 @@ public class GuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { - case GuiId.CALCULATOR: return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem())); - case GuiId.RECIPE_VIEWER: return new GuiRecipeViewer(new ContainerRecipeViewer(), null); - case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor(), null); - case GuiId.RECIPE_PICKER: return new GuiRecipePicker(new ContainerRecipe(), null, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null)); + case GuiId.CALCULATOR: + return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem())); + case GuiId.RECIPE_VIEWER: + return new GuiRecipeViewer(new ContainerRecipeViewer(), null); + case GuiId.RECIPE_EDITOR: + return new GuiRecipeEditor(new ContainerRecipeEditor(), null); + case GuiId.RECIPE_PICKER: + return new GuiRecipePicker(new ContainerRecipe(), null, + JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null)); } return null; } diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java index edde4c0..92b34ba 100644 --- a/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java +++ b/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java @@ -1,6 +1,7 @@ package me.towdium.jecalculation.gui.commom; import codechicken.nei.guihook.GuiContainerManager; +import me.towdium.jecalculation.core.ItemStackWrapper; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -10,7 +11,6 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import me.towdium.jecalculation.core.ItemStackWrapper; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -22,15 +22,22 @@ import java.lang.reflect.Method; */ public abstract class GuiJustEnoughCalculation extends GuiContainer { protected GuiScreen parent; - protected RenderItem renderItem = new RenderItem(){ + protected RenderItem renderItem = new RenderItem() { @Override - public void renderItemOverlayIntoGUI(FontRenderer p_77021_1_, TextureManager p_77021_2_, ItemStack p_77021_3_, int p_77021_4_, int p_77021_5_, String text) { - if(p_77021_3_!=null && p_77021_3_.hasTagCompound() && p_77021_3_.getTagCompound().getBoolean("jecalculation")){ + public void renderItemOverlayIntoGUI(FontRenderer p_77021_1_, + TextureManager p_77021_2_, + ItemStack p_77021_3_, + int p_77021_4_, + int p_77021_5_, + String text) { + if (p_77021_3_ != null && p_77021_3_.hasTagCompound() && + p_77021_3_.getTagCompound().getBoolean("jecalculation")) { boolean b = p_77021_1_.getUnicodeFlag(); p_77021_1_.setUnicodeFlag(true); - super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, ItemStackWrapper.getDisplayAmount(p_77021_3_)); + super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, + ItemStackWrapper.getDisplayAmount(p_77021_3_)); p_77021_1_.setUnicodeFlag(b); - }else { + } else { super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, text); } @@ -51,13 +58,13 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer { mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer); } - public void click(int mouseX, int mouseY, int mouseButton){ + public void click(int mouseX, int mouseY, int mouseButton) { this.mouseClicked(mouseX, mouseY, mouseButton); } - public void click(int index){ - for(Object button : buttonList){ - if(((GuiButton) button).id == index){ + public void click(int index) { + for (Object button : buttonList) { + if (((GuiButton) button).id == index) { actionPerformed(((GuiButton) button)); } } @@ -67,11 +74,12 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer { fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color); } - public void updateLayout(){} + public void updateLayout() { + } @Override - protected void keyTyped(char typedChar, int keyCode){ - if(keyCode == 1){ + protected void keyTyped(char typedChar, int keyCode) { + if (keyCode == 1) { mc.displayGuiScreen(parent); } } @@ -79,7 +87,7 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer { @Override public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) { RenderItem buffer1 = itemRender; - RenderItem buffer2 = GuiContainerManager.drawItems; + RenderItem buffer2 = GuiContainerManager.drawItems; itemRender = renderItem; GuiContainerManager.drawItems = renderItem; super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); @@ -87,14 +95,15 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer { GuiContainerManager.drawItems = buffer2; } - protected Slot getSlotUnderMouse(int x, int y){ + protected Slot getSlotUnderMouse(int x, int y) { Method getSlot = null; try { getSlot = GuiContainer.class.getDeclaredMethod("getSlotAtPosition", int.class, int.class); } catch (NoSuchMethodException ignored) { try { getSlot = GuiContainer.class.getDeclaredMethod("func_146975_c", int.class, int.class); - } catch (NoSuchMethodException ignored_) {} + } catch (NoSuchMethodException ignored_) { + } } try { getSlot.setAccessible(true); diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java b/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java index 6941e62..9d24ad0 100644 --- a/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java +++ b/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java @@ -1,8 +1,5 @@ package me.towdium.jecalculation.gui.commom; -import java.util.ArrayList; -import java.util.List; - import codechicken.nei.VisiblityData; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.TaggedInventoryArea; @@ -16,29 +13,40 @@ import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; /** * CODE IS DONE BY Zyin055 * A GuiScreen replacement that supports putting tooltips onto GuiButtons. * SEE HERE: www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437428-guide-1-7-2-how-to-make-button-tooltips */ -public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler -{ +public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler { int mousedOverButtonId = -1; - /** Show a white "?" in the top right part of any button with a tooltip assigned to it */ + /** + * Show a white "?" in the top right part of any button with a tooltip assigned to it + */ public static boolean ShowTooltipButtonEffect = true; - /** Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered */ + /** + * Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered + */ public static boolean ShowTooltipButtonMouseoverEffect = true; - /** Putting this string into a tooltip will cause a line break */ + /** + * Putting this string into a tooltip will cause a line break + */ public String tooltipNewlineDelimeter = "_p"; - /** The amount of time in milliseconds until a tooltip is rendered */ + /** + * The amount of time in milliseconds until a tooltip is rendered + */ public long tooltipDelay = 900; - /** The maximum width in pixels a tooltip can occupy before word wrapping occurs */ + /** + * The maximum width in pixels a tooltip can occupy before word wrapping occurs + */ public int tooltipMaxWidth = 150; protected int tooltipXOffset = 0; @@ -56,18 +64,17 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen @Override protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_); - if(ShowTooltipButtonEffect) + if (ShowTooltipButtonEffect) RenderTooltipButtonEffect(); if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null) - for(Object button : buttonList){ - if(((GuiButton) button).id == mousedOverButtonId){ + for (Object button : buttonList) { + if (((GuiButton) button).id == mousedOverButtonId) { RenderTooltipButtonMouseoverEffect(((GuiButton) button)); } } } - public void drawScreen(int mouseX, int mouseY, float f) - { + public void drawScreen(int mouseX, int mouseY, float f) { for (Object button : buttonList) { if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) { mousedOverButtonId = ((GuiButton) button).id; @@ -110,45 +117,38 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen /** * This method must be overriden. Gets a tooltip String for a specific button. * Recommended to use a switch/case statement for buttonId for easy implementation. + * * @param buttonId The ID of the button this tooltip corresponds to * @return The tooltip string for the specified buttonId. null if no tooltip exists for this button. */ protected abstract String GetButtonTooltip(int buttonId); /** - * Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons + * Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons * that are being mouseovered. */ - protected void DrawTooltipScreen(int mouseX, int mouseY) - { - - + protected void DrawTooltipScreen(int mouseX, int mouseY) { //find out which button is being mouseovered //calculate how long this button has been mouseovered for - if(mousedOverButtonId > -1) - { + if (mousedOverButtonId > -1) { long systemTime = System.currentTimeMillis(); - if(prevSystemTime > 0) + if (prevSystemTime > 0) mouseoverTime += systemTime - prevSystemTime; prevSystemTime = systemTime; - } - else - { + } else { mouseoverTime = 0; } //render the button's tooltip - if(mouseoverTime > tooltipDelay) - { + if (mouseoverTime > tooltipDelay) { String tooltip = GetButtonTooltip(mousedOverButtonId); - if(tooltip != null) - { + if (tooltip != null) { RenderTooltip(mouseX, mouseY, tooltip); } } @@ -156,26 +156,27 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen /** * Determines if a GuiButton is being mouseovered. + * * @return true if this button is mouseovered */ - private boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button) - { - return mouseX >= button.xPosition + button.getButtonWidth() - 10 && mouseX <= button.xPosition + button.getButtonWidth() && - mouseY >= button.yPosition && mouseY <= button.yPosition + 10; + private boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button) { + return mouseX >= button.xPosition + button.getButtonWidth() - 10 && + mouseX <= button.xPosition + button.getButtonWidth() && mouseY >= button.yPosition && + mouseY <= button.yPosition + 10; } /** * Render anything special onto all buttons that have tooltips assigned to them. */ - private void RenderTooltipButtonEffect() - { + private void RenderTooltipButtonEffect() { for (Object buttonObj : buttonList) { GuiButton button = ((GuiButton) buttonObj); if (GetButtonTooltip(button.id) != null) { boolean flag = fontRendererObj.getUnicodeFlag(); fontRendererObj.setUnicodeFlag(true); - fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 -guiLeft, button.yPosition + 1 - guiTop, 14737632); + fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 - guiLeft, + button.yPosition + 1 - guiTop, 14737632); fontRendererObj.setUnicodeFlag(flag); } } @@ -184,36 +185,35 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen /** * Render anything special onto buttons that have tooltips assigned to them when they are mousevered. */ - private void RenderTooltipButtonMouseoverEffect(GuiButton button) - { + private void RenderTooltipButtonMouseoverEffect(GuiButton button) { boolean flag = fontRendererObj.getUnicodeFlag(); fontRendererObj.setUnicodeFlag(true); - fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7 - guiLeft, button.yPosition+1 - guiTop, 14737632); + fontRendererObj + .drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition + button.getButtonWidth() - 7 - guiLeft, + button.yPosition + 1 - guiTop, 14737632); fontRendererObj.setUnicodeFlag(flag); } /** * Renders a tooltip at (x,y). */ - private void RenderTooltip(int x, int y, String tooltip) - { + private void RenderTooltip(int x, int y, String tooltip) { String[] tooltipArray = ParseTooltipArrayFromString(tooltip); this.drawHoveringText(ImmutableList.copyOf(tooltipArray), x, y, fontRendererObj); } /** * Converts a String representation of a tooltip into a String[], and also decodes any font codes used. + * * @param s Ex: "Hello,_nI am your _ltooltip_r and you love me." * @return An array of Strings such that each String width does not exceed tooltipMaxWidth */ - private String[] ParseTooltipArrayFromString(String s) - { + private String[] ParseTooltipArrayFromString(String s) { s = DecodeStringCodes(s); String[] tooltipSections = s.split(tooltipNewlineDelimeter); ArrayList tooltipArrayList = new ArrayList(); - for(String section : tooltipSections) - { + for (String section : tooltipSections) { String tooltip = ""; String[] tooltipWords = section.split(" "); @@ -238,45 +238,29 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen /** * Decodes any font codes into something useable by the fontRendererObj. + * * @param s E.x.: "Hello,_nI am your _ltooltip_r and you love me." * @return E.x. output (html not included):
"Hello,
I am your tooltip and you love me." */ - private String DecodeStringCodes(String s) - { - return s.replace("_0", FontCodes.BLACK) - .replace("_1", FontCodes.DARK_BLUE) - .replace("_2", FontCodes.DARK_GREEN) - .replace("_3", FontCodes.DARK_AQUA) - .replace("_4", FontCodes.DARK_RED) - .replace("_5", FontCodes.DARK_PURPLE) - .replace("_6", FontCodes.GOLD) - .replace("_7", FontCodes.GRAY) - .replace("_8", FontCodes.DARK_GREY) - .replace("_9", FontCodes.BLUE) - .replace("_a", FontCodes.GREEN) - .replace("_b", FontCodes.AQUA) - .replace("_c", FontCodes.RED) - .replace("_d", FontCodes.LIGHT_PURPLE) - .replace("_e", FontCodes.YELLOW) - .replace("_f", FontCodes.WHITE) - .replace("_k", FontCodes.OBFUSCATED) - .replace("_l", FontCodes.BOLD) - .replace("_m", FontCodes.STRIKETHROUGH) - .replace("_n", FontCodes.UNDERLINE) - .replace("_o", FontCodes.ITALICS) - .replace("_r", FontCodes.RESET); + private String DecodeStringCodes(String s) { + return s.replace("_0", FontCodes.BLACK).replace("_1", FontCodes.DARK_BLUE).replace("_2", FontCodes.DARK_GREEN) + .replace("_3", FontCodes.DARK_AQUA).replace("_4", FontCodes.DARK_RED) + .replace("_5", FontCodes.DARK_PURPLE).replace("_6", FontCodes.GOLD).replace("_7", FontCodes.GRAY) + .replace("_8", FontCodes.DARK_GREY).replace("_9", FontCodes.BLUE).replace("_a", FontCodes.GREEN) + .replace("_b", FontCodes.AQUA).replace("_c", FontCodes.RED).replace("_d", FontCodes.LIGHT_PURPLE) + .replace("_e", FontCodes.YELLOW).replace("_f", FontCodes.WHITE).replace("_k", FontCodes.OBFUSCATED) + .replace("_l", FontCodes.BOLD).replace("_m", FontCodes.STRIKETHROUGH).replace("_n", FontCodes.UNDERLINE) + .replace("_o", FontCodes.ITALICS).replace("_r", FontCodes.RESET); } /*** * Gets the width of the tooltip in pixels. */ - private int GetTooltipWidth(String[] tooltipArray) - { + private int GetTooltipWidth(String[] tooltipArray) { int longestWidth = 0; - for(String s : tooltipArray) - { + for (String s : tooltipArray) { int width = mc.fontRenderer.getStringWidth(s); - if(width > longestWidth) + if (width > longestWidth) longestWidth = width; } return longestWidth; @@ -285,11 +269,9 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen /** * Gets the height of the tooltip in pixels. */ - private int GetTooltipHeight(String[] tooltipArray) - { + private int GetTooltipHeight(String[] tooltipArray) { int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2; - if (tooltipArray.length > 1) - { + if (tooltipArray.length > 1) { tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT; } return tooltipHeight; @@ -312,7 +294,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen @Override public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) { - itemStack.stackSize=0; + itemStack.stackSize = 0; return false; } @@ -322,8 +304,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen } - public class FontCodes - { + public class FontCodes { //color codes for rendered strings public static final String BLACK = "\2470"; public static final String DARK_BLUE = "\2471"; diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/ContainerRecipe.java b/src/main/java/me/towdium/jecalculation/gui/commom/recipe/ContainerRecipe.java index 1cc4480..cf356e3 100644 --- a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/ContainerRecipe.java +++ b/src/main/java/me/towdium/jecalculation/gui/commom/recipe/ContainerRecipe.java @@ -1,12 +1,12 @@ package me.towdium.jecalculation.gui.commom.recipe; import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.core.ItemStackWrapper; +import me.towdium.jecalculation.core.Recipe; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import me.towdium.jecalculation.core.ItemStackWrapper; -import me.towdium.jecalculation.core.Recipe; /** @@ -14,26 +14,30 @@ import me.towdium.jecalculation.core.Recipe; */ public class ContainerRecipe extends Container { - public ContainerRecipe(){ + public ContainerRecipe() { InventoryRecipe inventoryRecipe = new InventoryRecipe(); int i, left, top; - i = 0; left = 9; top = 9; - for(int a = 0; a < 2; a++){ - for(int b =0; b < 2; b++){ - addSlotToContainer(new Slot(inventoryRecipe,i+2*a+b,left+b*59,top+a*24)); + i = 0; + left = 9; + top = 9; + for (int a = 0; a < 2; a++) { + for (int b = 0; b < 2; b++) { + addSlotToContainer(new Slot(inventoryRecipe, i + 2 * a + b, left + b * 59, top + a * 24)); } } - i = 4; left = 9; top = 69; - for(int a = 0; a < 4; a++){ - for(int b =0; b < 3; b++){ - addSlotToContainer(new Slot(inventoryRecipe,i+3*a+b,left+b*59,top+a*24)); + i = 4; + left = 9; + top = 69; + for (int a = 0; a < 4; a++) { + for (int b = 0; b < 3; b++) { + addSlotToContainer(new Slot(inventoryRecipe, i + 3 * a + b, left + b * 59, top + a * 24)); } } } @Override public Slot getSlot(int p_75139_1_) { - if(p_75139_1_ <= 15) + if (p_75139_1_ <= 15) return super.getSlot(p_75139_1_); else return null; @@ -46,20 +50,20 @@ public class ContainerRecipe extends Container { @Override public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - if(slotId<0 || slotId>=16){ + if (slotId < 0 || slotId >= 16) { return null; } Slot slot = getSlot(slotId); - if(slot != null){ + if (slot != null) { ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex()); - if(itemStack != null){ - if(clickedButton == 0 && mode == 0){ + if (itemStack != null) { + if (clickedButton == 0 && mode == 0) { ItemStackWrapper.Click.leftClick(slot.getStack(), true); - }else if(clickedButton == 0 && mode == 1){ + } else if (clickedButton == 0 && mode == 1) { ItemStackWrapper.Click.leftShift(slot.getStack(), true); - }else if(clickedButton == 1 && mode == 0){ + } else if (clickedButton == 1 && mode == 0) { ItemStackWrapper.Click.rightClick(slot.getStack(), true); - }else if(clickedButton == 1 && mode == 1){ + } else if (clickedButton == 1 && mode == 1) { ItemStackWrapper.Click.rightShift(slot.getStack(), true); } slot.putStack(itemStack.stackSize == 0 ? null : itemStack); @@ -78,33 +82,33 @@ public class ContainerRecipe extends Container { return null; } - public Recipe buildRecipe(){ + public Recipe buildRecipe() { ItemStack[] output = new ItemStack[4]; boolean flag1 = false, flag2 = false; - for(int i=0; i<4; i++){ + for (int i = 0; i < 4; i++) { ItemStack buffer = getSlot(i).getStack(); - if(buffer != null && buffer.hasTagCompound()){ + if (buffer != null && buffer.hasTagCompound()) { buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID); - if(buffer.getTagCompound().hasNoTags()){ + if (buffer.getTagCompound().hasNoTags()) { buffer.setTagCompound(null); } } output[i] = buffer; - if(output[i] != null){ + if (output[i] != null) { flag1 = true; } } ItemStack[] input = new ItemStack[12]; - for(int i=4; i<16; i++){ + for (int i = 4; i < 16; i++) { ItemStack buffer = getSlot(i).getStack(); - if(buffer != null && buffer.hasTagCompound()){ + if (buffer != null && buffer.hasTagCompound()) { buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID); - if(buffer.getTagCompound().hasNoTags()){ + if (buffer.getTagCompound().hasNoTags()) { buffer.setTagCompound(null); } } - input[i-4] = buffer; - if(input[i-4] != null){ + input[i - 4] = buffer; + if (input[i - 4] != null) { flag2 = true; } } diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/GuiRecipe.java b/src/main/java/me/towdium/jecalculation/gui/commom/recipe/GuiRecipe.java index 8a51597..a4af5e1 100644 --- a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/GuiRecipe.java +++ b/src/main/java/me/towdium/jecalculation/gui/commom/recipe/GuiRecipe.java @@ -1,6 +1,7 @@ package me.towdium.jecalculation.gui.commom.recipe; import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.core.ItemStackWrapper; import me.towdium.jecalculation.core.Recipe; import me.towdium.jecalculation.gui.commom.GuiTooltipScreen; import net.minecraft.client.gui.GuiButton; @@ -11,7 +12,6 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import me.towdium.jecalculation.core.ItemStackWrapper; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -31,39 +31,45 @@ public class GuiRecipe extends GuiTooltipScreen { public void initGui() { super.initGui(); int i, left, top; - i = 0; left = 31 + guiLeft; top = 7 + guiTop; - for(int a = 0; a < 2; a++){ - for(int b =0; b < 2; b++){ - buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "#")); + i = 0; + left = 31 + guiLeft; + top = 7 + guiTop; + for (int a = 0; a < 2; a++) { + for (int b = 0; b < 2; b++) { + buttonList.add(new GuiButton(i + 2 * a + b, left + b * 59, top + a * 24, 20, 20, "#")); } } - i = 4; left = 31 + guiLeft; top = 67 + guiTop; - for(int a = 0; a < 4; a++){ - for(int b =0; b < 3; b++){ - buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "#")); + i = 4; + left = 31 + guiLeft; + top = 67 + guiTop; + for (int a = 0; a < 4; a++) { + for (int b = 0; b < 3; b++) { + buttonList.add(new GuiButton(i + 3 * a + b, left + b * 59, top + a * 24, 20, 20, "#")); } } } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipe.png")); + this.mc.getTextureManager() + .bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipe.png")); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); - if(activeSlot != -1){ + if (activeSlot != -1) { Slot slot = inventorySlots.getSlot(activeSlot); - this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20); + this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 2, + this.guiTop + slot.yDisplayPosition - 2, 176, 0, 20, 20); } } @Override - protected void actionPerformed(GuiButton button){ + protected void actionPerformed(GuiButton button) { int buttonId = button.id; - if(buttonId <= 15){ + if (buttonId <= 15) { Slot slot = inventorySlots.getSlot(buttonId); - if(button.displayString.equals("#")){ + if (button.displayString.equals("#")) { slot.putStack(ItemStackWrapper.toPercentage(slot.getStack())); button.displayString = "%"; - }else { + } else { slot.putStack(ItemStackWrapper.toNormal(slot.getStack())); button.displayString = "#"; } @@ -93,9 +99,9 @@ public class GuiRecipe extends GuiTooltipScreen { @Override protected void keyTyped(char typedChar, int keyCode) { if (keyCode == 1) { - if(activeSlot != -1){ + if (activeSlot != -1) { setActiveSlot(-1); - }else { + } else { super.keyTyped(typedChar, keyCode); } } @@ -104,11 +110,11 @@ public class GuiRecipe extends GuiTooltipScreen { @Override protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { boolean b = false; - if(slotIn != null){ + if (slotIn != null) { b = slotIn.getHasStack(); } super.handleMouseClick(slotIn, slotId, clickedButton, clickType); - if(slotIn != null && b && !slotIn.getHasStack()){ + if (slotIn != null && b && !slotIn.getHasStack()) { ((GuiButton) buttonList.get(slotIn.getSlotIndex())).displayString = "#"; } } @@ -121,40 +127,40 @@ public class GuiRecipe extends GuiTooltipScreen { this.activeSlot = activeSlot; } - public void displayRecipe(Recipe recipe){ + public void displayRecipe(Recipe recipe) { List output = recipe.getOutput(); List input = recipe.getInput(); - for(int i=0; i<4; i++){ - if(i(27); @@ -89,41 +89,45 @@ public class GuiCalculator extends GuiTooltipScreen{ @Override public void initGui() { super.initGui(); - buttonLeft = new GuiButton(4, guiLeft+7, guiTop+139, 20, 20, "<"); - buttonRight = new GuiButton(5, guiLeft+65, guiTop+139, 20, 20, ">"); - buttonEdit = new GuiButton(3, guiLeft+7, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.edit")); + buttonLeft = new GuiButton(4, guiLeft + 7, guiTop + 139, 20, 20, "<"); + buttonRight = new GuiButton(5, guiLeft + 65, guiTop + 139, 20, 20, ">"); + buttonEdit = new GuiButton(3, guiLeft + 7, guiTop + 53, 79, 20, + StatCollector.translateToLocal("gui.calculator.edit")); //buttonCalculate = new GuiButton(1, guiLeft+111, guiTop+7, 58, 20, StatCollector.translateToLocal("gui.calculator.calculate")); - buttonView = new GuiButton(7, guiLeft+90, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.view")); + buttonView = new GuiButton(7, guiLeft + 90, guiTop + 53, 79, 20, + StatCollector.translateToLocal("gui.calculator.view")); //buttonList.add(buttonCalculate); - buttonList.add(new GuiButton(2, guiLeft+101, guiTop+7, 68, 20, StatCollector.translateToLocal("gui.calculator.add"))); + buttonList.add(new GuiButton(2, guiLeft + 101, guiTop + 7, 68, 20, + StatCollector.translateToLocal("gui.calculator.add"))); buttonList.add(buttonEdit); buttonList.add(buttonView); buttonList.add(buttonLeft); buttonList.add(buttonRight); - buttonMode = new GuiButton(6, guiLeft+89, guiTop+139, 80, 20, StatCollector.translateToLocal("gui.calculator.input")); + buttonMode = new GuiButton(6, guiLeft + 89, guiTop + 139, 80, 20, + StatCollector.translateToLocal("gui.calculator.input")); buttonList.add(buttonMode); - textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 57, 18); + textFieldAmount = new GuiTextField(fontRendererObj, guiLeft + 39, guiTop + 8, 57, 18); Slot dest = inventorySlots.getSlot(0); - ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem(); + ItemStack itemStack = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem(); dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest")); ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem(); - for(int i=0; i idents = new ArrayList<>(); LOOP: - for(ICraftingHandler handler : GuiCraftingRecipe.craftinghandlers){ - if(handler instanceof TemplateRecipeHandler){ - if(((TemplateRecipeHandler) handler).getOverlayIdentifier() == null){ + for (ICraftingHandler handler : GuiCraftingRecipe.craftinghandlers) { + if (handler instanceof TemplateRecipeHandler) { + if (((TemplateRecipeHandler) handler).getOverlayIdentifier() == null) { continue; } - for (String id : idents){ - if(((TemplateRecipeHandler) handler).getOverlayIdentifier().equals(id) ){ + for (String id : idents) { + if (((TemplateRecipeHandler) handler).getOverlayIdentifier().equals(id)) { continue LOOP; } } @@ -131,7 +135,7 @@ public class GuiCalculator extends GuiTooltipScreen{ } } String[] strings = new String[idents.size()]; - for(int i=0; i 0){ + this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 2, + this.guiTop + slot.yDisplayPosition - 2, 176, 0, 20, 20); + } else if (activeSlot > 0) { Slot slot = inventorySlots.getSlot(activeSlot); - this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-1, this.guiTop+slot.yDisplayPosition-1, 196, 0, 18, 18); + this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 1, + this.guiTop + slot.yDisplayPosition - 1, 196, 0, 18, 18); } textFieldAmount.drawTextBox(); drawMissingTexture(); @@ -160,24 +167,29 @@ public class GuiCalculator extends GuiTooltipScreen{ protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_); fontRendererObj.drawString("x", 30, 13, 4210752); - drawCenteredStringWithoutShadow(fontRendererObj, StatCollector.translateToLocal("gui.calculator.recent"), 143, 36, 4210752); + drawCenteredStringWithoutShadow(fontRendererObj, StatCollector.translateToLocal("gui.calculator.recent"), 143, + 36, 4210752); drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 0xFFFFFF); } @Override protected String GetButtonTooltip(int buttonId) { - switch (buttonId){ - case 2: return StatCollector.translateToLocal("gui.calculator.addTooltip"); - case 3: return StatCollector.translateToLocal("gui.calculator.editTooltip"); - case 6: return StatCollector.translateToLocal("gui.calculator.modeTooltip"); - case 7: return StatCollector.translateToLocal("gui.calculator.viewTooltip"); + switch (buttonId) { + case 2: + return StatCollector.translateToLocal("gui.calculator.addTooltip"); + case 3: + return StatCollector.translateToLocal("gui.calculator.editTooltip"); + case 6: + return StatCollector.translateToLocal("gui.calculator.modeTooltip"); + case 7: + return StatCollector.translateToLocal("gui.calculator.viewTooltip"); } return null; } @Override - protected void actionPerformed(GuiButton button){ - switch (button.id){ + protected void actionPerformed(GuiButton button) { + switch (button.id) { /*case 1: if(inventorySlots.getSlot(0).getStack() != null){ mode = EnumMode.INPUT; @@ -185,31 +197,34 @@ public class GuiCalculator extends GuiTooltipScreen{ } break;*/ case 2: - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); + JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), + textFieldAmount.getText()); mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this)); break; case 3: List list; if (activeSlot == -1) { - list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(0).getStack(), null); - }else { - list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(activeSlot).getStack(), null); + list = JustEnoughCalculation.proxy.getPlayerHandler() + .getAllRecipeIndexOf(inventorySlots.getSlot(0).getStack(), null); + } else { + list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf( + inventorySlots.getSlot(activeSlot).getStack(), null); } mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, list)); break; case 4: - if(page>1){ + if (page > 1) { page--; } break; case 5: - if(page 27 && s.getStack() != null){ + Slot s = getSlotUnderMouse(mouseX, mouseY); + if (s != null && s.getSlotIndex() > 27 && s.getStack() != null) { inventorySlots.getSlot(0).putStack(s.getStack()); mode = EnumMode.INPUT; refreshRecipe(); updateLayout(); - }else if(s != null && s.getSlotIndex() > 0 && s.getSlotIndex() <= 27 && s.getStack() != null){ + } else if (s != null && s.getSlotIndex() > 0 && s.getSlotIndex() <= 27 && s.getStack() != null) { GuiCraftingRecipe.openRecipeGui("item", s.getStack().copy()); } - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); + JustEnoughCalculation.proxy.getPlayerHandler() + .syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); //Slot slot = getSlotUnderMouse(mouseX, mouseY); /*if(slot != null && slot.getSlotIndex() == 0 && mouseButton == 0){ setActiveSlot(slot.getSlotIndex()); @@ -280,26 +297,27 @@ public class GuiCalculator extends GuiTooltipScreen{ } @Override - protected void keyTyped(char typedChar, int keyCode){ - if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)){ - if(keyCode == 1){ - if(activeSlot != -1){ + protected void keyTyped(char typedChar, int keyCode) { + if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)) { + if (keyCode == 1) { + if (activeSlot != -1) { inventorySlots.getSlot(activeSlot).putStack(buffer); setActiveSlot(-1); - }else { + } else { super.keyTyped(typedChar, keyCode); } } } else { - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); + JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), + textFieldAmount.getText()); refreshRecipe(); updateLayout(); } } - public void updateLayout(){ - switch (mode){ + public void updateLayout() { + switch (mode) { case OUTPUT: buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.output"); break; @@ -313,36 +331,42 @@ public class GuiCalculator extends GuiTooltipScreen{ buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.catalyst"); break; } - boolean b = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null); - if(activeSlot == -1){ + boolean b = JustEnoughCalculation.proxy.getPlayerHandler() + .getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null); + if (activeSlot == -1) { buttonEdit.enabled = b; - }else { - buttonEdit.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(activeSlot).getStack(), null); + } else { + buttonEdit.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf( + inventorySlots.getSlot(activeSlot).getStack(), null); } //buttonCalculate.enabled = b; buttonView.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipe(null); - if(costRecord != null){ - switch (mode){ + if (costRecord != null) { + switch (mode) { case OUTPUT: - total = (costRecord.getOutputStack().size()+26)/27; - fillSlotsWith(costRecord.getOutputStack(), (page-1)*27);break; + total = (costRecord.getOutputStack().size() + 26) / 27; + fillSlotsWith(costRecord.getOutputStack(), (page - 1) * 27); + break; case PROCEDURE: - total = (costRecord.getProcedureStack().size()+26)/27; - fillSlotsWith(costRecord.getProcedureStack(), (page-1)*27);break; + total = (costRecord.getProcedureStack().size() + 26) / 27; + fillSlotsWith(costRecord.getProcedureStack(), (page - 1) * 27); + break; case INPUT: - total = (costRecord.getInputStack().size()+26)/27; - fillSlotsWith(costRecord.getInputStack(), (page-1)*27);break; + total = (costRecord.getInputStack().size() + 26) / 27; + fillSlotsWith(costRecord.getInputStack(), (page - 1) * 27); + break; case CATALYST: - total = (costRecord.getCatalystStack().size()+26)/27; - fillSlotsWith(costRecord.getCatalystStack(), (page-1)*27);break; + total = (costRecord.getCatalystStack().size() + 26) / 27; + fillSlotsWith(costRecord.getCatalystStack(), (page - 1) * 27); + break; } - }else { + } else { fillSlotsWith(new ArrayList(), 0); total = 0; } buttonLeft.enabled = page != 1; buttonRight.enabled = page < total; - if(JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()){ + if (JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()) { checkItem(); } } @@ -352,43 +376,44 @@ public class GuiCalculator extends GuiTooltipScreen{ } public void setActiveSlot(int activeSlot) { - if(activeSlot == -1){ - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); - }else { + if (activeSlot == -1) { + JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), + textFieldAmount.getText()); + } else { buffer = inventorySlots.getSlot(activeSlot).getStack(); } this.activeSlot = activeSlot; updateLayout(); } - public void onOpen(){ - if(inventorySlots.getSlot(0).getStack() != null){ + public void onOpen() { + if (inventorySlots.getSlot(0).getStack() != null) { refreshRecipe(); } - if(init){ + if (init) { updateLayout(); } } - protected void fillSlotsWith(List itemStacks, int start){ + protected void fillSlotsWith(List itemStacks, int start) { int pos = 1; - for(int i=start; i15 ? 0 : 15-d; + int d = (int) (amount / (double) ItemStackWrapper.getGhostItemAmount(itemStack) * 15); + d = d > 15 ? 0 : 15 - d; items.put(i, d); } } @@ -478,7 +504,7 @@ public class GuiCalculator extends GuiTooltipScreen{ @Override public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) { Slot slot = getSlotUnderMouse(i, i1); - if(slot != null && slot.getSlotIndex() == 0){ + if (slot != null && slot.getSlotIndex() == 0) { ItemStack buffer = itemStack.copy(); buffer.stackSize = 1; ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true); @@ -487,9 +513,10 @@ public class GuiCalculator extends GuiTooltipScreen{ mode = EnumMode.INPUT; refreshRecipe(); updateLayout(); - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); + JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), + textFieldAmount.getText()); } - itemStack.stackSize=0; + itemStack.stackSize = 0; return false; } } \ No newline at end of file diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/InventoryCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/calculator/InventoryCalculator.java index 6d499d4..46d734e 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/InventoryCalculator.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/calculator/InventoryCalculator.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; /** * @author Towdium */ -public class InventoryCalculator extends InventoryBasic{ +public class InventoryCalculator extends InventoryBasic { public InventoryCalculator(ItemStack itemStack) { super("Calculator", false, 37); diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java index 8a2d96e..fc0fbfb 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java @@ -1,27 +1,27 @@ package me.towdium.jecalculation.gui.guis.recipeEditor; import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.core.Recipe; +import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; +import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe; import me.towdium.jecalculation.network.packets.PacketRecipeUpdate; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.inventory.Slot; import net.minecraft.util.StatCollector; -import me.towdium.jecalculation.core.Recipe; -import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; -import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe; /** * @author Towdium */ -public class GuiRecipeEditor extends GuiRecipe{ +public class GuiRecipeEditor extends GuiRecipe { int index = -1; - public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index){ + public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index) { super(containerRecipeEditor, parent); this.index = index; } - public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent){ + public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent) { super(containerRecipeEditor, parent); } @@ -33,34 +33,36 @@ public class GuiRecipeEditor extends GuiRecipe{ @Override public void initGui() { super.initGui(); - buttonList.add(new GuiButton(16, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.save"))); - buttonList.add(new GuiButton(17, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.clear"))); - if(index != -1){ + buttonList.add(new GuiButton(16, guiLeft + 125, guiTop + 7, 44, 20, + StatCollector.translateToLocal("gui.recipeEditor.save"))); + buttonList.add(new GuiButton(17, guiLeft + 125, guiTop + 31, 44, 20, + StatCollector.translateToLocal("gui.recipeEditor.clear"))); + if (index != -1) { displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(index, null)); } } @Override - protected void actionPerformed(GuiButton button){ + protected void actionPerformed(GuiButton button) { super.actionPerformed(button); int buttonId = button.id; - if(buttonId == 16) { - Recipe recipe = ((ContainerRecipe)inventorySlots).buildRecipe(); - if(recipe == null){ + if (buttonId == 16) { + Recipe recipe = ((ContainerRecipe) inventorySlots).buildRecipe(); + if (recipe == null) { mc.displayGuiScreen(parent); return; } - if(index == -1){ + if (index == -1) { JustEnoughCalculation.proxy.getPlayerHandler().addRecipe(recipe, null); JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, -1)); mc.displayGuiScreen(parent); - }else { + } else { JustEnoughCalculation.proxy.getPlayerHandler().setRecipe(recipe, index, null); JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, index)); mc.displayGuiScreen(parent); } - }else if(buttonId == 17) { - for(Object slot : inventorySlots.inventorySlots){ + } else if (buttonId == 17) { + for (Object slot : inventorySlots.inventorySlots) { ((Slot) slot).inventory.setInventorySlotContents(((Slot) slot).getSlotIndex(), null); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java index fc44975..e231a31 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java @@ -1,27 +1,27 @@ package me.towdium.jecalculation.gui.guis.recipePicker; import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; +import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe; import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor; import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor; import me.towdium.jecalculation.network.packets.PacketRecipeUpdate; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.StatCollector; -import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; -import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe; import java.util.List; /** * @author Towdium */ -public class GuiRecipePicker extends GuiRecipe{ +public class GuiRecipePicker extends GuiRecipe { protected List recipes; protected int index; protected GuiButton buttonLeft; protected GuiButton buttonRight; - public GuiRecipePicker(ContainerRecipe containerRecipe, GuiScreen parent, List recipes){ + public GuiRecipePicker(ContainerRecipe containerRecipe, GuiScreen parent, List recipes) { super(containerRecipe, parent); this.recipes = recipes; } @@ -29,34 +29,36 @@ public class GuiRecipePicker extends GuiRecipe{ @Override public void initGui() { super.initGui(); - buttonLeft = new GuiButton(16, guiLeft+125, guiTop+7, 20, 20, "<"); - buttonRight = new GuiButton(17, guiLeft+149, guiTop+7, 20, 20, ">"); + buttonLeft = new GuiButton(16, guiLeft + 125, guiTop + 7, 20, 20, "<"); + buttonRight = new GuiButton(17, guiLeft + 149, guiTop + 7, 20, 20, ">"); buttonList.add(buttonLeft); buttonList.add(buttonRight); - buttonList.add(new GuiButton(18, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipePicker.delete"))); + buttonList.add(new GuiButton(18, guiLeft + 125, guiTop + 31, 44, 20, + StatCollector.translateToLocal("gui.recipePicker.delete"))); updateLayout(); } @Override - protected void actionPerformed(GuiButton button){ + protected void actionPerformed(GuiButton button) { super.actionPerformed(button); int buttonId = button.id; - if(buttonId>=0 && buttonId<=15){ + if (buttonId >= 0 && buttonId <= 15) { GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index)); mc.displayGuiScreen(recipeEditor); - recipeEditor.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null)); + recipeEditor + .displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null)); recipeEditor.click(buttonId); - }else if(buttonId == 16) { - if(index>0){ + } else if (buttonId == 16) { + if (index > 0) { index--; updateLayout(); } - }else if(buttonId == 17) { - if(index"); + buttonLeft = new GuiButton(0, guiLeft + 7, guiTop + 139, 20, 20, "<"); + buttonRight = new GuiButton(1, guiLeft + 149, guiTop + 139, 20, 20, ">"); buttonList.add(buttonLeft); buttonList.add(buttonRight); - for(int i=0; i<6; i++){ - buttonList.add(new GuiButtonExt(2+2*i, guiLeft+83, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.edit"))); - buttonList.add(new GuiButtonExt(3+2*i, guiLeft+128, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.delete"))); + for (int i = 0; i < 6; i++) { + buttonList.add(new GuiButtonExt(2 + 2 * i, guiLeft + 83, guiTop + 7 + 22 * i, 41, 18, + StatCollector.translateToLocal("gui.recipeViewer.edit"))); + buttonList.add(new GuiButtonExt(3 + 2 * i, guiLeft + 128, guiTop + 7 + 22 * i, 41, 18, + StatCollector.translateToLocal("gui.recipeViewer.delete"))); } updateLayout(); } @@ -49,7 +51,8 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { //GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipeViewer.png")); + mc.getTextureManager() + .bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipeViewer.png")); drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); } @@ -61,13 +64,13 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { @Override public void updateLayout() { recipes = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null); - total = recipes == null ? 0 : (recipes.size()+5)/6; - if(page>total && page != 1){ + total = recipes == null ? 0 : (recipes.size() + 5) / 6; + if (page > total && page != 1) { page = total; } displayRecipes(); - for(int i=0; i<6; i++){ - boolean flag = recipes.size() > (page-1)*6+i; + for (int i = 0; i < 6; i++) { + boolean flag = recipes.size() > (page - 1) * 6 + i; ((GuiButton) buttonList.get(2 + 2 * i)).enabled = flag; ((GuiButton) buttonList.get(3 + 2 * i)).enabled = flag; } @@ -76,9 +79,9 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { } @Override - protected void actionPerformed(GuiButton button){ + protected void actionPerformed(GuiButton button) { int i = button.id; - switch (i){ + switch (i) { case 0: page--; updateLayout(); @@ -88,11 +91,14 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { updateLayout(); break; default: - if(i%2 == 0){ - mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this, recipes.get((page-1)*6+i/2-1))); - }else{ - JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get((page-1)*6+i/2-1), null); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get((page-1)*6+i/2-1))); + if (i % 2 == 0) { + mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this, + recipes.get((page - 1) * 6 + i / 2 - 1))); + } else { + JustEnoughCalculation.proxy.getPlayerHandler() + .removeRecipe(recipes.get((page - 1) * 6 + i / 2 - 1), null); + JustEnoughCalculation.networkWrapper + .sendToServer(new PacketRecipeUpdate(null, recipes.get((page - 1) * 6 + i / 2 - 1))); updateLayout(); } } @@ -100,39 +106,41 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { /** * display the recipe at the position + * * @param position range 1-6 */ - public void displayRecipe(@Nullable Recipe recipe, int position){ - if(recipe != null){ + public void displayRecipe(@Nullable Recipe recipe, int position) { + if (recipe != null) { List items = recipe.getOutput(); - for(int i=0; i<4; i++){ - if(i recipes = new ArrayList(); + public List recipes = new ArrayList<>(); @Override public void addRecipe(Recipe recipe, UUID uuid) { - for (Recipe oneRecipe : recipes){ - if(oneRecipe.equals(recipe)){ + for (Recipe oneRecipe : recipes) { + if (oneRecipe.equals(recipe)) { return; } } - if(recipe != null){ + if (recipe != null) { recipes.add(recipe); } } @Override public boolean getHasRecipe(UUID uuid) { - return recipes.size()!=0; + return recipes.size() != 0; } @Override public ImmutableList getAllRecipeIndex(UUID uuid) { int a = recipes.size(); - ImmutableList.Builder builder = new ImmutableList.Builder(); - for (int i = 0; i builder = new ImmutableList.Builder<>(); + for (int i = 0; i < a; i++) { builder.add(i); } return builder.build(); @@ -53,11 +53,11 @@ public class PlayerHandlerClient implements IPlayerHandler { @Override public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) { - if(itemStack == null){ + if (itemStack == null) { return false; } - for (Recipe recipe : recipes){ - if(recipe.getHasOutput(itemStack)){ + for (Recipe recipe : recipes) { + if (recipe.getHasOutput(itemStack)) { return true; } } @@ -67,17 +67,17 @@ public class PlayerHandlerClient implements IPlayerHandler { @Override public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) { int i = getRecipeIndexOf(itemStack, null); - if(i == -1){ + if (i == -1) { return null; - }else { + } else { return recipes.get(i); } } @Override public ImmutableList getAllRecipeOf(ItemStack itemStack, UUID uuid) { - ImmutableList.Builder recipeBuilder = new ImmutableList.Builder(); - for(Integer index : getAllRecipeIndexOf(itemStack, null)){ + ImmutableList.Builder recipeBuilder = new ImmutableList.Builder<>(); + for (Integer index : getAllRecipeIndexOf(itemStack, null)) { recipeBuilder.add(recipes.get(index)); } return recipeBuilder.build(); @@ -86,7 +86,7 @@ public class PlayerHandlerClient implements IPlayerHandler { @Override public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) { int[] result = new int[]{-1, -1, -1, -1}; - for(int[] record : getAllUnsortedRecipeIndexOf(itemStack)){ + for (int[] record : getAllUnsortedRecipeIndexOf(itemStack)) { result[record[1]] = record[0]; } for (int index : result) { @@ -100,15 +100,15 @@ public class PlayerHandlerClient implements IPlayerHandler { @Override public ImmutableList getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) { ImmutableList.Builder> builder1 = new ImmutableList.Builder<>(); - for(int i=0; i<4; i++){ - builder1.add(new ImmutableList.Builder()); + for (int i = 0; i < 4; i++) { + builder1.add(new ImmutableList.Builder<>()); } ImmutableList> resultBuffer = builder1.build(); - for(int[] result : getAllUnsortedRecipeIndexOf(itemStack)){ + for (int[] result : getAllUnsortedRecipeIndexOf(itemStack)) { resultBuffer.get(result[1]).add(result[0]); } ImmutableList.Builder builder2 = new ImmutableList.Builder<>(); - for(ImmutableList.Builder priority : resultBuffer){ + for (ImmutableList.Builder priority : resultBuffer) { builder2.addAll(priority.build().reverse()); } return builder2.build(); @@ -126,13 +126,13 @@ public class PlayerHandlerClient implements IPlayerHandler { @Override public Recipe getRecipe(int index, UUID uuid) { - return index getAllUnsortedRecipeIndexOf(ItemStack itemStack){ + ImmutableList getAllUnsortedRecipeIndexOf(ItemStack itemStack) { ImmutableList.Builder builder = new ImmutableList.Builder<>(); int size = recipes.size(); int buffer; - for(int i = 0; i recipes = new ArrayList<>(amount); - for(int i=0; i players = new HashMap<>(); + private HashMap players = new HashMap<>(); @Override public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) { @@ -102,7 +102,7 @@ public class PlayerHandlerServer implements IPlayerHandler { return false; } - public PlayerHandlerClient getClient(UUID uuid){ + public PlayerHandlerClient getClient(UUID uuid) { return players.get(uuid); } } diff --git a/src/main/java/me/towdium/jecalculation/network/ProxyServer.java b/src/main/java/me/towdium/jecalculation/network/ProxyServer.java index 8699cb8..cc947b2 100644 --- a/src/main/java/me/towdium/jecalculation/network/ProxyServer.java +++ b/src/main/java/me/towdium/jecalculation/network/ProxyServer.java @@ -1,7 +1,7 @@ package me.towdium.jecalculation.network; -import net.minecraftforge.common.MinecraftForge; import me.towdium.jecalculation.event.PlayerEventHandler; +import net.minecraftforge.common.MinecraftForge; /** * @author Towdium diff --git a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java b/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java index a73276b..b2bdd9c 100644 --- a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java +++ b/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java @@ -5,9 +5,8 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; -import net.minecraft.item.ItemStack; - import me.towdium.jecalculation.item.ItemCalculator; +import net.minecraft.item.ItemStack; /** * @author Towdium @@ -15,7 +14,8 @@ import me.towdium.jecalculation.item.ItemCalculator; public class PacketCalculatorUpdate implements IMessage, IMessageHandler { ItemStack itemStack; - public PacketCalculatorUpdate(){} + public PacketCalculatorUpdate() { + } public PacketCalculatorUpdate(ItemStack itemStack) { this.itemStack = itemStack; @@ -33,9 +33,10 @@ public class PacketCalculatorUpdate implements IMessage, IMessageHandler { PlayerHandlerClient client; - public PacketSyncRecord(){} + public PacketSyncRecord() { + } - public PacketSyncRecord(PlayerHandlerClient client){ + public PacketSyncRecord(PlayerHandlerClient client) { this.client = client; } @Override public void toBytes(ByteBuf buf) { - if (client == null){ + if (client == null) { buf.writeShort(-1); return; } @@ -41,7 +42,7 @@ public class PacketSyncRecord implements IMessage, IMessageHandler itemStacks = new ArrayList<>(); LOOP: - for(PositionedStack item : iRecipeHandler.getIngredientStacks(i)){ - for(ItemStack current : itemStacks){ - if(ItemStackWrapper.isTypeEqual(current, item.items[0])){ + for (PositionedStack item : iRecipeHandler.getIngredientStacks(i)) { + for (ItemStack current : itemStacks) { + if (ItemStackWrapper.isTypeEqual(current, item.items[0])) { current.stackSize++; continue LOOP; } } itemStacks.add(item.items[0].copy()); } - int index=4; - for(ItemStack itemStack : itemStacks){ + int index = 4; + for (ItemStack itemStack : itemStacks) { ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true); guiContainer.inventorySlots.getSlot(index++).putStack(itemStack); } diff --git a/src/main/java/me/towdium/jecalculation/plugin/NEICalculatorConfig.java b/src/main/java/me/towdium/jecalculation/plugin/NEICalculatorConfig.java index 4992f9e..68c71f2 100644 --- a/src/main/java/me/towdium/jecalculation/plugin/NEICalculatorConfig.java +++ b/src/main/java/me/towdium/jecalculation/plugin/NEICalculatorConfig.java @@ -10,9 +10,10 @@ public class NEICalculatorConfig implements IConfigureNEI { @Override public void loadConfig() { LOOP: - for(String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()){ - for(String b : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty().getStringList()){ - if(s.equals(b)){ + for (String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()) { + for (String b : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty() + .getStringList()) { + if (s.equals(b)) { continue LOOP; } }