Chore: rename

- rename networkWrapper to network
- move JECConfig and ItemCalculator to outer package and rename
This commit is contained in:
Discreater committed 2021-03-01 00:31:16 +08:00
1 parent 4b5de3267e
commit 2989787c86
18 files changed
+746 -183

No files matched your search

@@ -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();
}
}
@@ -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
@@ -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<String, String> 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@";
}
}
@@ -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<String> 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();
}
}
@@ -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) {
@@ -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);
}
}
@@ -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();
}
@@ -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());
}
}
@@ -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<PacketC
@Override
public IMessage onMessage(PacketCalculatorUpdate message, MessageContext ctx) {
if (ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof ItemCalculator) {
if (ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof JecaItem) {
ctx.getServerHandler().playerEntity.inventory
.setInventorySlotContents(ctx.getServerHandler().playerEntity.inventory.currentItem,
message.itemStack);
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.plugin;
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;
@@ -10,9 +11,9 @@ public class NEICalculatorConfig implements IConfigureNEI {
@Override
public void loadConfig() {
LOOP:
for (String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()) {
for (String b : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty()
.getStringList()) {
for (String s : JecaConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()) {
for (String b : JecaConfig.EnumItems.ListRecipeBlackList.getProperty()
.getStringList()) {
if (s.equals(b)) {
continue LOOP;
}
@@ -0,0 +1,8 @@
package me.towdium.jecalculation.utils;
/**
* Author: towdium
* Date: 8/10/17.
*/
public class IllegalPositionException extends RuntimeException {
}
@@ -0,0 +1,421 @@
//package me.towdium.jecalculation.utils;
//
//import me.towdium.jecalculation.JustEnoughCalculation;
//import me.towdium.jecalculation.utils.wrappers.Pair;
//import net.minecraft.client.Minecraft;
//import net.minecraft.client.gui.FontRenderer;
//import net.minecraft.item.Item;
//import net.minecraft.item.ItemStack;
//import net.minecraft.nbt.*;
//import net.minecraft.util.ResourceLocation;
//import net.minecraftforge.client.MinecraftForgeClient;
//import net.minecraftforge.fluids.Fluid;
//import net.minecraftforge.fml.common.Loader;
//import net.minecraftforge.fml.relauncher.Side;
//import net.minecraftforge.fml.relauncher.SideOnly;
//import org.apache.commons.io.FileUtils;
//import org.apache.commons.lang3.StringEscapeUtils;
//
//import javax.annotation.Nullable;
//import javax.annotation.ParametersAreNonnullByDefault;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.nio.charset.Charset;
//import java.text.BreakIterator;
//import java.text.DecimalFormat;
//import java.util.*;
//import java.util.function.BiFunction;
//import java.util.function.BiPredicate;
//import java.util.function.Function;
//import java.util.function.Supplier;
//import java.util.stream.Stream;
//import java.util.stream.StreamSupport;
//
//import static net.minecraft.client.resources.I18n.format;
//
///**
// * Author: Towdium
// * Date: 2016/6/25.
// */
//@SuppressWarnings("UnusedReturnValue")
//@ParametersAreNonnullByDefault
//public class Utilities {
// // FLOAT FORMATTING
// public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T', 'P'};
// public static DecimalFormat[] format = new DecimalFormat[]{
// new DecimalFormat("#."), new DecimalFormat("#.#"), new DecimalFormat("#.##"),
// new DecimalFormat("#.###"), new DecimalFormat("#.####")
// };
//
// public static String cutNumber(float f, int size) {
// BiFunction<Float, Integer, String> 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 <T> Stream<T> stream(Optional<T> o) {
// return o.map(Stream::of).orElse(Stream.empty());
// }
//
// public static <T> Supplier<T> 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<K, V> {
// public HashMap<Pair<K, K>, V> data = new HashMap<>();
//
// public void put(K a, K b, V v) {
// Pair<K, K> 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<T> implements Iterator<T> {
// ListIterator<T> i;
//
// public ReversedIterator(List<T> l) {
// i = l.listIterator(l.size());
// }
//
// @Override
// public boolean hasNext() {
// return i.hasPrevious();
// }
//
// @Override
// public T next() {
// return i.previous();
// }
//
// public Stream<T> 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<String, Boolean> search(String translateKey, Object... parameters) {
// Pair<String, Boolean> 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<String> 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<String> temp = new ArrayList<>();
// Function<Character, Integer> 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<String> wrap(String s, Locale l, Function<Character, Integer> 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<T> {
// LinkedList<T> data = new LinkedList<>();
// BiPredicate<T, T> tester;
// int limit;
//
// public Recent(BiPredicate<T, T> 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<T> toList() {
// //noinspection unchecked
// return (List<T>) 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();
// }
// }
// }
//}
@@ -0,0 +1,52 @@
package me.towdium.jecalculation.utils.wrappers;
/**
* Author: Towdium
* Date: 2016/7/1.
*/
public class Pair<K, V> {
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<? extends K> ke, Class<? extends V> 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<K, V> setOne(K one) {
this.one = one;
return this;
}
public Pair<K, V> setTwo(V two) {
this.two = two;
return this;
}
}
@@ -0,0 +1,19 @@
package me.towdium.jecalculation.utils.wrappers;
/**
* Author: Towdium
* Date: 18-12-7
*/
public class Quad<T, U, V, W> {
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;
}
}
@@ -0,0 +1,17 @@
package me.towdium.jecalculation.utils.wrappers;
/**
* Author: Towdium
* Date: 2016/7/1.
*/
public class Trio<T, U, V> {
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;
}
}
@@ -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<T> {
public T value;
public Predicate<T> predicate = t -> true;
public Wrapper(T value) {
this.value = value;
}
public Wrapper<T> push(@Nullable T value) {
if (value != null && predicate.test(value))
this.value = value;
return this;
}
public Wrapper<T> or(Supplier<T> s) {
if (value == null) value = s.get();
return this;
}
public Optional<T> toOptional() {
return Optional.ofNullable(value);
}
public Wrapper<T> ifPresent(Consumer<T> c) {
if (value != null)
c.accept(value);
return this;
}
public Wrapper<T> ifPresentNot(Runnable r) {
if (value == null)
r.run();
return this;
}
}