diff --git a/build.gradle b/build.gradle index 73fbb83..6906e5f 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ compileJava { minecraft { version = '1.7.10-10.13.4.1614-1.7.10' runDir = "eclipse" + replace '@VERSION@', project.version } jar { diff --git a/src/main/java/me/towdium/jecalculation/JecaConfig.java b/src/main/java/me/towdium/jecalculation/JecaConfig.java new file mode 100644 index 0000000..6fb1e2e --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/JecaConfig.java @@ -0,0 +1,129 @@ +package me.towdium.jecalculation; + +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import java.io.File; + +public class JecaConfig { + public static boolean initialized = false; + public static Configuration config; + + public enum EnumItems { + EnableInventoryCheck, ListRecipeBlackList, ListRecipeCategory; + + public String getComment() { + switch (this) { + case EnableInventoryCheck: + return "Set to false to disable auto inventory check"; + case ListRecipeBlackList: + return "Add string identifier here to disable quick transfer of this type recipe\n" + + "Names can be found in ListRecipeCategory"; + case ListRecipeCategory: + return "List of categories, this is maintained by the mod automatically"; + } + return ""; + } + + public String getName() { + switch (this) { + case EnableInventoryCheck: + return "EnableInventoryCheck"; + case ListRecipeBlackList: + return "ListRecipeBlackList"; + case ListRecipeCategory: + return "ListRecipeCategory"; + } + return ""; + } + + public String getCategory() { + switch (this) { + case EnableInventoryCheck: + case ListRecipeBlackList: + case ListRecipeCategory: + return EnumCategory.General.toString(); + } + return ""; + } + + public EnumType getType() { + switch (this) { + case EnableInventoryCheck: + return EnumType.Boolean; + case ListRecipeBlackList: + case ListRecipeCategory: + return EnumType.ListString; + } + return EnumType.Error; + } + + public Object getDefault() { + switch (this) { + case EnableInventoryCheck: + return true; + case ListRecipeBlackList: + return new String[0]; + case ListRecipeCategory: + return new String[]{"crafting", "smelting"}; + } + return JecaConfig.empty; + } + + public Property init() { + EnumType type = this.getType(); + if (type != null) { + switch (this.getType()) { + case Boolean: + return config.get(this.getCategory(), this.getName(), (Boolean) this.getDefault(), + this.getComment()); + case ListString: + return config.get(this.getCategory(), this.getName(), (String[]) this.getDefault(), + this.getComment()); + } + config.getCategory(EnumCategory.General.toString()).get(this.getName()); + } + return config.get(this.getCategory(), this.getName(), false, this.getComment()); + } + + public Property getProperty() { + return config.getCategory(EnumCategory.General.toString()).get(this.getName()); + } + } + + public enum EnumCategory { + General; + + @Override + public String toString() { + if (this == EnumCategory.General) { + return "general"; + } + return ""; + } + } + + public enum EnumType {Boolean, ListString, Error} + + public static Object empty; + + public static void preInit(FMLPreInitializationEvent event) { + config = new Configuration(new File(event.getModConfigurationDirectory(), "JustEnoughCalculation" + ".cfg"), + JustEnoughCalculation.Reference.VERSION); + config.load(); + handleInit(); + config.save(); + } + + + public static void handleInit() { + for (EnumItems item : EnumItems.values()) { + item.init(); + } + } + + public static void save() { + config.save(); + } +} diff --git a/src/main/java/me/towdium/jecalculation/item/ItemCalculator.java b/src/main/java/me/towdium/jecalculation/JecaItem.java similarity index 67% rename from src/main/java/me/towdium/jecalculation/item/ItemCalculator.java rename to src/main/java/me/towdium/jecalculation/JecaItem.java index 692a36c..f73a7e1 100644 --- a/src/main/java/me/towdium/jecalculation/item/ItemCalculator.java +++ b/src/main/java/me/towdium/jecalculation/JecaItem.java @@ -1,7 +1,9 @@ -package me.towdium.jecalculation.item; +package me.towdium.jecalculation; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import me.towdium.jecalculation.JustEnoughCalculation; import me.towdium.jecalculation.gui.GuiHandler; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -11,10 +13,14 @@ import net.minecraft.world.World; /** * @author Towdium */ -public class ItemCalculator extends Item { +public class JecaItem extends Item { + public static JecaItem INSTANCE = new JecaItem(); - public ItemCalculator() { + public JecaItem() { + setHasSubtypes(true); setMaxStackSize(1); + setCreativeTab(CreativeTabs.tabTools); + setUnlocalizedName("item_calculator"); } @Override diff --git a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java index a1371f5..747a899 100644 --- a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java +++ b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java @@ -4,26 +4,24 @@ 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.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.GameRegistry; import cpw.mods.fml.relauncher.Side; -import me.towdium.jecalculation.item.ItemCalculator; 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.common.config.Configuration; -import net.minecraftforge.common.config.Property; import net.minecraftforge.oredict.ShapedOreRecipe; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Map; /** * @author Towdium @@ -32,30 +30,36 @@ import java.util.ArrayList; @Mod(modid = JustEnoughCalculation.Reference.MODID, name = JustEnoughCalculation.Reference.MODNAME, version = JustEnoughCalculation.Reference.VERSION, - dependencies = "after:NotEnoughItems") + dependencies = "required-after:NotEnoughItems") public class JustEnoughCalculation { - public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator") - .setTextureName(Reference.MODID + ":" + "itemCalculator"); - public static SimpleNetworkWrapper networkWrapper; - public static Logger log = LogManager.getLogger(Reference.MODID); + @Mod.Instance(Reference.MODID) + public static JustEnoughCalculation instance; - @SidedProxy(clientSide = "me.towdium.jecalculation.network.ProxyClient", + @SidedProxy(modId = Reference.MODID, + clientSide = "me.towdium.jecalculation.network.ProxyClient", serverSide = "me.towdium.jecalculation.network.ProxyServer") public static IProxy proxy; - @Mod.Instance(JustEnoughCalculation.Reference.MODID) - public static JustEnoughCalculation instance; + public static SimpleNetworkWrapper network; + public static Logger logger = LogManager.getLogger(Reference.MODID); + public static Item itemCalculator = new JecaItem().setUnlocalizedName("itemCalculator") + .setTextureName(Reference.MODID + ":" + "itemCalculator"); + + @NetworkCheckHandler + public static boolean networkCheck(Map mods, Side s) { + return s == Side.SERVER || mods.containsKey(Reference.MODID); + } @Mod.EventHandler - public static void preInit(FMLPreInitializationEvent event) { - JECConfig.preInit(event); + public static void initPre(FMLPreInitializationEvent event) { + JecaConfig.preInit(event); GameRegistry.registerItem(itemCalculator, itemCalculator.getUnlocalizedName().substring(5)); - networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID); - networkWrapper.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1, Side.SERVER); - networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2, Side.SERVER); - networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT); - networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER); + 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 @@ -89,140 +93,9 @@ public class JustEnoughCalculation { //DefaultOverlayHandler } - public static class JECConfig { - public static boolean initialized = false; - public static Configuration config; - - public enum EnumItems { - EnableInventoryCheck, ListRecipeBlackList, ListRecipeCategory; - - public String getComment() { - switch (this) { - case EnableInventoryCheck: - return "Set to false to disable auto inventory check"; - case ListRecipeBlackList: - return "Add string identifier here to disable quick transfer of this type recipe\n" + - "Names can be found in ListRecipeCategory"; - case ListRecipeCategory: - return "List of categories, this is maintained by the mod automatically"; - } - return ""; - } - - public String getName() { - switch (this) { - case EnableInventoryCheck: - return "EnableInventoryCheck"; - case ListRecipeBlackList: - return "ListRecipeBlackList"; - case ListRecipeCategory: - return "ListRecipeCategory"; - } - return ""; - } - - public String getCategory() { - switch (this) { - case EnableInventoryCheck: - return EnumCategory.General.toString(); - case ListRecipeBlackList: - return EnumCategory.General.toString(); - case ListRecipeCategory: - return EnumCategory.General.toString(); - } - return ""; - } - - public EnumType getType() { - switch (this) { - case EnableInventoryCheck: - return EnumType.Boolean; - case ListRecipeBlackList: - return EnumType.ListString; - case ListRecipeCategory: - return EnumType.ListString; - } - return EnumType.Error; - } - - public Object getDefault() { - switch (this) { - case EnableInventoryCheck: - return true; - case ListRecipeBlackList: - return new String[0]; - case ListRecipeCategory: - return new String[]{"crafting", "smelting"}; - } - return JECConfig.empty; - } - - public Property init() { - EnumType type = this.getType(); - if (type != null) { - switch (this.getType()) { - case Boolean: - return config.get(this.getCategory(), this.getName(), (Boolean) this.getDefault(), - this.getComment()); - case ListString: - return config.get(this.getCategory(), this.getName(), (String[]) this.getDefault(), - this.getComment()); - } - config.getCategory(EnumCategory.General.toString()).get(this.getName()); - } - return config.get(this.getCategory(), this.getName(), false, this.getComment()); - } - - public Property getProperty() { - return config.getCategory(EnumCategory.General.toString()).get(this.getName()); - } - } - - public enum EnumCategory { - General; - - @Override - public String toString() { - switch (this) { - case General: - return "general"; - default: - return ""; - } - } - } - - public enum EnumType {Boolean, ListString, Error} - - public static Object empty; - - public static void preInit(FMLPreInitializationEvent event) { - config = new Configuration(new File(event.getModConfigurationDirectory(), "JustEnoughCalculation" + ".cfg"), - Reference.VERSION); - config.load(); - handleFormerVersion(); - handleInit(); - config.save(); - } - - public static void handleFormerVersion() { - config.getCategory("general").remove("RecipeTypeSupport"); - } - - public static void handleInit() { - for (EnumItems item : EnumItems.values()) { - item.init(); - } - } - - public static void save() { - config.save(); - } - } - public static class Reference { public static final String MODID = "jecalculation"; public static final String MODNAME = "Just Enough Calculation"; - public static final String VERSION = "0.4.0"; + public static final String VERSION = "@VERSION@"; } } 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 index 7972475..b9f3ccc 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/calculator/GuiCalculator.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/calculator/GuiCalculator.java @@ -3,6 +3,7 @@ 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; @@ -82,7 +83,7 @@ public class GuiCalculator extends GuiTooltipScreen { public GuiCalculator(ContainerCalculator containerCalculator) { super(containerCalculator, null); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord()); + JustEnoughCalculation.network.sendToServer(new PacketSyncRecord()); items = new HashMap<>(27); } @@ -118,7 +119,7 @@ public class GuiCalculator extends GuiTooltipScreen { mode = EnumMode.fromInt(ItemStackWrapper.NBT.getInt(calculatorItem, "mode")); init = true; onOpen(); - if (!JustEnoughCalculation.JECConfig.initialized) { + if (!JecaConfig.initialized) { ArrayList idents = new ArrayList<>(); LOOP: for (ICraftingHandler handler : GuiCraftingRecipe.craftinghandlers) { @@ -138,9 +139,9 @@ public class GuiCalculator extends GuiTooltipScreen { for (int i = 0; i < idents.size(); i++) { strings[i] = idents.get(i); } - JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().set(strings); - JustEnoughCalculation.JECConfig.save(); - JustEnoughCalculation.JECConfig.initialized = true; + JecaConfig.EnumItems.ListRecipeCategory.getProperty().set(strings); + JecaConfig.save(); + JecaConfig.initialized = true; } } @@ -366,7 +367,7 @@ public class GuiCalculator extends GuiTooltipScreen { } buttonLeft.enabled = page != 1; buttonRight.enabled = page < total; - if (JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()) { + if (JecaConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()) { checkItem(); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java index fc0fbfb..cb33ef2 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/recipeEditor/GuiRecipeEditor.java @@ -54,11 +54,11 @@ public class GuiRecipeEditor extends GuiRecipe { } if (index == -1) { JustEnoughCalculation.proxy.getPlayerHandler().addRecipe(recipe, null); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, -1)); + JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(recipe, -1)); mc.displayGuiScreen(parent); } else { JustEnoughCalculation.proxy.getPlayerHandler().setRecipe(recipe, index, null); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, index)); + JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(recipe, index)); mc.displayGuiScreen(parent); } } else if (buttonId == 17) { diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java b/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java index e231a31..6eae099 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/recipePicker/GuiRecipePicker.java @@ -60,7 +60,7 @@ public class GuiRecipePicker extends GuiRecipe { } } else if (buttonId == 18) { JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get(index), null); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get(index))); + JustEnoughCalculation.network.sendToServer(new PacketRecipeUpdate(null, recipes.get(index))); mc.displayGuiScreen(parent); } } 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 index 76c2dc1..e22f2c2 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/GuiRecipeViewer.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/recipeViewer/GuiRecipeViewer.java @@ -97,7 +97,7 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation { } else { JustEnoughCalculation.proxy.getPlayerHandler() .removeRecipe(recipes.get((page - 1) * 6 + i / 2 - 1), null); - JustEnoughCalculation.networkWrapper + JustEnoughCalculation.network .sendToServer(new PacketRecipeUpdate(null, recipes.get((page - 1) * 6 + i / 2 - 1))); updateLayout(); } diff --git a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java b/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java index 2bdd5fb..7246e06 100644 --- a/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java +++ b/src/main/java/me/towdium/jecalculation/network/PlayerHandlerClient.java @@ -134,7 +134,7 @@ public class PlayerHandlerClient implements IPlayerHandler { ItemStack itemStack = Minecraft.getMinecraft().thePlayer.getHeldItem(); ItemStackWrapper.NBT.setItem(itemStack, "dest", itemIn); ItemStackWrapper.NBT.setString(itemStack, "text", string); - JustEnoughCalculation.networkWrapper.sendToServer(new PacketCalculatorUpdate(itemStack)); + JustEnoughCalculation.network.sendToServer(new PacketCalculatorUpdate(itemStack)); } @Override @@ -157,7 +157,7 @@ public class PlayerHandlerClient implements IPlayerHandler { FileOutputStream fileoutputstream = new FileOutputStream(file); CompressedStreamTools.writeCompressed(compound, fileoutputstream); } catch (Exception e) { - JustEnoughCalculation.log.warn("Fail to save records for" + event.entityPlayer.getDisplayName()); + JustEnoughCalculation.logger.warn("Fail to save records for" + event.entityPlayer.getDisplayName()); } } diff --git a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java b/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java index b2bdd9c..0a85231 100644 --- a/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java +++ b/src/main/java/me/towdium/jecalculation/network/packets/PacketCalculatorUpdate.java @@ -5,7 +5,7 @@ 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.item.ItemCalculator; +import me.towdium.jecalculation.JecaItem; import net.minecraft.item.ItemStack; /** @@ -33,7 +33,7 @@ public class PacketCalculatorUpdate implements IMessage, IMessageHandler form = (fl, len) -> format[len - 1 - (int) Math.log10(fl)].format(fl); +// int scale = (int) Math.log10(f) / 3; +// if (scale == 0) return form.apply(f, size); +// else return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1]; +// } +// +// @SuppressWarnings("OptionalUsedAsFieldOrParameterType") +// public static Stream stream(Optional o) { +// return o.map(Stream::of).orElse(Stream.empty()); +// } +// +// public static Supplier fake(Runnable r) { +// return () -> { +// r.run(); +// return null; +// }; +// } +// +// public static String repeat(String s, int n) { +// StringBuilder sb = new StringBuilder(); +// for (int i = 0; i < n; i++) sb.append(s); +// return sb.toString(); +// } +// +// // MOD NAME +// @Nullable +// public static String getModName(Item item) { +// ResourceLocation tmp = item.getRegistryName(); +// if (tmp == null) return null; +// String id = tmp.getNamespace(); +// return id.equals("minecraft") ? "Minecraft" : Loader.instance().getIndexedModList().get(id).getName(); +// } +// +// public static String getModName(Fluid fluid) { +// String name = fluid.getName(); +// if (name.equals("lava") || name.equals("water")) return "Minecraft"; +// else return Loader.instance().getIndexedModList().get(fluid.getStill().getNamespace()).getName(); +// } +// +// public static NBTTagCompound getTag(ItemStack is) { +// NBTTagCompound tagCompound = is.getTagCompound(); +// if (tagCompound == null) { +// tagCompound = new NBTTagCompound(); +// is.setTagCompound(tagCompound); +// } +// return tagCompound; +// // TODO check return is.getOrCreateSubCompound(JustEnoughCalculation.Reference.MODID); +// } +// +// public static class Relation { +// public HashMap, V> data = new HashMap<>(); +// +// public void put(K a, K b, V v) { +// Pair pair = new Pair<>(a, b); +// V tmp = data.get(pair); +// data.put(tmp == null ? new Pair<>(b, a) : pair, v); +// } +// +// @Nullable +// public V get(K a, K b) { +// V ret = data.get(new Pair<>(a, b)); +// if (ret == null) ret = data.get(new Pair<>(b, a)); +// return ret; +// } +// } +// +// public static class Timer { +// long time = System.currentTimeMillis(); +// boolean running = false; +// +// public void setState(boolean b) { +// if (!b && running) running = false; +// if (b && !running) { +// running = true; +// time = System.currentTimeMillis(); +// } +// } +// +// public long getTime() { +// return running ? System.currentTimeMillis() - time : 0; +// } +// } +// +// @SuppressWarnings("UnusedReturnValue") +// public static class Circulator { +// int total, current; +// +// public Circulator(int total) { +// this(total, 0); +// } +// +// public Circulator(int total, int current) { +// this.total = total; +// this.current = current; +// } +// +// public int next() { +// return current + 1 == total ? 0 : current + 1; +// } +// +// public int prev() { +// return current == 0 ? total - 1 : current - 1; +// } +// +// public Circulator move(int steps) { +// current += steps; +// if (current < 0) current += (-current) / total * total + total; +// else current = current % total; +// return this; +// } +// +// public int current() { +// return current; +// } +// +// public Circulator set(int index) { +// if (index >= 0 && index < total) current = index; +// else throw new RuntimeException(String.format("Expected: [0, %d), given: %d.", total, index)); +// return this; +// } +// +// public Circulator copy() { +// return new Circulator(total).set(current); +// } +// } +// +// public static class ReversedIterator implements Iterator { +// ListIterator i; +// +// public ReversedIterator(List l) { +// i = l.listIterator(l.size()); +// } +// +// @Override +// public boolean hasNext() { +// return i.hasPrevious(); +// } +// +// @Override +// public T next() { +// return i.previous(); +// } +// +// public Stream stream() { +// return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, Spliterator.ORDERED), false); +// } +// } +// +// @SideOnly(Side.CLIENT) +// public static class I18n { +// public static boolean contains(String s1, String s2) { +// return s1.contains(s2); +// } +// +// public static Pair search(String translateKey, Object... parameters) { +// Pair ret = new Pair<>(null, null); +// translateKey = "jecalculation." + translateKey; +// String buffer = format(translateKey, parameters); +// ret.two = !buffer.equals(translateKey); +// buffer = StringEscapeUtils.unescapeJava(buffer); +// ret.one = buffer.replace("\t", " "); +// return ret; +// } +// +// public static String get(String translateKey, Object... parameters) { +// return search(translateKey, parameters).one; +// } +// +// public static List wrap(String s, int width) { +// return new TextWrapper().wrap(s, MinecraftForgeClient.getLocale(), +// i -> TextWrapper.renderer.getCharWidth(i), width); +// } +// +// static class TextWrapper { +// static FontRenderer renderer = Minecraft.getMinecraft().fontRenderer; +// +// String str; +// BreakIterator it; +// List temp = new ArrayList<>(); +// Function func; +// int start, end, section, space, cursor, width; +// +// private void cut() { +// char c = str.charAt(cursor); +// if (c == '\f') cursor++; +// temp.add(str.substring(start, cursor)); +// if (c == ' ' || c == ' ' || c == '\n') cursor++; +// start = cursor; +// end = cursor; +// space = width; +// section = func.apply(str.charAt(cursor)); +// } +// +// private void move() { +// temp.add(str.substring(start, end)); +// start = end; +// space = width; +// } +// +// private List wrap(String s, Locale l, Function func, int width) { +// temp.clear(); +// start = 0; +// end = 0; +// cursor = 0; +// space = width; +// str = s; +// it = BreakIterator.getLineInstance(l); +// it.setText(s); +// this.width = width; +// this.func = func; +// for (int i = it.next(); i != BreakIterator.DONE; i = it.next()) { +// for (cursor = end; cursor < i; cursor++) { +// char ch = str.charAt(cursor); +// section += func.apply(str.charAt(cursor)); +// if (ch == '\n' || ch == '\f') cut(); +// else if (section > space) { +// if (start == end) cut(); +// else move(); +// } +// } +// space -= section; +// section = 0; +// end = cursor; +// } +// move(); +// return temp; +// } +// } +// } +// +// public static class Recent { +// LinkedList data = new LinkedList<>(); +// BiPredicate tester; +// int limit; +// +// public Recent(BiPredicate tester, int limit) { +// this.tester = tester; +// this.limit = limit; +// } +// +// public Recent(int limit) { +// this.limit = limit; +// } +// +// public boolean push(T obj, boolean replace) { +// if (replace) data.pop(); +// boolean ret = data.removeIf(t -> tester != null ? tester.test(t, obj) : t.equals(obj)); +// data.addFirst(obj); +// if (data.size() > limit) data.removeLast(); +// return ret; +// } +// +// public List toList() { +// //noinspection unchecked +// return (List) data.clone(); +// } +// +// public void clear() { +// data.clear(); +// } +// +// public int size() { +// return data.size(); +// } +// } +// +// public static class Json { +// @Nullable +// public static NBTTagCompound read(File f) { +// try { +// String s = FileUtils.readFileToString(f, "UTF-8"); +// return read(s); +// } catch (IOException e) { +// return null; +// } +// } +// +// @Nullable +// public static NBTTagCompound read(String s) { +// try { +// return JsonToNBT.getTagFromJson(s); +// } catch (NBTException e) { +// e.printStackTrace(); +// return null; +// } +// } +// +// public static void write(NBTTagCompound nbt, File f) { +// FileOutputStream fos = null; +// try { +// fos = new FileOutputStream(f); +// fos.write(write(nbt).getBytes(Charset.forName("UTF-8"))); +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (fos != null) { +// try { +// fos.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// +// public static String write(NBTTagCompound nbt) { +// Writer w = new Writer(); +// write(nbt, w); +// w.enter(); +// return w.build(); +// } +// +// private static void write(NBTBase nbt, Writer w) { +// if (nbt instanceof NBTTagCompound) { +// NBTTagCompound tags = (NBTTagCompound) nbt; +// boolean wrap = tags.getKeySet().size() > 1; +// boolean first = true; +// w.sb.append('{'); +// if (wrap) w.indent++; +// for (String i : tags.getKeySet()) { +// if (first) first = false; +// else w.sb.append(','); +// if (wrap) w.enter(); +// w.sb.append('"'); +// w.sb.append(i); +// w.sb.append("\": "); +// write(tags.getTag(i), w); +// } +// if (wrap) { +// w.indent--; +// w.enter(); +// } +// w.sb.append('}'); +// } else if (nbt instanceof NBTTagList) { +// NBTTagList tags = (NBTTagList) nbt; +// boolean wrap = tags.tagCount() > 1; +// boolean first = true; +// w.sb.append('['); +// if (wrap) w.indent++; +// for (NBTBase i : tags) { +// if (first) first = false; +// else w.sb.append(','); +// if (wrap) w.enter(); +// write(i, w); +// } +// if (wrap) { +// w.indent--; +// w.enter(); +// } +// w.sb.append(']'); +// } else w.sb.append(nbt.toString()); +// } +// +// private static class Writer { +// public int indent = 0; +// StringBuilder sb = new StringBuilder(); +// +// public void enter() { +// sb.append('\n'); +// char[] tmp = new char[4 * indent]; +// Arrays.fill(tmp, ' '); +// sb.append(tmp); +// } +// +// public String build() { +// return sb.toString(); +// } +// } +// } +//} diff --git a/src/main/java/me/towdium/jecalculation/utils/wrappers/Pair.java b/src/main/java/me/towdium/jecalculation/utils/wrappers/Pair.java new file mode 100644 index 0000000..d435b3d --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/utils/wrappers/Pair.java @@ -0,0 +1,52 @@ +package me.towdium.jecalculation.utils.wrappers; + +/** + * Author: Towdium + * Date: 2016/7/1. + */ +public class Pair { + public K one; + public V two; + + public Pair(K one, V two) { + this.one = one; + this.two = two; + } + + @Override + public int hashCode() { + return one.hashCode() + two.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Pair) { + Pair p = (Pair) obj; + return one.equals(p.one) && two.equals(p.two); + } + return false; + } + + public boolean swap(Class ke, Class ve) { + if (ke.isInstance(one) && ve.isInstance(two)) return true; + else if (!(ke.isInstance(two) && ve.isInstance(one))) return false; + else { + //noinspection unchecked + K o = (K) two; + //noinspection unchecked + two = (V) one; + one = o; + return true; + } + } + + public Pair setOne(K one) { + this.one = one; + return this; + } + + public Pair setTwo(V two) { + this.two = two; + return this; + } +} diff --git a/src/main/java/me/towdium/jecalculation/utils/wrappers/Quad.java b/src/main/java/me/towdium/jecalculation/utils/wrappers/Quad.java new file mode 100644 index 0000000..62daaed --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/utils/wrappers/Quad.java @@ -0,0 +1,19 @@ +package me.towdium.jecalculation.utils.wrappers; + +/** + * Author: Towdium + * Date: 18-12-7 + */ +public class Quad { + public T one; + public U two; + public V three; + public W four; + + public Quad(T one, U two, V three, W four) { + this.one = one; + this.two = two; + this.three = three; + this.four = four; + } +} diff --git a/src/main/java/me/towdium/jecalculation/utils/wrappers/Trio.java b/src/main/java/me/towdium/jecalculation/utils/wrappers/Trio.java new file mode 100644 index 0000000..5a75900 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/utils/wrappers/Trio.java @@ -0,0 +1,17 @@ +package me.towdium.jecalculation.utils.wrappers; + +/** + * Author: Towdium + * Date: 2016/7/1. + */ +public class Trio { + public T one; + public U two; + public V three; + + public Trio(T one, U two, V three) { + this.one = one; + this.two = two; + this.three = three; + } +} diff --git a/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java b/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java new file mode 100644 index 0000000..1e84be2 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java @@ -0,0 +1,47 @@ +package me.towdium.jecalculation.utils.wrappers; + +import javax.annotation.Nullable; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.function.Supplier; + +/** + * Author: Towdium + * Date: 2016/7/1. + */ +public class Wrapper { + public T value; + public Predicate predicate = t -> true; + + public Wrapper(T value) { + this.value = value; + } + + public Wrapper push(@Nullable T value) { + if (value != null && predicate.test(value)) + this.value = value; + return this; + } + + public Wrapper or(Supplier s) { + if (value == null) value = s.get(); + return this; + } + + public Optional toOptional() { + return Optional.ofNullable(value); + } + + public Wrapper ifPresent(Consumer c) { + if (value != null) + c.accept(value); + return this; + } + + public Wrapper ifPresentNot(Runnable r) { + if (value == null) + r.run(); + return this; + } +} diff --git a/src/main/resources/assets/jecalculation/models/item/itemCalculator.json b/src/main/resources/assets/jecalculation/models/item/itemCalculator.json index 57c1a7d..63059a6 100644 --- a/src/main/resources/assets/jecalculation/models/item/itemCalculator.json +++ b/src/main/resources/assets/jecalculation/models/item/itemCalculator.json @@ -2,17 +2,5 @@ "parent": "builtin/generated", "textures": { "layer0": "jecalculation:items/itemCalculator" - }, - "display": { - "thirdperson": { - "rotation": [ -90, 0, 0 ], - "translation": [ 0, 1, -3 ], - "scale": [ 0.55, 0.55, 0.55 ] - }, - "firstperson": { - "rotation": [ 0, -135, 25 ], - "translation": [ 0, 4, 2 ], - "scale": [ 1.7, 1.7, 1.7 ] - } } }