diff --git a/src/main/java/me/towdium/jecalculation/JecaConfig.java b/src/main/java/me/towdium/jecalculation/JecaConfig.java index 6fb1e2e..4798200 100644 --- a/src/main/java/me/towdium/jecalculation/JecaConfig.java +++ b/src/main/java/me/towdium/jecalculation/JecaConfig.java @@ -66,7 +66,7 @@ public class JecaConfig { case ListRecipeBlackList: return new String[0]; case ListRecipeCategory: - return new String[]{"crafting", "smelting"}; + return new String[]{"minecraft.crafting", "minecraft.smelting"}; } return JecaConfig.empty; } @@ -104,7 +104,9 @@ public class JecaConfig { } } - public enum EnumType {Boolean, ListString, Error} + public enum EnumType { + Boolean, ListString, Error + } public static Object empty; diff --git a/src/main/java/me/towdium/jecalculation/JecaItem.java b/src/main/java/me/towdium/jecalculation/JecaItem.java index 1d10f99..724ab4d 100644 --- a/src/main/java/me/towdium/jecalculation/JecaItem.java +++ b/src/main/java/me/towdium/jecalculation/JecaItem.java @@ -14,7 +14,7 @@ import net.minecraft.world.World; public class JecaItem extends Item { public static JecaItem INSTANCE = new JecaItem(); - public static final String NAME = "item_calculator"; + public static final String NAME = "itemCalculator"; public JecaItem() { setHasSubtypes(true); @@ -26,9 +26,7 @@ public class JecaItem extends Item { @Override public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { - playerIn.openGui(JustEnoughCalculation.instance, GuiHandler.GuiId.CALCULATOR, worldIn, 0, 0, 0); - ItemStack stack = playerIn.inventory.getStackInSlot(0); - //JustEnoughCalculation.log.info(stack==null ? "" : stack.getItem().getUnlocalizedName() + "-" + stack.getItemDamage()); + playerIn.openGui(JustEnoughCalculation.INSTANCE, GuiHandler.GuiId.EDITOR, worldIn, 0, 0, 0); return itemStackIn; } } \ No newline at end of file diff --git a/src/main/java/me/towdium/jecalculation/JecaTranslator.java b/src/main/java/me/towdium/jecalculation/JecaTranslator.java new file mode 100644 index 0000000..46dfd54 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/JecaTranslator.java @@ -0,0 +1,15 @@ +package me.towdium.jecalculation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.resources.I18n; +import org.apache.commons.lang3.StringEscapeUtils; + +@SideOnly(Side.CLIENT) +public class JecaTranslator { + public static String format(String translateKey, Object... parameters){ + String buffer = I18n.format(translateKey, parameters); + buffer = StringEscapeUtils.unescapeJava(buffer); + return buffer.replace("\t", " "); + } +} diff --git a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java index 902a9fa..64da8b7 100644 --- a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java +++ b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java @@ -3,38 +3,29 @@ package me.towdium.jecalculation; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.network.NetworkCheckHandler; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; +import me.towdium.jecalculation.gui.GuiHandler; +import me.towdium.jecalculation.nei.NEIPlugin; import me.towdium.jecalculation.network.IProxy; -import me.towdium.jecalculation.network.packets.PacketCalculatorUpdate; -import me.towdium.jecalculation.network.packets.PacketRecipeUpdate; -import me.towdium.jecalculation.network.packets.PacketSyncRecord; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.ShapedOreRecipe; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Map; - /** * @author Towdium */ +@SuppressWarnings("unused") @Mod(modid = JustEnoughCalculation.Reference.MODID, name = JustEnoughCalculation.Reference.MODNAME, version = JustEnoughCalculation.Reference.VERSION, dependencies = "required-after:NotEnoughItems") public class JustEnoughCalculation { @Mod.Instance(Reference.MODID) - public static JustEnoughCalculation instance; + public static JustEnoughCalculation INSTANCE; @SidedProxy(modId = Reference.MODID, clientSide = "me.towdium.jecalculation.network.ProxyClient", @@ -44,53 +35,25 @@ public class JustEnoughCalculation { public static SimpleNetworkWrapper network; public static Logger logger = LogManager.getLogger(Reference.MODID); - @NetworkCheckHandler - public static boolean networkCheck(Map mods, Side s) { - return s == Side.SERVER || mods.containsKey(Reference.MODID); - } - @Mod.EventHandler public static void initPre(FMLPreInitializationEvent event) { JecaConfig.preInit(event); GameRegistry.registerItem(JecaItem.INSTANCE, JecaItem.NAME); network = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID); - network.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1, Side.SERVER); - network.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2, Side.SERVER); - network.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT); - network.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER); } @Mod.EventHandler - public static void iniFt(FMLInitializationEvent event) { - /*if(event.getSide().isClient()){ - Minecraft.getMinecraft().getRenderItem().getItemModelMesher(). - register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory")); - }*/ - ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(JecaItem.INSTANCE), "SIS", "SRS", "SOS", 'S', - "stone", 'I', "dyeBlack", 'R', "dustRedstone", 'O', "ingotIron") { - { - try { - Field f = ShapedOreRecipe.class.getDeclaredField("input"); - f.setAccessible(true); - Object[] o = (Object[]) f.get(this); - if (o[1] instanceof ArrayList) { - ArrayList buffer = (ArrayList) o[1]; - ArrayList a = new ArrayList(buffer); - Item i = GameRegistry.findItem("Botania", "dye"); - if (i != null) - a.add(new ItemStack(i, 1, 15)); - o[1] = a; - } - } catch (Exception ignored) { - } - } - }; - GameRegistry.addRecipe(recipe); + public static void init(FMLInitializationEvent event) { + NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler()); proxy.init(); - - //DefaultOverlayHandler } + @Mod.EventHandler + public static void postInit(FMLPostInitializationEvent event) { + NEIPlugin.init(); + } + + public static class Reference { public static final String MODID = "jecalculation"; public static final String MODNAME = "Just Enough Calculation"; diff --git a/src/main/java/me/towdium/jecalculation/core/Calculator.java b/src/main/java/me/towdium/jecalculation/core/Calculator.java deleted file mode 100644 index 04c0d32..0000000 --- a/src/main/java/me/towdium/jecalculation/core/Calculator.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.towdium.jecalculation.core; - -import me.towdium.jecalculation.JustEnoughCalculation; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.List; - - -/** - * @author Towdium - * This is calculating core v3.0, I call it global coordinating calculation XD. - * The procudure might be more complex, but can avoid some unexpected results. - */ - -public class Calculator { - List costRecords; - - 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) { - if (count > 100) { - return; - } - // all the items possible tp cancel - for (ItemRecord itemRecord : cancellableItems) { - // all the recipes for one item - LOOP1: - 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)) { - continue LOOP1; - } - costRecords.add(record); - count++; - cancellableItems = record.getCancellableItems(); - continue LOOP2; - } - } - } - break; - } - } - - public CostRecord getCost() { - return costRecords.get(costRecords.size() - 1); - } - - protected long getCount(ItemRecord itemRecord, Recipe recipe) { - long a = recipe.getOutputAmount(itemRecord.toItemStack()); - 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 deleted file mode 100644 index f36bf72..0000000 --- a/src/main/java/me/towdium/jecalculation/core/CostRecord.java +++ /dev/null @@ -1,255 +0,0 @@ -package me.towdium.jecalculation.core; - -import com.google.common.collect.ImmutableList; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * @author Towdium - */ -public class CostRecord { - private List output; - private List input; - private List catalyst; - private List procedure; - - public CostRecord(ItemRecord itemRecord) { - output = new ArrayList<>(); - input = new ArrayList<>(); - catalyst = new LinkedList<>(); - procedure = new ArrayList<>(); - input.add(itemRecord); - } - - 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) { - ItemRecord record = new ItemRecord(itemStack, count); - record.approx = b; - output.add(record); - } - } - for (ItemStack itemStack : recipe.input) { - if (itemStack != null) { - ItemRecord record = new ItemRecord(itemStack, count); - record.approx = b; - input.add(record); - record = new ItemRecord(itemStack); - record.approx = b; - catalyst.add(record); - } - } - procedure.add(dest); - } - - /** - * Generate CostRecord merging two CostRecords - * ItemRecord with amount 0 may be left there - */ - public CostRecord(CostRecord costRecord1, CostRecord costRecord2) { - output = new ArrayList<>(); - for (ItemRecord record : costRecord1.output) { - output.add(record.copy()); - } - input = new ArrayList<>(); - for (ItemRecord record : costRecord1.input) { - input.add(record.copy()); - } - catalyst = new LinkedList<>(); - for (ItemRecord record : costRecord1.catalyst) { - catalyst.add(record.copy()); - } - procedure = new ArrayList<>(); - for (ItemRecord record : costRecord1.procedure) { - procedure.add(record.copy()); - } - 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)) { - itemRecordExt.add(itemRecordAdd); - continue LOOP; - } - } - output.add(itemRecordAdd.copy()); - } - // merge input - LOOP: - for (ItemRecord itemRecordAdd : costRecord2.input) { - for (ItemRecord itemRecordExt : input) { - if (itemRecordAdd.isSameType(itemRecordExt)) { - itemRecordExt.add(itemRecordAdd); - continue LOOP; - } - } - input.add(itemRecordAdd.copy()); - } - // cancel catalyst by output - LOOP: - 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)) { - itemRecordExt.minus(itemRecordAdd); - continue LOOP; - } - } - } - // merge catalyst - LOOP: - for (ItemRecord itemRecordAdd : costRecord2.catalyst) { - for (ItemRecord itemRecordExt : catalyst) { - if (itemRecordAdd.isSameType(itemRecordExt)) { - itemRecordExt.add(itemRecordAdd); - continue LOOP; - } - } - catalyst.add(itemRecordAdd.copy()); - } - // cancel input and output - for (ItemRecord itemRecordIn : input) { - for (ItemRecord itemRecordOut : output) { - if (itemRecordIn.isSameType(itemRecordOut)) { - itemRecordIn.cancel(itemRecordOut); - } - } - } - } - - ImmutableList getCancellableItems() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (ItemRecord itemRecord : input) { - if (!itemRecord.isLocked() && itemRecord.amount != 0) { - builder.add(itemRecord); - } - } - return builder.build(); - } - - public ImmutableList getOutputStack() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (ItemRecord itemRecord : output) { - if (itemRecord.amount != 0) { - builder.add(itemRecord.toItemStack()); - } - } - return builder.build(); - } - - public ImmutableList getProcedureStack() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (int i = procedure.size() - 1; i >= 0; i--) { - ItemRecord itemRecord = procedure.get(i); - if (itemRecord.amount != 0) { - builder.add(itemRecord.toItemStack()); - } - } - return builder.build(); - } - - public ImmutableList getInputStack() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (ItemRecord itemRecord : input) { - if (itemRecord.amount != 0) { - builder.add(itemRecord.toItemStack()); - } - } - return builder.build(); - } - - 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) { - continue LOOP; - } - } - ItemRecord buffer = itemRecord.copy(); - //buffer.amount=0; - ItemStack itemStack = buffer.toItemStack(); - //itemStack.getTagCompound().setBoolean("mark", true); - builder.add(itemStack); - } - } - return builder.build(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CostRecord) { - LOOP: - for (ItemRecord itemRecordIn : output) { - for (ItemRecord itemRecordExt : ((CostRecord) obj).output) { - if (itemRecordExt.isSameType(itemRecordIn)) { - if (itemRecordExt.amount != itemRecordIn.amount) { - return false; - } else { - continue LOOP; - } - } - } - return false; - } - LOOP: - for (ItemRecord itemRecordIn : input) { - for (ItemRecord itemRecordExt : ((CostRecord) obj).input) { - if (itemRecordExt.isSameType(itemRecordIn)) { - if (itemRecordExt.amount != itemRecordIn.amount) { - return false; - } else { - continue LOOP; - } - } - } - return false; - } - LOOP: - for (ItemRecord itemRecordIn : ((CostRecord) obj).output) { - for (ItemRecord itemRecordExt : output) { - if (itemRecordExt.isSameType(itemRecordIn)) { - if (itemRecordExt.amount != itemRecordIn.amount) { - return false; - } else { - continue LOOP; - } - } - } - return false; - } - LOOP: - for (ItemRecord itemRecordIn : ((CostRecord) obj).input) { - for (ItemRecord itemRecordExt : input) { - if (itemRecordExt.isSameType(itemRecordIn)) { - if (itemRecordExt.amount != itemRecordIn.amount) { - return false; - } else { - continue LOOP; - } - } - } - return false; - } - return true; - } else { - return false; - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/core/ItemRecord.java b/src/main/java/me/towdium/jecalculation/core/ItemRecord.java deleted file mode 100644 index f4f4791..0000000 --- a/src/main/java/me/towdium/jecalculation/core/ItemRecord.java +++ /dev/null @@ -1,132 +0,0 @@ -package me.towdium.jecalculation.core; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -/** - * @author Towdium - */ -public class ItemRecord { - Item item; - int meta; - long amount; - boolean approx; - boolean locked; - - /** - * Generate ItemRecord based on the ItemStack and multiply the amount - */ - 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) { - this(itemStack, 1); - } - - /** - * Generate ItemRecord with customized amount - */ - public ItemRecord(ItemStack itemStack, long amount, boolean approx) { - item = itemStack.getItem(); - meta = itemStack.getItemDamage(); - this.amount = amount; - this.approx = approx; - } - - public ItemRecord(Item item, int meta, long amount, boolean approx) { - this.item = item; - this.meta = meta; - this.amount = amount; - this.approx = approx; - } - - @Override - public String toString() { - 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) { - return ItemStackWrapper.getUnifiedAmount(recipe.output[i]); - } - } - return 0; - } - - public boolean isSameType(ItemRecord record) { - return item == record.item && meta == record.meta; - } - - public boolean add(ItemRecord record) { - if (isSameType(record)) { - amount += record.amount; - approx = approx || record.approx; - return true; - } else { - return false; - } - } - - public boolean minus(ItemRecord record) { - if (isSameType(record)) { - amount -= record.amount; - return true; - } else { - return false; - } - } - - 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) { - approx = true; - record.approx = true; - } - return i != 0; - } else { - return false; - } - } - - public ItemRecord copy() { - return new ItemRecord(item, meta, amount, approx); - } - - public ItemStack toItemStack() { - ItemStack itemStack = new ItemStack(item, 1, meta); - NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setLong("amount", amount); - if (approx) { - tagCompound.setBoolean("approx", true); - } - itemStack.setTagCompound(tagCompound); - return itemStack; - } - - public boolean isLocked() { - return locked; - } - - public void setLocked(boolean locked) { - this.locked = locked; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ItemRecord) { - ItemRecord record = ((ItemRecord) obj); - return record.approx == approx && record.item == item && record.amount == amount && record.meta == meta; - } else { - return false; - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/core/ItemStackHelper.java b/src/main/java/me/towdium/jecalculation/core/ItemStackHelper.java new file mode 100644 index 0000000..1c8dd32 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/core/ItemStackHelper.java @@ -0,0 +1,13 @@ +package me.towdium.jecalculation.core; + +import net.minecraft.item.ItemStack; + +public class ItemStackHelper { + public static boolean isTypeEqual(ItemStack one, ItemStack two) { + return one != null && two != null && one.getItem() == two.getItem() && getMetadata(one) == getMetadata(two); + } + + private static int getMetadata(ItemStack stack) { + return stack.getItemDamage(); + } +} diff --git a/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java b/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java deleted file mode 100644 index a2c2628..0000000 --- a/src/main/java/me/towdium/jecalculation/core/ItemStackWrapper.java +++ /dev/null @@ -1,326 +0,0 @@ -package me.towdium.jecalculation.core; - -import me.towdium.jecalculation.JustEnoughCalculation; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -/** - * @author Towdium - */ -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 isStackEqual(ItemStack one, ItemStack two) { - return ItemStack.areItemStacksEqual(one, two); - } - - public static int getUnifiedAmount(ItemStack itemStack) { - if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { - return itemStack.getTagCompound().getInteger("percentage"); - } else { - return itemStack.stackSize * 100; - } - } - - 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) { - return ""; - } - int i = itemStack.getTagCompound().getInteger("percentage"); - if (i != 0) { - return i + "%"; - } else { - if (l == -1) { - return String.valueOf(itemStack.stackSize); - } - return getSimplifiedString((l + 99) / 100, itemStack.getTagCompound().getBoolean("approx")); - } - } else { - return String.valueOf(itemStack.stackSize); - } - } else - return ""; - } - - public static ItemStack toPercentage(ItemStack itemStack) { - if (itemStack == null) { - return null; - } - NBT.setInt(itemStack, "percentage", itemStack.stackSize * 100); - itemStack.stackSize = 1; - return itemStack; - } - - public static ItemStack toNormal(ItemStack itemStack) { - if (itemStack == null) { - return null; - } - if (itemStack.hasTagCompound()) { - int i = itemStack.getTagCompound().getInteger("percentage"); - itemStack.stackSize = (i + 99) / 100; - itemStack.setTagCompound(null); - } else { - itemStack.stackSize = 1; - } - itemStack.setTagCompound(null); - ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true); - return itemStack; - } - - public static String getSimplifiedString(long l, boolean approx) { - String s; - 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 < 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); - } - } - return s; - } - - public static long getGhostItemAmount(ItemStack itemStack) { - if (itemStack.hasTagCompound()) { - long l = itemStack.getTagCompound().getLong("amount"); - return (l + 99) / 100; - } else { - return 0; - } - - } - - public static class NBT { - public static void initNBT(ItemStack itemStack) { - if (!itemStack.hasTagCompound()) { - itemStack.setTagCompound(new NBTTagCompound()); - } - } - - public static void setItem(ItemStack dest, String key, ItemStack content) { - initNBT(dest); - NBTTagCompound buffer = new NBTTagCompound(); - if (content != null) { - content.writeToNBT(buffer); - dest.getTagCompound().setTag(key, buffer); - } else { - dest.getTagCompound().removeTag(key); - } - - } - - public static ItemStack getItem(ItemStack itemStack, String key) { - NBTTagCompound tagCompound = itemStack.getTagCompound(); - if (tagCompound == null) { - return null; - } - NBTTagCompound itemTagCompound = tagCompound.getCompoundTag(key); - if (itemTagCompound == null) { - return null; - } - return ItemStack.loadItemStackFromNBT(itemTagCompound); - } - - 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) { - initNBT(dest); - dest.getTagCompound().setInteger(key, 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) { - initNBT(dest); - dest.getTagCompound().setLong(key, value); - } - - public static String getString(ItemStack dest, String key) { - if (dest.getTagCompound() != null) { - return dest.getTagCompound().getString(key); - } 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) { - return dest.getTagCompound().getInteger(key); - } else - return 0; - } - - public static long getLong(ItemStack dest, String key) { - if (dest.getTagCompound() != null) { - return dest.getTagCompound().getLong(key); - } else - return 0; - } - } - - public static class Click { - 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 { - itemStack.stackSize += 1; - } - } - return true; - } - } - - 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")) { - int i = itemStack.getTagCompound().getInteger("percentage"); - itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i + 10); - } else { - if (itemStack.stackSize == 1) { - itemStack.stackSize = 10; - } else if (itemStack.stackSize <= 54) { - itemStack.stackSize += 10; - } else { - itemStack.stackSize = 64; - } - } - } - return true; - } - } - - public static boolean rightClick(ItemStack itemStack, boolean doChange) { - if (itemStack == null) { - return false; - } else { - if (doChange) { - if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { - int i = itemStack.getTagCompound().getInteger("percentage"); - if (i == 1 || i == 0) { - itemStack.stackSize = 0; - return true; - } - itemStack.getTagCompound().setInteger("percentage", --i); - } else { - itemStack.stackSize -= 1; - } - } - return true; - } - } - - public static boolean rightShift(ItemStack itemStack, boolean doChange) { - if (itemStack == null) { - return false; - } else { - if (doChange) { - if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) { - int i = itemStack.getTagCompound().getInteger("percentage"); - 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.stackSize = 0; - } else if (itemStack.stackSize <= 10) { - itemStack.stackSize = 1; - } else { - itemStack.stackSize -= 10; - } - } - } - return true; - } - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/core/Recipe.java b/src/main/java/me/towdium/jecalculation/core/Recipe.java deleted file mode 100644 index 0d89e44..0000000 --- a/src/main/java/me/towdium/jecalculation/core/Recipe.java +++ /dev/null @@ -1,285 +0,0 @@ -package me.towdium.jecalculation.core; - -import com.google.common.collect.ImmutableList; -import cpw.mods.fml.common.network.ByteBufUtils; -import io.netty.buffer.ByteBuf; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -/** - * @author Towdium - */ -public class Recipe { - ItemStack[] output; - ItemStack[] input; - - public Recipe(ItemStack[] output, ItemStack[] input) { - 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) { - boolean flag = false; - for (int j = 0; j < i; j++) { - if (this.output[j] != null && ItemStackWrapper.isTypeEqual(this.output[j], itemstack)) { - this.output[j].stackSize += itemstack.stackSize; - flag = true; - break; - } - } - if (!flag) { - this.output[i] = itemstack.copy(); - } - } - } - 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)) { - this.input[i].stackSize += itemstack.stackSize; - break; - } else if (this.input[i] == null) { - this.input[i] = itemstack.copy(); - break; - } - } - } - } - } - - 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]) < ItemStackWrapper.getUnifiedAmount(buffer)) { - return -1; - } - } - return i; - } - } - return -1; - } - - public int getExactInputIndex(ItemStack itemStack) { - for (int i = 0; i < 12; i++) { - if (ItemStackWrapper.isStackEqual(input[i], itemStack)) { - return i; - } - } - return -1; - } - - public int getInputIndex(ItemStack itemStack) { - for (int i = 0; i < 12; i++) { - if (ItemStackWrapper.isTypeEqual(input[i], itemStack)) { - return i; - } - } - return -1; - } - - public boolean getHasExactInput(ItemStack itemStack) { - return getExactInputIndex(itemStack) != -1; - } - - public int getOutputAmount(ItemStack itemStack) { - for (int i = 0; i < 4; i++) { - if (ItemStackWrapper.isTypeEqual(output[i], itemStack)) { - return ItemStackWrapper.getUnifiedAmount(output[i]); - } - } - return 0; - } - - public int getInputAmount(ItemStack itemStack) { - for (int i = 0; i < 12; i++) { - if (ItemStackWrapper.isTypeEqual(input[i], itemStack)) { - return ItemStackWrapper.getUnifiedAmount(input[i]); - } - } - return 0; - } - - public boolean getHasOutput(ItemStack itemStack) { - return getOutputIndex(itemStack) != -1; - } - - public boolean getHasInput(ItemStack itemStack) { - return getInputIndex(itemStack) != -1; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Recipe) { - for (int i = 0; i < 4; i++) { - if (!ItemStackWrapper.isStackEqual(output[i], ((Recipe) obj).output[i])) { - return false; - } - } - for (int i = 0; i < 12; i++) { - if (!ItemStackWrapper.isStackEqual(input[i], ((Recipe) obj).input[i])) { - return false; - } - } - return true; - } else { - return false; - } - } - - public boolean isOutputEqual(Recipe recipe) { - for (int i = 0; i < 4; i++) { - if (!ItemStackWrapper.isStackEqual(output[i], recipe.output[i])) { - return false; - } - } - return true; - } - - public ImmutableList getOutput() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - for (ItemStack itemStack : output) { - if (itemStack != null) { - builder.add(itemStack.copy()); - } - } - return builder.build(); - } - - public ImmutableList getInput() { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - 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")) { - return true; - } - } - 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) { - short a = buf.readShort(); - if (a == 0) { - return null; - } - short b = buf.readShort(); - ItemStack[] output = new ItemStack[4]; - ItemStack[] input = new ItemStack[12]; - for (int i = 0; i < a; i++) { - output[i] = ByteBufUtils.readItemStack(buf); - } - for (int i = 0; i < b; i++) { - input[i] = ByteBufUtils.readItemStack(buf); - } - return new Recipe(output, input); - } - - public static void toByte(ByteBuf buf, Recipe recipe) { - if (recipe == null) { - buf.writeShort(0); - return; - } - short a = 0; - short b = 0; - for (ItemStack itemStack : recipe.output) { - if (itemStack != null) { - a++; - } - } - for (ItemStack itemStack : recipe.input) { - if (itemStack != null) { - b++; - } - } - buf.writeShort(a); - buf.writeShort(b); - ItemStack[] output1 = recipe.output; - for (ItemStack itemStack : output1) { - if (itemStack != null) { - ByteBufUtils.writeItemStack(buf, itemStack); - } - } - ItemStack[] input1 = recipe.input; - for (ItemStack itemStack : input1) { - if (itemStack != null) { - ByteBufUtils.writeItemStack(buf, itemStack); - } - } - } - } - - public static class NBTUtl { - public static NBTTagCompound toNBT(Recipe recipe) { - NBTTagCompound tagCompound = new NBTTagCompound(); - for (int i = 0; i < 4; i++) { - if (recipe.output[i] != null) { - NBTTagCompound buffer = new NBTTagCompound(); - recipe.output[i].writeToNBT(buffer); - tagCompound.setTag(i + "", buffer); - } - } - for (int i = 0; i < 12; i++) { - if (recipe.input[i] != null) { - NBTTagCompound buffer = new NBTTagCompound(); - recipe.input[i].writeToNBT(buffer); - tagCompound.setTag((i + 4) + "", buffer); - } - } - return tagCompound; - } - - public static Recipe fromNBT(NBTTagCompound tagCompound) { - ItemStack[] output = new ItemStack[4]; - ItemStack[] input = new ItemStack[12]; - boolean inputNull = true; - boolean outputNull = true; - for (int i = 0; i < 4; i++) { - NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i)); - if (buffer != null) { - output[i] = ItemStack.loadItemStackFromNBT(buffer); - if (output[i] != null) { - outputNull = false; - } - } - } - for (int i = 0; i < 12; i++) { - NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i + 4)); - if (buffer != null) { - input[i] = ItemStack.loadItemStackFromNBT(buffer); - if (input[i] != null) { - inputNull = false; - } - } - } - return inputNull || outputNull ? null : new Recipe(output, input); - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/event/GuiEventHandler.java b/src/main/java/me/towdium/jecalculation/event/GuiEventHandler.java deleted file mode 100644 index dada69e..0000000 --- a/src/main/java/me/towdium/jecalculation/event/GuiEventHandler.java +++ /dev/null @@ -1,97 +0,0 @@ -package me.towdium.jecalculation.event; - - -import cpw.mods.fml.common.eventhandler.EventPriority; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.InputEvent; -import me.towdium.jecalculation.gui.guis.calculator.GuiCalculator; -import net.minecraftforge.client.event.GuiOpenEvent; - -import java.util.Date; - -/** - * @author Towdium - */ -public class GuiEventHandler { - long time = new Date().getTime(); - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onMouseClick(InputEvent.MouseInputEvent event) { - /*if(event.gui instanceof GuiRecipeEditor){ - if(new Date().getTime() - time < 200){ - event.setCanceled(true); - return; - } - if (((GuiRecipeEditor) Minecraft.getMinecraft().currentScreen).getActiveSlot() != -1){ - GuiRecipeEditor guiContainer = (GuiRecipeEditor) event.gui; - ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse(); - Slot slot = ((GuiRecipeEditor) event.gui).inventorySlots.getSlot(((GuiRecipeEditor) event.gui).getActiveSlot()); - slot.putStack(itemStack == null ? null : itemStack.copy()); - if(Mouse.isButtonDown(0)){ - time = new Date().getTime(); - if(guiContainer.getSlotUnderMouse() != null){ - guiContainer.setActiveSlot(guiContainer.getSlotUnderMouse().getSlotIndex()); - event.gui.mc.thePlayer.playSound("random.click", 1f, 1f ); - event.setCanceled(true); - return; - } - int y = guiContainer.height - Mouse.getEventY() * guiContainer.height / guiContainer.mc.displayHeight - 1; - int x = Mouse.getEventX() * guiContainer.width / guiContainer.mc.displayWidth; - boolean over = ((ItemListOverlay)JEIPlugin.runtime.getItemListOverlay()).isMouseOver(x, y); - if(!over || (y>25 && y 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 9f375c5..8f4baad 100644 --- a/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java +++ b/src/main/java/me/towdium/jecalculation/gui/GuiHandler.java @@ -1,47 +1,35 @@ package me.towdium.jecalculation.gui; import cpw.mods.fml.common.network.IGuiHandler; -import me.towdium.jecalculation.JustEnoughCalculation; -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.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 me.towdium.jecalculation.gui.guis.GuiCalculator; +import me.towdium.jecalculation.gui.guis.GuiEditor; +import me.towdium.jecalculation.gui.guis.GuiRecipeSearch; +import net.minecraft.client.Minecraft; 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 int CALCULATOR = 0; - public static final int RECIPE_VIEWER = 1; - public static final int RECIPE_EDITOR = 2; - public static final int RECIPE_PICKER = 3; + public static final int RECIPE_SEARCH = 1; + public static final int EDITOR = 2; + } @Override - public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override - public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - switch (ID) { + 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)); + return new GuiCalculator(null); + case GuiId.RECIPE_SEARCH: + return new GuiRecipeSearch(Minecraft.getMinecraft().currentScreen); + case GuiId.EDITOR: + return new GuiEditor(null); } return null; } diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaContainer.java b/src/main/java/me/towdium/jecalculation/gui/JecaContainer.java new file mode 100644 index 0000000..cbac81a --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/JecaContainer.java @@ -0,0 +1,53 @@ +package me.towdium.jecalculation.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryBasic; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public abstract class JecaContainer extends Container { + InventoryBasic inventory; + List slotBuffer = new ArrayList<>(); + + public JecaContainer() { + addSlots(); + int count = 0; + int current = -1; + for(int[] record: slotBuffer) { + count += (record[4] * record[5]); + } + inventory = new InventoryBasic("Temp", false, count); + for(int[] record: slotBuffer) { + for(int a = 0; a < record[4]; a++) { + for(int b=0; b < record[5];b++) { + addSlotToContainer(new Slot(inventory, ++current, record[0]+b*record[2], record[1]+a*record[3])); + } + } + } + } + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + return true; + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { + return null; + } + + protected void addSlotSingle(int left, int top){ + slotBuffer.add(new int[]{left, top, 0, 0, 1, 1}); + } + + protected void addSlotGroup(int left, int top, int intervalH, int intervalV, int sizeH, int sizeV){ + slotBuffer.add(new int[]{left, top, intervalH, intervalV, sizeH, sizeV}); + } + + + protected abstract void addSlots(); +} diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaGuiContainer.java b/src/main/java/me/towdium/jecalculation/gui/JecaGuiContainer.java new file mode 100644 index 0000000..ce4adeb --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/JecaGuiContainer.java @@ -0,0 +1,174 @@ +package me.towdium.jecalculation.gui; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; + +public abstract class JecaGuiContainer extends GuiContainer { + GuiScreen parent; + int activeSlot = -1; + long timeStart = 0; + + public JecaGuiContainer(Container inventorySlotsIn, GuiScreen parent) { + super(inventorySlotsIn); + this.parent = parent; + } + + public boolean setActiveSlot(int id) { + if (id == -1 || getSizeSlotActive(id) != 0) { + activeSlot = id; + return true; + } else { + return false; + } + } + + public int getActiveSlot() { + return activeSlot; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + RenderHelper.disableStandardItemLighting(); // ? + + drawToolTipScreen(mouseX, mouseY); + RenderHelper.enableStandardItemLighting(); // > + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + drawActiveSlot(); + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) { + if (keyCode == 1) { + if (activeSlot != -1) { + setActiveSlot(-1); + } else { + mc.displayGuiScreen(parent); + } + } else { + super.keyTyped(typedChar, keyCode); + } + } + + @Override + protected void mouseClicked(int i1, int i2, int i3) { + if (activeSlot == -1) { + Slot slot = getSlotUnderMouse(); + if (slot != null && setActiveSlot(slot.getSlotIndex())) { + mc.thePlayer.playSound("gui.button.press", 0.2f, 1f); + } + super.mouseClicked(i1, i2, i3); + } else { + activeSlot = -1; + mc.thePlayer.playSound("gui.button.press", 0.2f, 1f); + } + } + + /** + * called by NEI when need display item name or tool tip + * + * @param stack current mouse over item + */ + public void handleMouseOverNEIItemPanel(ItemStack stack) { + if (activeSlot != -1) { + inventorySlots.getSlot(activeSlot).putStack(stack == null ? null : stack.copy()); + } + } + + protected void drawToolTipScreen(int mouseX, int mouseY) { + boolean flagUnicode = mc.fontRenderer.getUnicodeFlag(); + boolean flagOver = false; + mc.fontRenderer.setUnicodeFlag(true); + //noinspection unchecked + for (GuiButton button : (List) buttonList) { + String tooltip = getButtonTooltip(button.id); + if (tooltip != null) { + mc.fontRenderer + .drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7, button.yPosition + 1, + 0xE0E0E0); + if (isMouseOver(button, mouseX, mouseY)) { + flagOver = true; + mc.fontRenderer.drawStringWithShadow("\247b?", button.xPosition + button.getButtonWidth() - 7, + button.yPosition + 1, 16777215); + mc.fontRenderer.setUnicodeFlag(flagUnicode); + if (timeStart == 0) { + timeStart = System.currentTimeMillis(); + } else if (System.currentTimeMillis() - timeStart > 1000) { + drawHoveringText(Arrays.asList(tooltip.split("\\\\n")), mouseX, mouseY, mc.fontRenderer); + } + } + } + } + if (!flagOver) { + timeStart = 0; + mc.fontRenderer.setUnicodeFlag(flagUnicode); + } + } + + protected void drawActiveSlot() { + if (activeSlot != -1) { + Slot slot = inventorySlots.getSlot(activeSlot); + int size = getSizeSlotActive(activeSlot); + int move = (size - 16) / 2; + drawRect(slot.xDisplayPosition - move, slot.yDisplayPosition - move, slot.xDisplayPosition + size - move, + slot.yDisplayPosition + size - move, 0x60aeff00); + } + } + + public void drawCenteredStringMultiLine(FontRenderer fontRendererIn, + String text, + int x1, + int x2, + int y1, + int y2, + int color) { + String[] buffer = text.split("\\n"); + float x = (x1 + x2) / 2.0f; + float y = (y1 + y2 - buffer.length * 10 + 2) / 2.0f - 10; + for (String s : buffer) { + fontRendererIn + .drawStringWithShadow(s, (int) x - fontRendererIn.getStringWidth(s) / 2, (int) (y += 10), color); + } + } + + protected boolean isMouseOver(GuiButton button, int mouseX, int mouseY) { + return mouseX >= button.xPosition + button.getButtonWidth() - 10 && + mouseX <= button.xPosition + button.getButtonWidth() && mouseY >= button.yPosition && + mouseY <= button.yPosition + 10; + } + + protected void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) { + fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color); + } + + protected abstract String getButtonTooltip(int buttonId); + + protected abstract int getSizeSlotActive(int index); + + protected Slot getSlotUnderMouse() { + Slot theSlot = null; + try { + Field field = JecaGuiContainer.class.getSuperclass().getDeclaredField("theSlot"); + field.setAccessible(true); + theSlot = (Slot) field.get(this); + field.setAccessible(false); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + return theSlot; + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java deleted file mode 100644 index 92b34ba..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/commom/GuiJustEnoughCalculation.java +++ /dev/null @@ -1,116 +0,0 @@ -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; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * @author Towdium - */ -public abstract class GuiJustEnoughCalculation extends GuiContainer { - protected GuiScreen parent; - 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")) { - 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_)); - p_77021_1_.setUnicodeFlag(b); - } else { - super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, text); - } - - - } - }; - - public GuiJustEnoughCalculation(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) { - super(inventorySlotsIn); - this.parent = parent; - } - - @Override - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - if (slotIn != null) { - slotId = slotIn.slotNumber; - } - mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer); - } - - 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) { - actionPerformed(((GuiButton) button)); - } - } - } - - public void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) { - fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color); - } - - public void updateLayout() { - } - - @Override - protected void keyTyped(char typedChar, int keyCode) { - if (keyCode == 1) { - mc.displayGuiScreen(parent); - } - } - - @Override - public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) { - RenderItem buffer1 = itemRender; - RenderItem buffer2 = GuiContainerManager.drawItems; - itemRender = renderItem; - GuiContainerManager.drawItems = renderItem; - super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); - itemRender = buffer1; - GuiContainerManager.drawItems = buffer2; - } - - 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_) { - } - } - try { - getSlot.setAccessible(true); - return (Slot) getSlot.invoke(this, x, y); - } catch (IllegalAccessException | InvocationTargetException | NullPointerException e) { - return null; - } - //getSlotAtPosition(int p_146975_1_, int p_146975_2_) - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java b/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java deleted file mode 100644 index 9d24ad0..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/commom/GuiTooltipScreen.java +++ /dev/null @@ -1,337 +0,0 @@ -package me.towdium.jecalculation.gui.commom; - -import codechicken.nei.VisiblityData; -import codechicken.nei.api.INEIGuiHandler; -import codechicken.nei.api.TaggedInventoryArea; -import com.google.common.collect.ImmutableList; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.inventory.Container; -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 { - int mousedOverButtonId = -1; - - /** - * 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 - */ - public static boolean ShowTooltipButtonMouseoverEffect = true; - - /** - * 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 - */ - public long tooltipDelay = 900; - - /** - * The maximum width in pixels a tooltip can occupy before word wrapping occurs - */ - public int tooltipMaxWidth = 150; - - protected int tooltipXOffset = 0; - protected int tooltipYOffset = 10; - - private final static int LINE_HEIGHT = 11; - - private long mouseoverTime = 0; - private long prevSystemTime = -1; - - public GuiTooltipScreen(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) { - super(inventorySlotsIn, parent); - } - - @Override - protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { - super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_); - if (ShowTooltipButtonEffect) - RenderTooltipButtonEffect(); - if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null) - for (Object button : buttonList) { - if (((GuiButton) button).id == mousedOverButtonId) { - RenderTooltipButtonMouseoverEffect(((GuiButton) button)); - } - } - } - - public void drawScreen(int mouseX, int mouseY, float f) { - for (Object button : buttonList) { - if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) { - mousedOverButtonId = ((GuiButton) button).id; - break; - } - } - - - super.drawScreen(mouseX, mouseY, f); - RenderHelper.disableStandardItemLighting(); - DrawTooltipScreen(mouseX, mouseY); - /*InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory; - Field field; - Slot theSlot = null; - try { - field = GuiContainer.class.getDeclaredField("theSlot"); - field.setAccessible(true); - theSlot = (Slot) field.get(this); - } catch (Exception ignored) {} - try { - field = GuiContainer.class.getDeclaredField("field_147006_u"); - field.setAccessible(true); - theSlot = (Slot) field.get(this); - } catch (Exception ignored) {} - if (inventoryplayer.getItemStack() == null && theSlot != null && theSlot.getHasStack()) - { - ItemStack itemstack1 = theSlot.getStack(); - //GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true); - drawHoveringText(GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true), mouseX, mouseY, fontRendererObj); - } - RenderHelper.enableStandardItemLighting();*/ - mousedOverButtonId = -1; - } - - @Override - protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { - - } - - /** - * 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 - * that are being mouseovered. - */ - 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) { - long systemTime = System.currentTimeMillis(); - - if (prevSystemTime > 0) - mouseoverTime += systemTime - prevSystemTime; - - prevSystemTime = systemTime; - } else { - mouseoverTime = 0; - } - - //render the button's tooltip - if (mouseoverTime > tooltipDelay) { - String tooltip = GetButtonTooltip(mousedOverButtonId); - if (tooltip != null) { - RenderTooltip(mouseX, mouseY, tooltip); - } - } - } - - /** - * 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; - } - - /** - * Render anything special onto all buttons that have tooltips assigned to them. - */ - 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.setUnicodeFlag(flag); - } - } - } - - /** - * Render anything special onto buttons that have tooltips assigned to them when they are mousevered. - */ - 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.setUnicodeFlag(flag); - } - - /** - * Renders a tooltip at (x,y). - */ - 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) { - s = DecodeStringCodes(s); - String[] tooltipSections = s.split(tooltipNewlineDelimeter); - ArrayList tooltipArrayList = new ArrayList(); - - for (String section : tooltipSections) { - String tooltip = ""; - String[] tooltipWords = section.split(" "); - - for (String tooltipWord : tooltipWords) { - int lineWidthWithNextWord = mc.fontRenderer.getStringWidth(tooltip + tooltipWord); - if (lineWidthWithNextWord > tooltipMaxWidth) { - tooltipArrayList.add(tooltip.trim()); - tooltip = tooltipWord + " "; - } else { - tooltip += tooltipWord + " "; - } - } - - tooltipArrayList.add(tooltip.trim()); - } - - String[] tooltipArray = new String[tooltipArrayList.size()]; - tooltipArrayList.toArray(tooltipArray); - - return tooltipArray; - } - - /** - * 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); - } - - /*** - * Gets the width of the tooltip in pixels. - */ - private int GetTooltipWidth(String[] tooltipArray) { - int longestWidth = 0; - for (String s : tooltipArray) { - int width = mc.fontRenderer.getStringWidth(s); - if (width > longestWidth) - longestWidth = width; - } - return longestWidth; - } - - /** - * Gets the height of the tooltip in pixels. - */ - private int GetTooltipHeight(String[] tooltipArray) { - int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2; - if (tooltipArray.length > 1) { - tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT; - } - return tooltipHeight; - } - - @Override - public VisiblityData modifyVisiblity(GuiContainer guiContainer, VisiblityData visiblityData) { - return null; - } - - @Override - public Iterable getItemSpawnSlots(GuiContainer guiContainer, ItemStack itemStack) { - return new ArrayList<>(); - } - - @Override - public List getInventoryAreas(GuiContainer guiContainer) { - return null; - } - - @Override - public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) { - itemStack.stackSize = 0; - return false; - } - - @Override - public boolean hideItemPanelSlot(GuiContainer guiContainer, int i, int i1, int i2, int i3) { - return false; - } - - - public class FontCodes { - //color codes for rendered strings - public static final String BLACK = "\2470"; - public static final String DARK_BLUE = "\2471"; - public static final String DARK_GREEN = "\2472"; - public static final String DARK_AQUA = "\2473"; - public static final String DARK_RED = "\2474"; - public static final String DARK_PURPLE = "\2475"; - public static final String GOLD = "\2476"; - public static final String GRAY = "\2477"; - public static final String DARK_GREY = "\2478"; - public static final String BLUE = "\2479"; - public static final String GREEN = "\247a"; - public static final String AQUA = "\247b"; - public static final String RED = "\247c"; - public static final String LIGHT_PURPLE = "\247d"; - public static final String YELLOW = "\247e"; - public static final String WHITE = "\247f"; - - //font styles - public static final String OBFUSCATED = "\247k"; - public static final String BOLD = "\247l"; - public static final String STRIKETHROUGH = "\247m"; - public static final String UNDERLINE = "\247n"; - public static final String ITALICS = "\247o"; - - public static final String RESET = "\247r"; - } - - -} \ No newline at end of file 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 deleted file mode 100644 index cf356e3..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/ContainerRecipe.java +++ /dev/null @@ -1,117 +0,0 @@ -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; - - -/** - * @author Towdium - */ -public class ContainerRecipe extends Container { - - 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 = 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) - return super.getSlot(p_75139_1_); - else - return null; - } - - @Override - public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) { - - } - - @Override - public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - if (slotId < 0 || slotId >= 16) { - return null; - } - Slot slot = getSlot(slotId); - if (slot != null) { - ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex()); - if (itemStack != null) { - if (clickedButton == 0 && mode == 0) { - ItemStackWrapper.Click.leftClick(slot.getStack(), true); - } else if (clickedButton == 0 && mode == 1) { - ItemStackWrapper.Click.leftShift(slot.getStack(), true); - } else if (clickedButton == 1 && mode == 0) { - ItemStackWrapper.Click.rightClick(slot.getStack(), true); - } else if (clickedButton == 1 && mode == 1) { - ItemStackWrapper.Click.rightShift(slot.getStack(), true); - } - slot.putStack(itemStack.stackSize == 0 ? null : itemStack); - } - } - return null; - } - - @Override - public boolean canInteractWith(EntityPlayer playerIn) { - return true; - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - return null; - } - - public Recipe buildRecipe() { - ItemStack[] output = new ItemStack[4]; - boolean flag1 = false, flag2 = false; - for (int i = 0; i < 4; i++) { - ItemStack buffer = getSlot(i).getStack(); - if (buffer != null && buffer.hasTagCompound()) { - buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID); - if (buffer.getTagCompound().hasNoTags()) { - buffer.setTagCompound(null); - } - } - output[i] = buffer; - if (output[i] != null) { - flag1 = true; - } - } - ItemStack[] input = new ItemStack[12]; - for (int i = 4; i < 16; i++) { - ItemStack buffer = getSlot(i).getStack(); - if (buffer != null && buffer.hasTagCompound()) { - buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID); - if (buffer.getTagCompound().hasNoTags()) { - buffer.setTagCompound(null); - } - } - input[i - 4] = buffer; - if (input[i - 4] != null) { - flag2 = true; - } - } - return flag1 && flag2 ? new Recipe(output, input) : null; - } -} 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 deleted file mode 100644 index a4af5e1..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/GuiRecipe.java +++ /dev/null @@ -1,181 +0,0 @@ -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; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; - -/** - * @author Towdium - */ -public class GuiRecipe extends GuiTooltipScreen { - private int activeSlot = -1; - - public GuiRecipe(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) { - super(inventorySlotsIn, parent); - } - - @Override - 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 = 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.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); - if (activeSlot != -1) { - Slot slot = inventorySlots.getSlot(activeSlot); - this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 2, - this.guiTop + slot.yDisplayPosition - 2, 176, 0, 20, 20); - } - } - - @Override - protected void actionPerformed(GuiButton button) { - int buttonId = button.id; - if (buttonId <= 15) { - Slot slot = inventorySlots.getSlot(buttonId); - if (button.displayString.equals("#")) { - slot.putStack(ItemStackWrapper.toPercentage(slot.getStack())); - button.displayString = "%"; - } else { - slot.putStack(ItemStackWrapper.toNormal(slot.getStack())); - button.displayString = "#"; - } - } - } - - - - /*@Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton){ - super.mouseClicked(mouseX, mouseY, mouseButton); - Slot slot = null; - try { - Field slotField = this.getClass().getDeclaredField("field_146998_K"); - slotField.setAccessible(true); - slot = (Slot) slotField.get(this); - } - catch (NoSuchFieldException ignored) {} - catch (IllegalAccessException ignored) {} - - if(slot != null && mouseButton == 0 && slot.getStack() == null){ - setActiveSlot(slot.getSlotIndex()); - mc.thePlayer.playSound("random.click", 1f, 1f ); - } - }*/ - - @Override - protected void keyTyped(char typedChar, int keyCode) { - if (keyCode == 1) { - if (activeSlot != -1) { - setActiveSlot(-1); - } else { - super.keyTyped(typedChar, keyCode); - } - } - } - - @Override - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - boolean b = false; - if (slotIn != null) { - b = slotIn.getHasStack(); - } - super.handleMouseClick(slotIn, slotId, clickedButton, clickType); - if (slotIn != null && b && !slotIn.getHasStack()) { - ((GuiButton) buttonList.get(slotIn.getSlotIndex())).displayString = "#"; - } - } - - public int getActiveSlot() { - return activeSlot; - } - - public void setActiveSlot(int activeSlot) { - this.activeSlot = activeSlot; - } - - public void displayRecipe(Recipe recipe) { - List output = recipe.getOutput(); - List input = recipe.getInput(); - for (int i = 0; i < 4; i++) { - if (i < output.size()) { - ItemStack itemStack = output.get(i); - this.inventorySlots.getSlot(i).putStack(itemStack); - ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true); - if (itemStack.getTagCompound().hasKey("percentage")) { - ((GuiButton) buttonList.get(i)).displayString = "%"; - } - } else { - this.inventorySlots.getSlot(i).putStack(null); - } - } - for (int i = 0; i < 12; i++) { - if (i < input.size()) { - ItemStack itemStack = input.get(i); - this.inventorySlots.getSlot(i + 4).putStack(itemStack); - ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true); - if (itemStack.getTagCompound().hasKey("percentage")) { - ((GuiButton) buttonList.get(i + 4)).displayString = "%"; - } - } else { - this.inventorySlots.getSlot(i + 4).putStack(null); - } - } - } - - @Override - protected String GetButtonTooltip(int buttonId) { - if (buttonId == 0) { - return StatCollector.translateToLocal("gui.calculator.tooltipUse"); - } else { - return null; - } - } - - @Override - public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) { - //JustEnoughCalculation.log.info(itemStack.toString()); - ItemStack buffer = itemStack.copy(); - ItemStackWrapper.NBT.setBool(buffer, "jecalculation", true); - buffer.stackSize = 1; - Slot slot = getSlotUnderMouse(i, i1); - if (slot != null) { - slot.putStack(buffer); - itemStack.stackSize = 0; - } - return false; - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/InventoryRecipe.java b/src/main/java/me/towdium/jecalculation/gui/commom/recipe/InventoryRecipe.java deleted file mode 100644 index d38c83b..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/commom/recipe/InventoryRecipe.java +++ /dev/null @@ -1,12 +0,0 @@ -package me.towdium.jecalculation.gui.commom.recipe; - -import net.minecraft.inventory.InventoryBasic; - -/** - * @author Towdium - */ -public class InventoryRecipe extends InventoryBasic { - public InventoryRecipe() { - super("Recipe", false, 16); - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java new file mode 100644 index 0000000..6ac1f01 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java @@ -0,0 +1,150 @@ +package me.towdium.jecalculation.gui.guis; + +import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.gui.JecaContainer; +import me.towdium.jecalculation.gui.JecaGuiContainer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; + +public class GuiCalculator extends JecaGuiContainer { + GuiTextField textFieldAmount; + + GuiButton buttonSearch; + GuiButton buttonAdd; + GuiButton buttonView; + GuiButton buttonSettings; + GuiButton buttonLeft; + GuiButton buttonRight; + GuiButton buttonMode; + GuiButton buttonStock; + + int activeSlot = -1; + int page = 1; + int total = 0; + + @SuppressWarnings("DuplicateBranchesInSwitch") + public enum EnumMode { + INPUT, PROCEDURE, OUTPUT, CATALYST; + + int toInt() { + switch (this) { + case INPUT: + return 1; + case PROCEDURE: + return 2; + case OUTPUT: + return 3; + case CATALYST: + return 4; + default: + return 1; + } + } + + static EnumMode fromInt(int i) { + switch (i) { + case 1: + return INPUT; + case 2: + return PROCEDURE; + case 3: + return OUTPUT; + case 4: + return CATALYST; + default: + return INPUT; + } + } + } + + public GuiCalculator(GuiScreen parent) { + super(new ContainerCalculator(), parent); + } + + @SuppressWarnings("unchecked") + @Override + public void initGui() { + super.initGui(); + buttonSearch = new GuiButton(1, guiLeft + 119, guiTop + 7, 50, 20, "search"); + buttonAdd = new GuiButton(2, guiLeft + 7, guiTop + 53, 52, 20, "Add"); + buttonView = new GuiButton(3, guiLeft + 63, guiTop + 53, 52, 20, "Records"); + buttonSettings = new GuiButton(4, guiLeft + 119, guiTop + 53, 50, 20, "Settings"); + buttonLeft = new GuiButton(5, guiLeft + 7, guiTop + 139, 14, 20, "<"); + buttonRight = new GuiButton(6, guiLeft + 45, guiTop + 139, 14, 20, ">"); + buttonMode = new GuiButton(7, guiLeft + 63, guiTop + 139, 52, 20, "Catalyst"); + buttonStock = new GuiButton(8, guiLeft + 119, guiTop + 139, 50, 20, "Stock"); + buttonList.add(buttonSearch); + buttonList.add(buttonAdd); + buttonList.add(buttonView); + buttonList.add(buttonSettings); + buttonList.add(buttonLeft); + buttonList.add(buttonRight); + buttonList.add(buttonMode); + buttonList.add(buttonStock); + textFieldAmount = new GuiTextField(fontRendererObj, guiLeft + 39, guiTop + 8, 75, 18); + } + + @Override + protected void actionPerformed(GuiButton button) { + //noinspection SwitchStatementWithTooFewBranches + switch (button.id) { + case 1: mc.displayGuiScreen(new GuiRecipeSearch(this)); + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + this.mc.getTextureManager().bindTexture( + new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiCalculator.png")); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + textFieldAmount.drawTextBox(); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + fontRendererObj.drawString("x", 30, 13, 0x404040); + drawCenteredStringWithoutShadow(fontRendererObj, "Recent", 144, 36, 0x404040); + drawCenteredString(fontRendererObj, page + "/" + total, 33, 145, 0xFFFFFF); + } + + @SuppressWarnings("SwitchStatementWithTooFewBranches") + @Override + protected String getButtonTooltip(int buttonId) { + switch (buttonId) { + case 4: + return "Hello\\nShit"; + default: + return null; + } + } + + @Override + protected int getSizeSlotActive(int index) { + return index == 0 ? 20: 0; + } + + public static class ContainerCalculator extends JecaContainer { + @Override + protected void addSlots() { + addSlotSingle(9, 9); + addSlotGroup(8, 32, 18, 18, 1, 6); + addSlotGroup(8, 82, 18, 18, 3, 9); + } + + @Nullable + @Override + public ItemStack slotClick(int slotId, + int dragType, + int clickTypeIn, + EntityPlayer player) { + return null; + } + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiEditor.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiEditor.java new file mode 100644 index 0000000..576e070 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiEditor.java @@ -0,0 +1,101 @@ +package me.towdium.jecalculation.gui.guis; + +import cpw.mods.fml.client.config.GuiButtonExt; +import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.JecaTranslator; +import me.towdium.jecalculation.gui.JecaContainer; +import me.towdium.jecalculation.gui.JecaGuiContainer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; +import java.util.ArrayList; + +public class GuiEditor extends JecaGuiContainer { + ArrayList buttonMode; + GuiButton buttonLeft; + GuiButton buttonRight; + GuiButton buttonNew; + GuiButton buttonHelp; + GuiButton buttonSave; + GuiButton buttonClear; + + + public GuiEditor(GuiScreen parent) { + super(new ContainerEditor(), parent); + } + + @SuppressWarnings("unchecked") + @Override + public void initGui() { + super.initGui(); + buttonMode = new ArrayList<>(); + int count = -1; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 4; j++) { + buttonMode.add(new GuiButtonExt(++count, 44 + j * 21 + guiLeft, 51 + i * 33 + guiTop, 10, 10, "#")); + buttonMode.add(new GuiButtonExt(++count, 54 + j * 21 + guiLeft, 51 + i * 33 + guiTop, 10, 10, "I")); + } + } + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 6; j++) { + buttonMode.add(new GuiButtonExt(++count, 44 + j * 21 + guiLeft, 117 + i * 32 + guiTop, 10, 10, "#")); + buttonMode.add(new GuiButtonExt(++count, 54 + j * 21 + guiLeft, 117 + i * 32 + guiTop, 10, 10, "I")); + } + } + buttonLeft = new GuiButtonExt(40, guiLeft + 7, guiTop + 7, 14, 20, "<"); + buttonRight = new GuiButtonExt(41, guiLeft + 90, guiTop + 7, 14, 20, ">"); + buttonNew = new GuiButtonExt(42, guiLeft + 108, guiTop + 7, 61, 20, + JecaTranslator.format("gui.editor.newGroup")); + buttonHelp = new GuiButtonExt(43, guiLeft + 131, guiTop + 75, 38, 18, JecaTranslator.format("gui.editor.help")); + buttonSave = new GuiButtonExt(44, guiLeft + 131, guiTop + 31, 38, 18, JecaTranslator.format("gui.editor.save")); + buttonClear = new GuiButtonExt(45, guiLeft + 131, guiTop + 53, 38, 18, + JecaTranslator.format("gui.editor.clear")); + buttonList.addAll(buttonMode); + buttonList.add(buttonLeft); + buttonList.add(buttonRight); + buttonList.add(buttonNew); + buttonList.add(buttonHelp); + buttonList.add(buttonSave); + buttonList.add(buttonClear); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.output"), 7, 44, 31, 61, + 0xFFFFFF); + drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.catalyst"), 7, 44, 64, 94, + 0xFFFFFF); + drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.input"), 7, 44, 97, 159, + 0xFFFFFF); + } + + @Nullable + @Override + protected String getButtonTooltip(int buttonId) { + return null; + } + + @Override + protected int getSizeSlotActive(int index) { + return 20; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + this.mc.getTextureManager() + .bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiEditor.png")); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + } + + public static class ContainerEditor extends JecaContainer { + @Override + protected void addSlots() { + addSlotGroup(46, 33, 21, 33, 1, 4); + addSlotGroup(46, 66, 21, 33, 1, 4); + addSlotGroup(46, 99, 21, 32, 2, 6); + } + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeList.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeList.java new file mode 100644 index 0000000..d619f39 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeList.java @@ -0,0 +1,38 @@ +package me.towdium.jecalculation.gui.guis; + +import cpw.mods.fml.client.config.GuiButtonExt; +import me.towdium.jecalculation.gui.JecaContainer; +import me.towdium.jecalculation.gui.JecaGuiContainer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.inventory.Container; + +public abstract class GuiRecipeList extends JecaGuiContainer { + + public GuiRecipeList(Container inventorySlotsIn, GuiScreen parent) { + super(inventorySlotsIn, parent); + } + + @Override + protected int getSizeSlotActive(int index) { + return 0; + } + + @SuppressWarnings("unchecked") + @Override + public void initGui() { + super.initGui(); + for (int i = 0; i < 5; i++) { + buttonList.add(new GuiButtonExt(2 * i, guiLeft + 83, guiTop + 32 + 21 * i, 41, 18, "edit")); + buttonList.add(new GuiButtonExt(1 + 2 * i, guiLeft + 128, guiTop + 32 + 21 * i, 41, 18, "delete")); + } + buttonList.add(new GuiButtonExt(10, guiLeft + 7, guiTop + 139, 20, 20, "<")); + buttonList.add(new GuiButtonExt(11, guiLeft + 149, guiTop + 139, 20, 20, ">")); + } + + protected static abstract class ContainerRecipeList extends JecaContainer { + @Override + protected void addSlots() { + addSlotGroup(8, 33, 18, 21, 5, 4); + } + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeSearch.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeSearch.java new file mode 100644 index 0000000..253a0c9 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipeSearch.java @@ -0,0 +1,70 @@ +package me.towdium.jecalculation.gui.guis; + +import me.towdium.jecalculation.JustEnoughCalculation; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.ResourceLocation; + +public class GuiRecipeSearch extends GuiRecipeList { + GuiButton buttonMode; + GuiButton buttonSearch; + EnumMode mode = EnumMode.OUT; + + enum EnumMode { + IN, OUT, IO; + + EnumMode next(){ + switch (this){ + case OUT: return IN; + case IN: return IO; + case IO: return OUT; + default: return OUT; + } + } + + EnumMode last(){ + switch (this){ + case OUT: return IO; + case IN: return OUT; + case IO: return IN; + default: return OUT; + } + } + } + + public GuiRecipeSearch(GuiScreen parent) { + super(new ContainerRecipeList() { + @Override + protected void addSlots() { + super.addSlots(); + addSlotSingle(9, 9); + } + }, parent); + } + + @SuppressWarnings("unchecked") + @Override + public void initGui() { + super.initGui(); + buttonMode = new GuiButton(12, 31+guiLeft, 7+guiTop, 84, 20, "mode"); + buttonSearch = new GuiButton(13, 119+guiLeft, 7+guiTop, 50, 20, "search"); + buttonList.add(buttonMode); + buttonList.add(buttonSearch); + } + + @Override + protected String getButtonTooltip(int buttonId) { + return null; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipeSearch.png")); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + } + + @Override + protected int getSizeSlotActive(int index) { + return index == 20 ? 20 : 0; + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/ContainerCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/calculator/ContainerCalculator.java deleted file mode 100644 index bd8f53b..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/ContainerCalculator.java +++ /dev/null @@ -1,69 +0,0 @@ -package me.towdium.jecalculation.gui.guis.calculator; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - - -/** - * @author Towdium - */ -public class ContainerCalculator extends Container { - EntityPlayer player; - InventoryCalculator inventoryCalculator; - - public ContainerCalculator(EntityPlayer player, ItemStack itemCalculator) { - this.player = player; - this.inventoryCalculator = new InventoryCalculator(itemCalculator); - addSlotToContainer(new Slot(inventoryCalculator, 0, 9, 9)); - int i, left, top; - i = 1; - left = 8; - top = 80; - for (int a = 0; a < 3; a++) { - for (int b = 0; b < 9; b++) { - addSlotToContainer(new Slot(inventoryCalculator, i + 9 * a + b, left + b * 18, top + a * 18)); - } - } - i = 28; - left = 8; - top = 32; - for (int a = 0; a < 1; a++) { - for (int b = 0; b < 6; b++) { - addSlotToContainer(new Slot(inventoryCalculator, i + 9 * a + b, left + b * 18, top + a * 18)); - } - } - } - - @Override - public Slot getSlot(int p_75139_1_) { - if (p_75139_1_ <= 33) - return super.getSlot(p_75139_1_); - else - return null; - } - - @Override - public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) { - } - - @Override - public boolean canInteractWith(EntityPlayer playerIn) { - return true; - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - return null; - } - - @Override - public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - return null; - } - - public EntityPlayer getPlayer() { - return player; - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/GuiCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/calculator/GuiCalculator.java deleted file mode 100644 index b9f3ccc..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/GuiCalculator.java +++ /dev/null @@ -1,523 +0,0 @@ -package me.towdium.jecalculation.gui.guis.calculator; - -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.ICraftingHandler; -import codechicken.nei.recipe.TemplateRecipeHandler; -import me.towdium.jecalculation.JecaConfig; -import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.core.Calculator; -import me.towdium.jecalculation.core.CostRecord; -import me.towdium.jecalculation.core.ItemStackWrapper; -import me.towdium.jecalculation.gui.commom.GuiTooltipScreen; -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 me.towdium.jecalculation.network.packets.PacketSyncRecord; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -import java.util.*; - -/** - * @author Towdium - */ -public class GuiCalculator extends GuiTooltipScreen { - static int recentLen = 6; - GuiTextField textFieldAmount; - GuiButton buttonLeft; - GuiButton buttonRight; - GuiButton buttonEdit; - GuiButton buttonMode; - //GuiButton buttonCalculate; - GuiButton buttonView; - CostRecord costRecord; - Map items; - int activeSlot = -1; - int page = 1; - int total = 0; - EnumMode mode = EnumMode.INPUT; - ItemStack buffer; - boolean init = false; - - public enum EnumMode { - INPUT, PROCEDURE, OUTPUT, CATALYST; - - int toInt() { - switch (this) { - case INPUT: - return 1; - case PROCEDURE: - return 2; - case OUTPUT: - return 3; - case CATALYST: - return 4; - default: - return 1; - } - } - - static EnumMode fromInt(int i) { - switch (i) { - case 1: - return INPUT; - case 2: - return PROCEDURE; - case 3: - return OUTPUT; - case 4: - return CATALYST; - default: - return INPUT; - } - } - } - - public GuiCalculator(ContainerCalculator containerCalculator) { - super(containerCalculator, null); - JustEnoughCalculation.network.sendToServer(new PacketSyncRecord()); - items = new HashMap<>(27); - } - - @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")); - //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")); - //buttonList.add(buttonCalculate); - 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")); - buttonList.add(buttonMode); - textFieldAmount = new GuiTextField(fontRendererObj, guiLeft + 39, guiTop + 8, 57, 18); - Slot dest = inventorySlots.getSlot(0); - 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 < recentLen; i++) { - inventorySlots.getSlot(28 + i).putStack(ItemStackWrapper.NBT.getItem(calculatorItem, "recent" + i)); - } - textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text")); - mode = EnumMode.fromInt(ItemStackWrapper.NBT.getInt(calculatorItem, "mode")); - init = true; - onOpen(); - if (!JecaConfig.initialized) { - ArrayList idents = new ArrayList<>(); - LOOP: - 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)) { - continue LOOP; - } - } - idents.add(((TemplateRecipeHandler) handler).getOverlayIdentifier()); - } - } - String[] strings = new String[idents.size()]; - for (int i = 0; i < idents.size(); i++) { - strings[i] = idents.get(i); - } - JecaConfig.EnumItems.ListRecipeCategory.getProperty().set(strings); - JecaConfig.save(); - JecaConfig.initialized = true; - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - //GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture( - new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiCalculator.png")); - this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); - if (activeSlot == 0) { - Slot slot = inventorySlots.getSlot(activeSlot); - 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); - } - textFieldAmount.drawTextBox(); - drawMissingTexture(); - } - - @Override - 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); - 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"); - } - return null; - } - - @Override - protected void actionPerformed(GuiButton button) { - switch (button.id) { - /*case 1: - if(inventorySlots.getSlot(0).getStack() != null){ - mode = EnumMode.INPUT; - refreshRecipe(); - } - break;*/ - case 2: - 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); - } - - mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, list)); - break; - case 4: - if (page > 1) { - page--; - } - break; - case 5: - if (page < total) { - page++; - } - break; - case 6: - switch (mode) { - case INPUT: - mode = EnumMode.PROCEDURE; - break; - case PROCEDURE: - mode = EnumMode.OUTPUT; - break; - case OUTPUT: - mode = EnumMode.CATALYST; - break; - case CATALYST: - mode = EnumMode.INPUT; - break; - } - ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem(); - ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt()); - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), - textFieldAmount.getText()); - page = 1; - break; - case 7: - mc.displayGuiScreen(new GuiRecipeViewer(new ContainerRecipeViewer(), this)); - break; - } - updateLayout(); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - //+JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText()); - textFieldAmount.mouseClicked(mouseX, mouseY, mouseButton); - super.mouseClicked(mouseX, mouseY, mouseButton); - if (mouseButton == 1 && buttonMode.mousePressed(mc, mouseX, mouseY)) { - switch (mode) { - case INPUT: - mode = EnumMode.CATALYST; - break; - case PROCEDURE: - mode = EnumMode.INPUT; - break; - case OUTPUT: - mode = EnumMode.PROCEDURE; - break; - case CATALYST: - mode = EnumMode.OUTPUT; - break; - } - mc.thePlayer.playSound("random.click", 0.8f, 0.8f); - updateLayout(); - ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem(); - ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt()); - } - 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) { - GuiCraftingRecipe.openRecipeGui("item", s.getStack().copy()); - } - 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()); - ((ContainerCalculator)inventorySlots).getPlayer().playSound("random.click", 1f, 1f ); - updateLayout(); - }*/ - - } - - @Override - 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 { - super.keyTyped(typedChar, keyCode); - } - } - } else { - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), - textFieldAmount.getText()); - - refreshRecipe(); - updateLayout(); - } - } - - public void updateLayout() { - switch (mode) { - case OUTPUT: - buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.output"); - break; - case PROCEDURE: - buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.procedure"); - break; - case INPUT: - buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.input"); - break; - case CATALYST: - buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.catalyst"); - break; - } - 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); - } - //buttonCalculate.enabled = b; - buttonView.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipe(null); - if (costRecord != null) { - switch (mode) { - case OUTPUT: - 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; - case INPUT: - 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; - } - } else { - fillSlotsWith(new ArrayList(), 0); - total = 0; - } - buttonLeft.enabled = page != 1; - buttonRight.enabled = page < total; - if (JecaConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()) { - checkItem(); - } - } - - public int getActiveSlot() { - return activeSlot; - } - - public void setActiveSlot(int activeSlot) { - 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) { - refreshRecipe(); - } - if (init) { - updateLayout(); - } - } - - protected void fillSlotsWith(List itemStacks, int start) { - int pos = 1; - for (int i = start; i < start + 27; i++) { - if (i <= itemStacks.size() - 1) { - ItemStack buffer = itemStacks.get(i); - ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true); - inventorySlots.getSlot(pos++).putStack(buffer); - } else { - inventorySlots.getSlot(pos++).putStack(null); - } - } - } - - protected void refreshRecipe() { - ItemStack dest = inventorySlots.getSlot(0).getStack(); - int i; - try { - i = Integer.valueOf(textFieldAmount.getText()); - } catch (NumberFormatException e) { - i = 1; - textFieldAmount.setTextColor(16711680); - TimerTask r = new TimerTask() { - @Override - public void run() { - textFieldAmount.setTextColor(14737632); - } - }; - Timer t = new Timer(); - t.schedule(r, 1000); - if (inventorySlots.getSlot(0).getStack() == null) { - return; - } - } - if (dest == null) { - return; - } - Calculator calculator = new Calculator(dest, i * 100); - costRecord = calculator.getCost(); - dest = dest.copy(); - dest.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID); - ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem(); - ItemStack[] stack = new ItemStack[6]; - for (int j = 0; j < recentLen; j++) { - stack[j] = ItemStackWrapper.NBT.getItem(calculatorItem, "recent" + j); - } - int duplicate = -1; - for (int j = 0; j < recentLen; j++) { - if (stack[j] != null && ItemStackWrapper.isTypeEqual(dest, stack[j])) { - duplicate = j; - } - } - if (duplicate == -1) { - ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest); - inventorySlots.getSlot(28).putStack(dest); - for (int j = 0; j < recentLen - 1; j++) { - ItemStackWrapper.NBT.setItem(calculatorItem, "recent" + (j + 1), stack[j]); - inventorySlots.getSlot(27 + 2 + j).putStack(stack[j]); - } - } else { - ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest); - inventorySlots.getSlot(28).putStack(dest); - for (int j = 0; j < duplicate; j++) { - ItemStackWrapper.NBT.setItem(calculatorItem, "recent" + (j + 1), stack[j]); - inventorySlots.getSlot(27 + 2 + j).putStack(stack[j]); - } - } - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(dest, textFieldAmount.getText()); - } - - protected void drawMissingTexture() { - for (int i = 0; i < 27; i++) { - Slot slot = inventorySlots.getSlot(i + 1); - if (items.containsKey(i)) { - int store = items.get(i); - int a = store == 0 ? 0 : store * 0x8000000 + 0x12ff0000; - drawRect(slot.xDisplayPosition + guiLeft - 1, slot.yDisplayPosition + guiTop - 1, - slot.xDisplayPosition + guiLeft + 17, slot.yDisplayPosition + guiTop + 17, a); - } - } - } - - protected void checkItem() { - if (mode != EnumMode.INPUT) { - for (int i = 0; i < 27; i++) { - items.put(i, 0); - } - return; - } - for (int i = 0; i < 27; i++) { - ItemStack itemStack = inventorySlots.getSlot(i + 1).getStack(); - if (itemStack == null) { - items.put(i, 0); - continue; - } - int amount = 0; - for (ItemStack itemStackPlayer : mc.thePlayer.inventory.mainInventory) { - if (ItemStackWrapper.isTypeEqual(itemStackPlayer, itemStack)) { - amount += itemStackPlayer.stackSize; - } - } - int d = (int) (amount / (double) ItemStackWrapper.getGhostItemAmount(itemStack) * 15); - d = d > 15 ? 0 : 15 - d; - items.put(i, d); - } - } - - @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) { - ItemStack buffer = itemStack.copy(); - buffer.stackSize = 1; - ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true); - ItemStackWrapper.NBT.setBool(buffer, "mark", true); - slot.putStack(buffer); - mode = EnumMode.INPUT; - refreshRecipe(); - updateLayout(); - JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), - textFieldAmount.getText()); - } - 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 deleted file mode 100644 index 46d734e..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/InventoryCalculator.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.towdium.jecalculation.gui.guis.calculator; - -import net.minecraft.inventory.InventoryBasic; -import net.minecraft.item.ItemStack; - -/** - * @author Towdium - */ -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/ContainerRecipeEditor.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/ContainerRecipeEditor.java deleted file mode 100644 index 3d45655..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/ContainerRecipeEditor.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.towdium.jecalculation.gui.guis.recipeEditor; - -import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe; - - -/** - * @author Towdium - */ -public class ContainerRecipeEditor extends ContainerRecipe { -} 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 deleted file mode 100644 index cb33ef2..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java +++ /dev/null @@ -1,70 +0,0 @@ -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; - -/** - * @author Towdium - */ -public class GuiRecipeEditor extends GuiRecipe { - int index = -1; - - public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index) { - super(containerRecipeEditor, parent); - this.index = index; - } - - public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent) { - super(containerRecipeEditor, parent); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float f) { - super.drawScreen(mouseX, mouseY, f); - } - - @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) { - displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(index, null)); - } - } - - @Override - protected void actionPerformed(GuiButton button) { - super.actionPerformed(button); - int buttonId = button.id; - if (buttonId == 16) { - Recipe recipe = ((ContainerRecipe) inventorySlots).buildRecipe(); - if (recipe == null) { - mc.displayGuiScreen(parent); - return; - } - if (index == -1) { - JustEnoughCalculation.proxy.getPlayerHandler().addRecipe(recipe, null); - JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(recipe, -1)); - mc.displayGuiScreen(parent); - } else { - JustEnoughCalculation.proxy.getPlayerHandler().setRecipe(recipe, index, null); - JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(recipe, index)); - mc.displayGuiScreen(parent); - } - } 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 deleted file mode 100644 index 6eae099..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java +++ /dev/null @@ -1,88 +0,0 @@ -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 java.util.List; - -/** - * @author Towdium - */ -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) { - super(containerRecipe, parent); - this.recipes = recipes; - } - - @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, ">"); - buttonList.add(buttonLeft); - buttonList.add(buttonRight); - buttonList.add(new GuiButton(18, guiLeft + 125, guiTop + 31, 44, 20, - StatCollector.translateToLocal("gui.recipePicker.delete"))); - updateLayout(); - } - - @Override - protected void actionPerformed(GuiButton button) { - super.actionPerformed(button); - int buttonId = button.id; - 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.click(buttonId); - } else if (buttonId == 16) { - if (index > 0) { - index--; - updateLayout(); - } - } else if (buttonId == 17) { - if (index < recipes.size() - 1) { - index++; - updateLayout(); - } - } else if (buttonId == 18) { - JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get(index), null); - JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(null, recipes.get(index))); - mc.displayGuiScreen(parent); - } - } - - /*@Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton){ - super.mouseClicked(mouseX, mouseY, mouseButton); - Slot slot = getSlotUnderMouse(mouseX, mouseY); - if(slot != null){ - GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index)); - mc.displayGuiScreen(recipeEditor); - recipeEditor.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null)); - recipeEditor.click(mouseX, mouseY, mouseButton); - if(slot.getStack() == null){ - recipeEditor.setActiveSlot(slot.getSlotIndex()); - } - } - }*/ - - public void updateLayout() { - displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null)); - buttonRight.enabled = index != recipes.size() - 1; - buttonLeft.enabled = index != 0; - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/ContainerRecipeViewer.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/ContainerRecipeViewer.java deleted file mode 100644 index 7567430..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/ContainerRecipeViewer.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.towdium.jecalculation.gui.guis.recipeViewer; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.InventoryBasic; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -/** - * @author Towdium - */ -public class ContainerRecipeViewer extends Container { - InventoryBasic inventory = new InventoryBasic("RecipeViewer", false, 24); - - public ContainerRecipeViewer() { - int i, left, top; - i = 0; - left = 8; - top = 8; - for (int a = 0; a < 6; a++) { - for (int b = 0; b < 4; b++) { - addSlotToContainer(new Slot(inventory, i + 4 * a + b, left + b * 18, top + a * 22)); - } - } - } - - @Override - public boolean canInteractWith(EntityPlayer playerIn) { - return true; - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - return null; - } - - @Override - public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - return null; - } - - @Override - public Slot getSlot(int p_75139_1_) { - if (p_75139_1_ <= 23) - return super.getSlot(p_75139_1_); - else - return null; - } - - @Override - public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) { - } -} diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/GuiRecipeViewer.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/GuiRecipeViewer.java deleted file mode 100644 index e22f2c2..0000000 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/GuiRecipeViewer.java +++ /dev/null @@ -1,148 +0,0 @@ -package me.towdium.jecalculation.gui.guis.recipeViewer; - -import cpw.mods.fml.client.config.GuiButtonExt; -import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.core.ItemStackWrapper; -import me.towdium.jecalculation.core.Recipe; -import me.towdium.jecalculation.gui.commom.GuiJustEnoughCalculation; -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.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; - -/** - * @author Towdium - */ -public class GuiRecipeViewer extends GuiJustEnoughCalculation { - List recipes; - GuiButton buttonLeft; - GuiButton buttonRight; - int page = 1; - int total; - - public GuiRecipeViewer(@Nonnull ContainerRecipeViewer container, @Nullable GuiScreen parent) { - super(container, parent); - } - - @Override - public void initGui() { - super.initGui(); - 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"))); - } - updateLayout(); - } - - @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")); - drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - drawCenteredString(fontRendererObj, page + "/" + total, 88, 145, 0xFFFFFF); - } - - @Override - public void updateLayout() { - recipes = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null); - 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; - ((GuiButton) buttonList.get(2 + 2 * i)).enabled = flag; - ((GuiButton) buttonList.get(3 + 2 * i)).enabled = flag; - } - buttonLeft.enabled = page != 1; - buttonRight.enabled = page < total; - } - - @Override - protected void actionPerformed(GuiButton button) { - int i = button.id; - switch (i) { - case 0: - page--; - updateLayout(); - break; - case 1: - page++; - 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.network - .sendToServer(new PacketRecipeUpdate(null, recipes.get((page - 1) * 6 + i / 2 - 1))); - updateLayout(); - } - } - } - - /** - * display the recipe at the position - * - * @param position range 1-6 - */ - public void displayRecipe(@Nullable Recipe recipe, int position) { - if (recipe != null) { - List items = recipe.getOutput(); - for (int i = 0; i < 4; i++) { - if (i < items.size()) { - ItemStack buffer = items.get(i); - ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true); - inventorySlots.getSlot((position - 1) * 4 + i).putStack(buffer); - } else { - inventorySlots.getSlot((position - 1) * 4 + i).putStack(null); - } - } - } else { - for (int i = 0; i < 4; i++) { - inventorySlots.getSlot((position - 1) * 4 + i).putStack(null); - } - } - } - - public void displayRecipes() { - if (recipes != null) { - for (int i = 1; i <= 6; i++) { - int index = i - 1 + 6 * (page - 1); - if (index < recipes.size()) { - displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null), - i); - } else { - displayRecipe(null, i); - } - } - } else { - for (int i = 1; i <= 6; i++) { - displayRecipe(null, i); - } - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java b/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java new file mode 100644 index 0000000..6f47467 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java @@ -0,0 +1,50 @@ +package me.towdium.jecalculation.nei; + +import codechicken.nei.PositionedStack; +import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.recipe.IRecipeHandler; +import me.towdium.jecalculation.core.ItemStackHelper; +import me.towdium.jecalculation.gui.guis.GuiEditor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class JecaOverlayHandler implements IOverlayHandler { + @Override + public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { + if(firstGui instanceof GuiEditor) { + List inputStacks = new ArrayList<>(); + LOOP: + for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) { + ItemStack itemStack = positionedStack.items[0]; + for (ItemStack exist : inputStacks) { + if (ItemStackHelper.isTypeEqual(exist, itemStack)) { + exist.stackSize += itemStack.stackSize; + continue LOOP; + } + } + inputStacks.add(itemStack.copy()); + } + ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0]; + + Minecraft mc = Minecraft.getMinecraft(); + mc.displayGuiScreen(new GuiEditor(firstGui)); + GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen; + if (myGuiContainer != null) { + myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack); + for (int i = 8; i <= 8 + inputStacks.size() - 1 && i <= 19; i++) { + myGuiContainer.inventorySlots.getSlot(i).putStack(inputStacks.get(i - 8)); + } + //crafting item, nei may not have + // myGuiContainer.inventorySlots.getSlot(4).putStack(); + } + + } else { + System.out.println(firstGui.getClass().toString()); + } + + } +} diff --git a/src/main/java/me/towdium/jecalculation/nei/JecaTooltipHandler.java b/src/main/java/me/towdium/jecalculation/nei/JecaTooltipHandler.java new file mode 100644 index 0000000..2766cf6 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/nei/JecaTooltipHandler.java @@ -0,0 +1,35 @@ +package me.towdium.jecalculation.nei; + +import codechicken.nei.guihook.IContainerTooltipHandler; +import me.towdium.jecalculation.gui.JecaGuiContainer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; + +import java.util.List; + +public class JecaTooltipHandler implements IContainerTooltipHandler { + @Override + public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { + return currenttip; + } + + @Override + public List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currenttip) { + if (gui instanceof JecaGuiContainer) { + ((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack); + } + return currenttip; + } + + @Override + public List handleItemTooltip(GuiContainer gui, + ItemStack itemstack, + int mousex, + int mousey, + List currenttip) { + if (gui instanceof JecaGuiContainer) { + ((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack); + } + return currenttip; + } +} diff --git a/src/main/java/me/towdium/jecalculation/nei/MyOverlayHandler.java b/src/main/java/me/towdium/jecalculation/nei/MyOverlayHandler.java deleted file mode 100644 index f83d38b..0000000 --- a/src/main/java/me/towdium/jecalculation/nei/MyOverlayHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package me.towdium.jecalculation.nei; - -import codechicken.nei.PositionedStack; -import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.IRecipeHandler; -import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.core.ItemStackWrapper; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by Towdium on 2016/3/21. - */ -public class MyOverlayHandler implements IOverlayHandler { - @Override - public void overlayRecipe(GuiContainer guiContainer, IRecipeHandler iRecipeHandler, int i, boolean b) { - ItemStack buffer = iRecipeHandler.getResultStack(i).item.copy(); - ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true); - guiContainer.inventorySlots.getSlot(0).putStack(buffer); - List itemStacks = new ArrayList<>(); - LOOP: - 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) { - ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true); - guiContainer.inventorySlots.getSlot(index++).putStack(itemStack); - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java b/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java index 8451196..fc7258a 100644 --- a/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java +++ b/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java @@ -2,27 +2,19 @@ package me.towdium.jecalculation.nei; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; -import me.towdium.jecalculation.JecaConfig; import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor; - +import me.towdium.jecalculation.gui.guis.GuiEditor; public class NEICalculatorConfig implements IConfigureNEI { + @Override public void loadConfig() { - LOOP: - for (String s : JecaConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()) { - for (String b : JecaConfig.EnumItems.ListRecipeBlackList.getProperty() - .getStringList()) { - if (s.equals(b)) { - continue LOOP; - } - } - API.registerGuiOverlay(GuiRecipeEditor.class, s); - API.registerGuiOverlayHandler(GuiRecipeEditor.class, new MyOverlayHandler(), s); + System.out.println("loaded nei config"); + String [] recipeType = new String[]{ "crafting", "crafting2x2", "smelting", "fuel", "brewing"}; + for (String ident : recipeType) { + API.registerGuiOverlay(GuiEditor.class, ident); + API.registerGuiOverlayHandler(GuiEditor.class, new JecaOverlayHandler(), ident); } - //API.registerGuiOverlay(GuiRecipeEditor.class, "crafting"); - //API.registerGuiOverlayHandler(GuiRecipeEditor.class, new MyOverlayHandler(), "crafting"); } @Override diff --git a/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java new file mode 100644 index 0000000..7f55220 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java @@ -0,0 +1,11 @@ +package me.towdium.jecalculation.nei; + +import codechicken.nei.api.API; +import codechicken.nei.guihook.GuiContainerManager; +import me.towdium.jecalculation.gui.guis.GuiEditor; + +public class NEIPlugin { + public static void init() { + GuiContainerManager.addTooltipHandler(new JecaTooltipHandler()); + } +} diff --git a/src/main/java/me/towdium/jecalculation/network/IPlayerHandler.java b/src/main/java/me/towdium/jecalculation/network/IPlayerHandler.java deleted file mode 100644 index 5429776..0000000 --- a/src/main/java/me/towdium/jecalculation/network/IPlayerHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.towdium.jecalculation.network; - -import com.google.common.collect.ImmutableList; -import me.towdium.jecalculation.core.Recipe; -import net.minecraft.item.ItemStack; - -import java.util.UUID; - -/** - * @author Towdium - */ -public interface IPlayerHandler { - - boolean getHasRecipeOf(ItemStack itemStack, UUID uuid); - - Recipe getRecipeOf(ItemStack itemStack, UUID uuid); - - ImmutableList getAllRecipeOf(ItemStack itemStack, UUID uuid); - - int getRecipeIndexOf(ItemStack itemStack, UUID uuid); - - ImmutableList getAllRecipeIndexOf(ItemStack itemStack, UUID uuid); - - void addRecipe(Recipe recipe, UUID uuid); - - void removeRecipe(int index, UUID uuid); - - void setRecipe(Recipe recipe, int index, UUID uuid); - - Recipe getRecipe(int index, UUID uuid); - - void syncItemCalculator(ItemStack itemIn, String string); - - void handleLogin(net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile event); - - void handleSave(net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile event); - - boolean removeRecipe(Recipe recipe, UUID uuid); - - boolean containsRecipe(Recipe recipe, UUID uuid); - - boolean getHasRecipe(UUID uuid); - - ImmutableList getAllRecipe(UUID uuid); - - ImmutableList getAllRecipeIndex(UUID uuid); -} diff --git a/src/main/java/me/towdium/jecalculation/network/IProxy.java b/src/main/java/me/towdium/jecalculation/network/IProxy.java index 3d85d23..53dd617 100644 --- a/src/main/java/me/towdium/jecalculation/network/IProxy.java +++ b/src/main/java/me/towdium/jecalculation/network/IProxy.java @@ -1,14 +1,5 @@ package me.towdium.jecalculation.network; -/** - * @author Towdium - */ - - public interface IProxy { - IPlayerHandler getPlayerHandler(); - void init(); - - } diff --git a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java b/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java deleted file mode 100644 index 7246e06..0000000 --- a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java +++ /dev/null @@ -1,211 +0,0 @@ -package me.towdium.jecalculation.network; - -import com.google.common.collect.ImmutableList; -import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.core.ItemStackWrapper; -import me.towdium.jecalculation.core.Recipe; -import me.towdium.jecalculation.network.packets.PacketCalculatorUpdate; -import net.minecraft.client.Minecraft; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.event.entity.player.PlayerEvent; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * @author Towdium - */ -public class PlayerHandlerClient implements IPlayerHandler { - public List recipes = new ArrayList<>(); - - @Override - public void addRecipe(Recipe recipe, UUID uuid) { - for (Recipe oneRecipe : recipes) { - if (oneRecipe.equals(recipe)) { - return; - } - } - if (recipe != null) { - recipes.add(recipe); - } - } - - @Override - public boolean getHasRecipe(UUID uuid) { - 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 < a; i++) { - builder.add(i); - } - return builder.build(); - } - - @Override - public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) { - if (itemStack == null) { - return false; - } - for (Recipe recipe : recipes) { - if (recipe.getHasOutput(itemStack)) { - return true; - } - } - return false; - } - - @Override - public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) { - int i = getRecipeIndexOf(itemStack, null); - if (i == -1) { - return null; - } 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)) { - recipeBuilder.add(recipes.get(index)); - } - return recipeBuilder.build(); - } - - @Override - public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) { - int[] result = new int[]{-1, -1, -1, -1}; - for (int[] record : getAllUnsortedRecipeIndexOf(itemStack)) { - result[record[1]] = record[0]; - } - for (int index : result) { - if (index != -1) { - return index; - } - } - return -1; - } - - @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<>()); - } - ImmutableList> resultBuffer = builder1.build(); - for (int[] result : getAllUnsortedRecipeIndexOf(itemStack)) { - resultBuffer.get(result[1]).add(result[0]); - } - ImmutableList.Builder builder2 = new ImmutableList.Builder<>(); - for (ImmutableList.Builder priority : resultBuffer) { - builder2.addAll(priority.build().reverse()); - } - return builder2.build(); - } - - @Override - public void removeRecipe(int index, UUID uuid) { - recipes.remove(index); - } - - @Override - public void setRecipe(Recipe recipe, int index, UUID uuid) { - recipes.set(index, recipe); - } - - @Override - public Recipe getRecipe(int index, UUID uuid) { - return index < recipes.size() ? recipes.get(index) : null; - } - - @Override - public void syncItemCalculator(ItemStack itemIn, String string) { - ItemStack itemStack = Minecraft.getMinecraft().thePlayer.getHeldItem(); - ItemStackWrapper.NBT.setItem(itemStack, "dest", itemIn); - ItemStackWrapper.NBT.setString(itemStack, "text", string); - JustEnoughCalculation.network.sendToServer(new PacketCalculatorUpdate(itemStack)); - } - - @Override - public void handleLogin(PlayerEvent.LoadFromFile event) { - try { - FileInputStream stream = new FileInputStream(event.getPlayerFile("jeca")); - NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(stream); - readFromNBT(tagCompound); - } catch (Exception e) { - recipes = new ArrayList<>(); - } - } - - @Override - public void handleSave(PlayerEvent.SaveToFile event) { - try { - File file = event.getPlayerFile("jeca"); - NBTTagCompound compound = new NBTTagCompound(); - writeToNBT(compound); - FileOutputStream fileoutputstream = new FileOutputStream(file); - CompressedStreamTools.writeCompressed(compound, fileoutputstream); - } catch (Exception e) { - JustEnoughCalculation.logger.warn("Fail to save records for" + event.entityPlayer.getDisplayName()); - } - } - - @Override - public boolean removeRecipe(Recipe recipe, UUID uuid) { - return recipes.remove(recipe); - } - - @Override - public boolean containsRecipe(Recipe recipe, UUID uuid) { - return recipes.contains(recipe); - } - - @Override - public ImmutableList getAllRecipe(UUID uuid) { - return ImmutableList.copyOf(recipes); - } - - ImmutableList getAllUnsortedRecipeIndexOf(ItemStack itemStack) { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - int size = recipes.size(); - int buffer; - for (int i = 0; i < size; i++) { - buffer = recipes.get(i).getOutputIndex(itemStack); - if (buffer != -1) { - builder.add(new int[]{i, buffer}); - } - } - return builder.build(); - } - - public void readFromNBT(NBTTagCompound tagCompound) { - int amount = tagCompound.getInteger("amount"); - List recipes = new ArrayList<>(amount); - for (int i = 0; i < amount; i++) { - Recipe buffer = Recipe.NBTUtl.fromNBT((NBTTagCompound) tagCompound.getTag(String.valueOf(i))); - if (buffer != null) { - recipes.add(buffer); - } - } - this.recipes = recipes; - } - - public void writeToNBT(NBTTagCompound tagCompound) { - tagCompound.setInteger("amount", recipes.size()); - int index = 0; - for (Recipe recipe : recipes) { - tagCompound.setTag(String.valueOf(index++), Recipe.NBTUtl.toNBT(recipe)); - } - } -} diff --git a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerServer.java b/src/main/java/me/towdium/jecalculation/network/PlayerHandlerServer.java deleted file mode 100644 index 11f1a83..0000000 --- a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerServer.java +++ /dev/null @@ -1,108 +0,0 @@ -package me.towdium.jecalculation.network; - -import com.google.common.collect.ImmutableList; -import me.towdium.jecalculation.core.Recipe; -import net.minecraft.item.ItemStack; -import net.minecraftforge.event.entity.player.PlayerEvent; - -import java.util.HashMap; -import java.util.UUID; - -/** - * @author Towdium - */ -public class PlayerHandlerServer implements IPlayerHandler { - private HashMap players = new HashMap<>(); - - @Override - public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) { - return false; - } - - @Override - public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) { - return null; - } - - @Override - public ImmutableList getAllRecipeOf(ItemStack itemStack, UUID uuid) { - return null; - } - - @Override - public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) { - return 0; - } - - @Override - public ImmutableList getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) { - return null; - } - - @Override - public void addRecipe(Recipe recipe, UUID uuid) { - players.get(uuid).addRecipe(recipe, null); - } - - @Override - public void removeRecipe(int index, UUID uuid) { - players.get(uuid).removeRecipe(index, null); - } - - @Override - public void setRecipe(Recipe recipe, int index, UUID uuid) { - players.get(uuid).setRecipe(recipe, index, null); - } - - @Override - public ImmutableList getAllRecipe(UUID uuid) { - return null; - } - - @Override - public ImmutableList getAllRecipeIndex(UUID uuid) { - return null; - } - - @Override - public Recipe getRecipe(int index, UUID uuid) { - return null; - } - - @Override - public void syncItemCalculator(ItemStack itemIn, String string) { - - } - - @Override - public void handleLogin(PlayerEvent.LoadFromFile event) { - PlayerHandlerClient client = new PlayerHandlerClient(); - client.handleLogin(event); - players.put(event.entityPlayer.getUniqueID(), client); - //JustEnoughCalculation.networkWrapper.sendTo(new PacketSyncRecord(client), ((EntityPlayerMP) event.entityPlayer)); - } - - @Override - public boolean getHasRecipe(UUID uuid) { - return false; - } - - @Override - public void handleSave(PlayerEvent.SaveToFile event) { - players.get(UUID.fromString(event.playerUUID)).handleSave(event); - } - - @Override - public boolean removeRecipe(Recipe recipe, UUID uuid) { - return false; - } - - @Override - public boolean containsRecipe(Recipe recipe, UUID uuid) { - return false; - } - - public PlayerHandlerClient getClient(UUID uuid) { - return players.get(uuid); - } -} diff --git a/src/main/java/me/towdium/jecalculation/network/ProxyClient.java b/src/main/java/me/towdium/jecalculation/network/ProxyClient.java index 8cdb6b7..9272719 100644 --- a/src/main/java/me/towdium/jecalculation/network/ProxyClient.java +++ b/src/main/java/me/towdium/jecalculation/network/ProxyClient.java @@ -2,30 +2,11 @@ package me.towdium.jecalculation.network; import cpw.mods.fml.common.network.NetworkRegistry; import me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.event.GuiEventHandler; -import me.towdium.jecalculation.event.PlayerEventHandler; import me.towdium.jecalculation.gui.GuiHandler; -import net.minecraftforge.common.MinecraftForge; -/** - * @author Towdium - */ public class ProxyClient implements IProxy { - PlayerHandlerClient playerHandler = new PlayerHandlerClient(); - - @Override - public IPlayerHandler getPlayerHandler() { - return playerHandler; - } - @Override public void init() { - NetworkRegistry.INSTANCE.registerGuiHandler(JustEnoughCalculation.instance, new GuiHandler()); - MinecraftForge.EVENT_BUS.register(new GuiEventHandler()); - MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); - } - - public void setPlayerHandler(PlayerHandlerClient playerHandler) { - this.playerHandler = playerHandler; + NetworkRegistry.INSTANCE.registerGuiHandler(JustEnoughCalculation.INSTANCE, new GuiHandler()); } } diff --git a/src/main/java/me/towdium/jecalculation/network/ProxyServer.java b/src/main/java/me/towdium/jecalculation/network/ProxyServer.java index cc947b2..014d40f 100644 --- a/src/main/java/me/towdium/jecalculation/network/ProxyServer.java +++ b/src/main/java/me/towdium/jecalculation/network/ProxyServer.java @@ -1,22 +1,8 @@ package me.towdium.jecalculation.network; -import me.towdium.jecalculation.event.PlayerEventHandler; -import net.minecraftforge.common.MinecraftForge; - -/** - * @author Towdium - */ -public class ProxyServer implements IProxy { - public static PlayerHandlerServer playerHandler = new PlayerHandlerServer(); - - @Override - public IPlayerHandler getPlayerHandler() { - return playerHandler; - } - +public class ProxyServer implements IProxy{ @Override public void init() { - MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); - } + } } diff --git a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java b/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java deleted file mode 100644 index 0a85231..0000000 --- a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java +++ /dev/null @@ -1,43 +0,0 @@ -package me.towdium.jecalculation.network.packets; - -import cpw.mods.fml.common.network.ByteBufUtils; -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 me.towdium.jecalculation.JecaItem; -import net.minecraft.item.ItemStack; - -/** - * @author Towdium - */ -public class PacketCalculatorUpdate implements IMessage, IMessageHandler { - ItemStack itemStack; - - public PacketCalculatorUpdate() { - } - - public PacketCalculatorUpdate(ItemStack itemStack) { - this.itemStack = itemStack; - } - - @Override - public void fromBytes(ByteBuf buf) { - itemStack = ByteBufUtils.readItemStack(buf); - } - - @Override - public void toBytes(ByteBuf buf) { - ByteBufUtils.writeItemStack(buf, itemStack); - } - - @Override - public IMessage onMessage(PacketCalculatorUpdate message, MessageContext ctx) { - if (ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof JecaItem) { - ctx.getServerHandler().playerEntity.inventory - .setInventorySlotContents(ctx.getServerHandler().playerEntity.inventory.currentItem, - message.itemStack); - } - return null; - } -} diff --git a/src/main/java/me/towdium/jecalculation/network/packets/PacketRecipeUpdate.java b/src/main/java/me/towdium/jecalculation/network/packets/PacketRecipeUpdate.java deleted file mode 100644 index cf0af63..0000000 --- a/src/main/java/me/towdium/jecalculation/network/packets/PacketRecipeUpdate.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.towdium.jecalculation.network.packets; - -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 me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.core.Recipe; -import me.towdium.jecalculation.network.IPlayerHandler; -import me.towdium.jecalculation.network.PlayerHandlerServer; - -import java.util.UUID; - -/** - * @author Towdium - */ -public class PacketRecipeUpdate implements IMessage, IMessageHandler { - Recipe recipe; - int index; - - public PacketRecipeUpdate() { - } - - public PacketRecipeUpdate(Recipe recipe, int index) { - this.recipe = recipe; - this.index = index; - } - - @Override - public void toBytes(ByteBuf buffer) { - buffer.writeInt(index); - Recipe.ByteBufUtl.toByte(buffer, recipe); - } - - @Override - public void fromBytes(ByteBuf buffer) { - index = buffer.readInt(); - recipe = Recipe.ByteBufUtl.fromByte(buffer); - } - - @Override - public IMessage onMessage(PacketRecipeUpdate message, MessageContext context) { - IPlayerHandler playerHandler = JustEnoughCalculation.proxy.getPlayerHandler(); - if (playerHandler instanceof PlayerHandlerServer) { - UUID uuid = context.getServerHandler().playerEntity.getUniqueID(); - if (message.index == -1) { - playerHandler.addRecipe(message.recipe, uuid); - } else if (message.recipe != null) { - playerHandler.setRecipe(message.recipe, message.index, uuid); - } else { - playerHandler.removeRecipe(index, uuid); - } - } - return null; - } - -} diff --git a/src/main/java/me/towdium/jecalculation/network/packets/PacketSyncRecord.java b/src/main/java/me/towdium/jecalculation/network/packets/PacketSyncRecord.java deleted file mode 100644 index 2d22409..0000000 --- a/src/main/java/me/towdium/jecalculation/network/packets/PacketSyncRecord.java +++ /dev/null @@ -1,70 +0,0 @@ -package me.towdium.jecalculation.network.packets; - -import cpw.mods.fml.common.network.ByteBufUtils; -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 me.towdium.jecalculation.JustEnoughCalculation; -import me.towdium.jecalculation.network.PlayerHandlerClient; -import me.towdium.jecalculation.network.PlayerHandlerServer; -import me.towdium.jecalculation.network.ProxyClient; -import me.towdium.jecalculation.network.ProxyServer; -import net.minecraft.nbt.NBTTagCompound; - -import java.util.UUID; - -/** - * @author Towdium - */ -public class PacketSyncRecord implements IMessage, IMessageHandler { - PlayerHandlerClient client; - - public PacketSyncRecord() { - } - - public PacketSyncRecord(PlayerHandlerClient client) { - this.client = client; - } - - @Override - public void toBytes(ByteBuf buf) { - if (client == null) { - buf.writeShort(-1); - return; - } - buf.writeShort(0); - NBTTagCompound tagCompound = new NBTTagCompound(); - client.writeToNBT(tagCompound); - ByteBufUtils.writeTag(buf, tagCompound); - } - - @Override - public void fromBytes(ByteBuf buf) { - short s = buf.readShort(); - if (s == -1) { - return; - } - this.client = new PlayerHandlerClient(); - NBTTagCompound tagCompound = ByteBufUtils.readTag(buf); - client.readFromNBT(tagCompound); - } - - @Override - public IMessage onMessage(PacketSyncRecord message, MessageContext ctx) { - if (message.client == null && JustEnoughCalculation.proxy instanceof ProxyServer) { - //JustEnoughCalculation.proxy.getPlayerHandler().handleLogin(ctx.getServerHandler().playerEntity.getDisplayNameString()); - UUID uuida = ctx.getServerHandler().playerEntity.getUniqueID(); - UUID uuidb = ctx.getServerHandler().playerEntity.getPersistentID(); - return new PacketSyncRecord( - ((PlayerHandlerServer) JustEnoughCalculation.proxy.getPlayerHandler()).getClient(uuida)); - } - if (message.client == null && JustEnoughCalculation.proxy instanceof ProxyClient) { - return null; - } - - - ((ProxyClient) JustEnoughCalculation.proxy).setPlayerHandler(message.client); - return null; - } -} diff --git a/src/main/java/me/towdium/jecalculation/utils/Utilities.java b/src/main/java/me/towdium/jecalculation/utils/Utilities.java index 56e700d..4379745 100644 --- a/src/main/java/me/towdium/jecalculation/utils/Utilities.java +++ b/src/main/java/me/towdium/jecalculation/utils/Utilities.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.text.BreakIterator; import java.text.DecimalFormat; import java.util.*; @@ -112,16 +113,9 @@ public class Utilities { } public static String translate(String unlocalized, Object... args) { - String localized = getLocalizedString(unlocalized); - return String.format(localized, args); + return net.minecraft.client.resources.I18n.format(unlocalized, args); } - private static String getLocalizedString(String unlocalized) { - // TODO Implement - return unlocalized; - } - - public static class Relation { public HashMap, V> data = new HashMap<>(); @@ -227,6 +221,7 @@ public class Utilities { } } + @Deprecated @SideOnly(Side.CLIENT) public static class I18n { public static boolean contains(String s1, String s2) { @@ -392,7 +387,7 @@ public class Utilities { FileOutputStream fos = null; try { fos = new FileOutputStream(f); - fos.write(write(nbt).getBytes(Charset.forName("UTF-8"))); + fos.write(write(nbt).getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); } finally { @@ -421,6 +416,7 @@ public class Utilities { w.sb.append('{'); if (wrap) w.indent++; + //noinspection unchecked for (String i : (Set) tags.func_150296_c()) { if (first) first = false; diff --git a/src/main/resources/assets/jecalculation/lang/en_US.lang b/src/main/resources/assets/jecalculation/lang/en_US.lang index b93d472..ebe571b 100644 --- a/src/main/resources/assets/jecalculation/lang/en_US.lang +++ b/src/main/resources/assets/jecalculation/lang/en_US.lang @@ -16,4 +16,12 @@ gui.recipeEditor.save=Save gui.recipeEditor.clear=Clear gui.recipeViewer.edit=Edit gui.recipeViewer.delete=Delete -item.item_calculator.name=Calculator +item.itemCalculator.name=Calculator + +gui.editor.output=Output +gui.editor.catalyst=Cata-\nlyst +gui.editor.input=Input +gui.editor.newGroup=New Group +gui.editor.save=Save +gui.editor.clear=Clear +gui.editor.help=Help \ No newline at end of file diff --git a/src/main/resources/assets/jecalculation/lang/zh_CN.lang b/src/main/resources/assets/jecalculation/lang/zh_CN.lang index 3b4e396..36484ab 100644 --- a/src/main/resources/assets/jecalculation/lang/zh_CN.lang +++ b/src/main/resources/assets/jecalculation/lang/zh_CN.lang @@ -16,4 +16,5 @@ gui.recipeEditor.save=储存 gui.recipeEditor.clear=清除 gui.recipeViewer.edit=编辑 gui.recipeViewer.delete=删除 -item.item_calculator.name=合成计算器 +item.itemCalculator.name=合成计算器 + diff --git a/src/main/resources/assets/jecalculation/models/item/item_calculator.json b/src/main/resources/assets/jecalculation/models/item/itemCalculator.json similarity index 52% rename from src/main/resources/assets/jecalculation/models/item/item_calculator.json rename to src/main/resources/assets/jecalculation/models/item/itemCalculator.json index 49b1708..63059a6 100644 --- a/src/main/resources/assets/jecalculation/models/item/item_calculator.json +++ b/src/main/resources/assets/jecalculation/models/item/itemCalculator.json @@ -1,6 +1,6 @@ { "parent": "builtin/generated", "textures": { - "layer0": "jecalculation:items/item_calculator" + "layer0": "jecalculation:items/itemCalculator" } } diff --git a/src/main/resources/assets/jecalculation/textures/gui/guiCalculator.png b/src/main/resources/assets/jecalculation/textures/gui/guiCalculator.png index bd1de8a..baee099 100644 Binary files a/src/main/resources/assets/jecalculation/textures/gui/guiCalculator.png and b/src/main/resources/assets/jecalculation/textures/gui/guiCalculator.png differ diff --git a/src/main/resources/assets/jecalculation/textures/items/item_calculator.png b/src/main/resources/assets/jecalculation/textures/items/itemCalculator.png similarity index 100% rename from src/main/resources/assets/jecalculation/textures/items/item_calculator.png rename to src/main/resources/assets/jecalculation/textures/items/itemCalculator.png