feat: start records

This commit is contained in:
Discreater committed 2021-04-29 22:48:22 +08:00
1 parent c5bda741a2
commit 90f768ed21
24 files changed
+286 -120

No files matched your search

@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.drawables.WContainer;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.wrappers.Single;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -4,7 +4,7 @@ import cpw.mods.fml.client.config.GuiUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.IllegalPositionException;
@@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.IWidget;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.Utilities;
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.IWidget;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.wrappers.Single;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.IWidget;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
@@ -47,7 +47,7 @@ public class WSwitcher implements IWidget {
Resource.WGT_ARR_R_D).setListenerLeft(() -> move(false));
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.COLOR_GUI_GREY);
wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
() -> keys.get(index.index()));
() -> keys.get(index.current()));
index = new Circulator(keys.size());
if (keys.size() == 1) {
left.setDisabled(true);
@@ -56,10 +56,10 @@ public class WSwitcher implements IWidget {
}
protected void move(boolean forward) {
if (forward) index.next();
else index.prev();
if (forward) index.move(1);
else index.move(-1);
if (listener != null) listener.accept(index.index());
if (listener != null) listener.accept(index.current());
}
@Override
@@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.IWPicker;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.*;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import net.minecraft.item.ItemStack;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -10,7 +10,7 @@ import me.towdium.jecalculation.client.gui.IWidget;
import me.towdium.jecalculation.client.gui.drawables.WContainer;
import me.towdium.jecalculation.client.gui.drawables.WPage;
import me.towdium.jecalculation.client.gui.drawables.WPanel;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.wrappers.Single;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -4,7 +4,7 @@ import codechicken.nei.recipe.IRecipeHandler;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.*;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import net.minecraft.item.ItemStack;
import java.util.*;
@@ -5,9 +5,9 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.IWPicker;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.*;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.core.label.labels.LabelFluidStack;
import me.towdium.jecalculation.core.label.labels.LabelOreDict;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.labels.LabelFluidStack;
import me.towdium.jecalculation.data.label.labels.LabelOreDict;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
@@ -6,7 +6,7 @@ import me.towdium.jecalculation.client.gui.IWPicker;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.*;
import me.towdium.jecalculation.core.label.labels.LabelUniversal;
import me.towdium.jecalculation.data.label.labels.LabelUniversal;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
@@ -1,66 +0,0 @@
package me.towdium.jecalculation.core;
import me.towdium.jecalculation.polyfill.Polyfill;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.StreamSupport;
/**
* Author: towdium
* Date: 17-10-6.
*/
public class Record {
public static final String KEY_NAME = "name";
public static final String KEY_CONTENT = "content";
ArrayList<Pair<String, ArrayList<Recipe>>> record = new ArrayList<>();
HashMap<String, Integer> index = new HashMap<>();
public Record(NBTTagList nbt) {
StreamSupport.stream(Polyfill.spliterator(nbt), false).filter(g -> g instanceof NBTTagCompound).forEach(g -> {
NBTTagCompound group = (NBTTagCompound) g;
String name = group.getString(KEY_NAME);
NBTTagList recipes = group.getTagList(KEY_CONTENT, 10);
StreamSupport.stream(Polyfill.spliterator(recipes), false).filter(r -> r instanceof NBTTagCompound)
.map(r -> (NBTTagCompound) r).forEach(r -> add(name, new Recipe(r)));
});
}
public void add(String group, Recipe recipe) {
Integer i = index.get(group);
if (i == null) {
record.add(new Pair<>(group, new ArrayList<>()));
i = record.size() - 1;
}
record.get(i).two.add(recipe);
}
public void set(String group, int index, Recipe recipe) {
Integer i = this.index.get(group);
if (i == null) throw new RuntimeException("Group not found: " + group + ".");
record.get(i).two.set(index, recipe);
}
public void foreach(BiConsumer<String, List<Recipe>> consumer) {
record.forEach(p -> consumer.accept(p.one, p.two));
}
public NBTTagList serialize() {
NBTTagList ret = new NBTTagList();
foreach((n, rs) -> {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString(KEY_NAME, n);
NBTTagList l = new NBTTagList();
rs.forEach(r -> l.appendTag(r.serialize()));
nbt.setTag(KEY_CONTENT, l);
ret.appendTag(nbt);
});
return ret;
}
}
@@ -1,6 +1,6 @@
package me.towdium.jecalculation.core;
package me.towdium.jecalculation.data;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.Polyfill;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -0,0 +1,153 @@
package me.towdium.jecalculation.data;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.Polyfill;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* Author: towdium
* Date: 17-10-6.
*/
public abstract class Record {
public static class RecordSP {
public static final String KEY_RECIPE = "recipe";
public static final String KEY_RECENT = "recent";
public RecordRecipe recipes;
public RecordRecent recents;
public RecordSP() {
recipes = new RecordRecipe();
recents = new RecordRecent();
}
public RecordSP(NBTTagCompound nbt) {
recipes = new RecordRecipe(nbt.getTagList(KEY_RECIPE, 10));
recents = new RecordRecent(nbt.getTagList(KEY_RECENT, 10));
}
public NBTTagCompound seialize() {
NBTTagCompound ret = new NBTTagCompound();
ret.setTag(KEY_RECIPE, recipes.serialize());
ret.setTag(KEY_RECENT, recents.setialize());
return ret;
}
}
public static class RecordMP {
HashMap<UUID, RecordSP> records;
public RecordSP get(UUID id) {
return records.get(id);
}
}
public static class RecordRecipe {
public static final String KEY_NAME = "name";
public static final String KEY_CONTENT = "content";
ArrayList<Pair<String, ArrayList<Recipe>>> record = new ArrayList<>();
HashMap<String, Integer> index = new HashMap<>();
public RecordRecipe() {
}
public RecordRecipe(NBTTagList nbt) {
StreamSupport.stream(Polyfill.spliterator(nbt), false).filter(g -> g instanceof NBTTagCompound)
.forEach(g -> {
NBTTagCompound group = (NBTTagCompound) g;
String name = group.getString(KEY_NAME);
NBTTagList recipes = group.getTagList(KEY_CONTENT, 10);
StreamSupport.stream(Polyfill.spliterator(recipes), false)
.filter(r -> r instanceof NBTTagCompound).map(r -> (NBTTagCompound) r)
.forEach(r -> add(name, new Recipe(r)));
});
}
public void add(String group, Recipe recipe) {
Integer i = index.get(group);
if (i == null) {
record.add(new Pair<>(group, new ArrayList<>()));
i = record.size() - 1;
}
record.get(i).two.add(recipe);
}
public void set(String group, int index, Recipe recipe) {
Integer i = this.index.get(group);
if (i == null)
throw new RuntimeException("Group not found: " + group + ".");
record.get(i).two.set(index, recipe);
}
public void remove(String group, int index) {
Integer i = this.index.get(group);
if (i == null)
throw new RuntimeException("Group not found: " + group + ".");
record.get(i).two.remove(index);
}
public void foreach(BiConsumer<String, List<Recipe>> consumer) {
record.forEach(p -> consumer.accept(p.one, p.two));
}
public NBTTagList serialize() {
NBTTagList ret = new NBTTagList();
foreach((n, rs) -> {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString(KEY_NAME, n);
NBTTagList l = new NBTTagList();
rs.forEach(r -> l.appendTag(r.serialize()));
nbt.setTag(KEY_CONTENT, l);
ret.appendTag(nbt);
});
return ret;
}
}
public static class RecordRecent {
Utilities.Recent<ILabel> record = new Utilities.Recent<>(9);
public RecordRecent(NBTTagList nbt) {
List<ILabel> ls = StreamSupport.stream(Polyfill.spliterator(nbt), false).filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.DESERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
new Utilities.ReversedIterator<>(ls).forEachRemaining(l -> record.push(l));
}
public RecordRecent() {
}
public void push(ILabel label) {
record.push(label);
}
public ILabel getLatest() {
return record.toList().get(0);
}
public List<ILabel> getRecords() {
List<ILabel> labels = record.toList();
return labels.subList(1, labels.size());
}
public NBTTagList setialize() {
NBTTagList ret = new NBTTagList();
record.toList().forEach(l -> ret.appendTag(ILabel.DESERIALIZER.serialize(l)));
return ret;
}
}
}
@@ -1,4 +1,4 @@
package me.towdium.jecalculation.core.label;
package me.towdium.jecalculation.data.label;
import com.google.common.base.CaseFormat;
import cpw.mods.fml.relauncher.Side;
@@ -7,10 +7,10 @@ import me.towdium.jecalculation.client.gui.IWPicker;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.guis.pickers.PickerSimple;
import me.towdium.jecalculation.client.gui.guis.pickers.PickerUniversal;
import me.towdium.jecalculation.core.label.labels.LabelFluidStack;
import me.towdium.jecalculation.core.label.labels.LabelItemStack;
import me.towdium.jecalculation.core.label.labels.LabelOreDict;
import me.towdium.jecalculation.core.label.labels.LabelUniversal;
import me.towdium.jecalculation.data.label.labels.LabelFluidStack;
import me.towdium.jecalculation.data.label.labels.LabelItemStack;
import me.towdium.jecalculation.data.label.labels.LabelOreDict;
import me.towdium.jecalculation.data.label.labels.LabelUniversal;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.ItemStackHelper;
import me.towdium.jecalculation.utils.Utilities.Relation;
@@ -52,6 +52,7 @@ public interface ILabel {
String getAmountString();
@SideOnly(Side.CLIENT)
String getDisplayName();
static String getIdentifier(ILabel c) {
@@ -1,10 +1,10 @@
package me.towdium.jecalculation.core.label.labels;
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
@@ -65,6 +65,7 @@ public class LabelFluidStack implements ILabel {
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return fluid.getLocalizedName();
}
@@ -83,6 +84,7 @@ public class LabelFluidStack implements ILabel {
}
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid));
return existing;
@@ -94,4 +96,11 @@ public class LabelFluidStack implements ILabel {
gui.drawResource(Resource.LBL_FLUID, 0, 0);
gui.drawFluid(fluid.getFluid(), 2, 2, 12, 12);
}
@Override
public boolean equals(Object obj) {
return obj instanceof LabelFluidStack
&& fluid.equals(((LabelFluidStack) obj).fluid)
&& amount == ((LabelFluidStack) obj).amount;
}
}
@@ -1,9 +1,9 @@
package me.towdium.jecalculation.core.label.labels;
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -43,6 +43,7 @@ public class LabelItemStack extends LabelSimpleAmount {
}
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(itemStack));
@@ -50,6 +51,7 @@ public class LabelItemStack extends LabelSimpleAmount {
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return itemStack.getItem() == null ? "" : itemStack.getDisplayName();
}
@@ -75,7 +77,9 @@ public class LabelItemStack extends LabelSimpleAmount {
@Override
public boolean equals(Object obj) {
return obj instanceof LabelItemStack && itemStack.equals(((LabelItemStack) obj).itemStack);
return obj instanceof LabelItemStack
&& itemStack.equals(((LabelItemStack) obj).itemStack)
&& amount == ((LabelItemStack) obj).amount;
}
public ItemStack getItemStack() {
@@ -1,11 +1,11 @@
package me.towdium.jecalculation.core.label.labels;
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
import me.towdium.jecalculation.utils.Utilities;
@@ -51,6 +51,7 @@ public class LabelOreDict extends LabelSimpleAmount {
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.L18n.format("label.ore_dict.name", name);
}
@@ -98,6 +99,7 @@ public class LabelOreDict extends LabelSimpleAmount {
}
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
@@ -1,6 +1,8 @@
package me.towdium.jecalculation.core.label.labels;
package me.towdium.jecalculation.data.label.labels;
import me.towdium.jecalculation.core.label.ILabel;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
@@ -60,6 +62,7 @@ public abstract class LabelSimpleAmount implements ILabel {
}
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
if (detailed) existing.add(FORMAT_GREY +
Utilities.L18n.format("label.common.tooltip.amount", Integer.toString(amount)));
@@ -67,6 +70,7 @@ public abstract class LabelSimpleAmount implements ILabel {
}
@Override
@SideOnly(Side.CLIENT)
public String getAmountString() {
return amount == 0 ? "" : Utilities.cutNumber(amount, 5);
}
@@ -1,10 +1,10 @@
package me.towdium.jecalculation.core.label.labels;
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
@@ -31,6 +31,7 @@ public class LabelUniversal extends LabelSimpleAmount {
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.L18n.format("label.universal.name", name);
}
@@ -53,4 +54,9 @@ public class LabelUniversal extends LabelSimpleAmount {
gui.drawResource(Resource.LBL_UNIV_B, 0, 0);
gui.drawResource(Resource.LBL_UNIV_F, 0, 0, (name.hashCode() * 0x131723) & 0xFFFFFF);
}
@Override
public boolean equals(Object obj) {
return obj instanceof LabelUniversal && name.equals(((LabelUniversal) obj).name);
}
}
@@ -1,7 +1,7 @@
package me.towdium.jecalculation.nei;
import codechicken.nei.guihook.GuiContainerManager;
import me.towdium.jecalculation.core.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel;
import net.minecraft.item.ItemStack;
public class NEIPlugin {
@@ -3,7 +3,8 @@ package me.towdium.jecalculation.utils;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameData;
import me.towdium.jecalculation.JustEnoughCalculation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Single;
import net.minecraft.client.resources.I18n;
@@ -11,6 +12,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.StringEscapeUtils;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Stream;
@@ -20,7 +23,8 @@ import java.util.stream.StreamSupport;
* Author: Towdium
* Date: 2016/6/25.
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "UnusedReturnValue"})
@ParametersAreNonnullByDefault
public class Utilities {
final static int[] scaleTable = {9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE};
static Map<String, String> dictionary = new HashMap<>();
@@ -38,8 +42,10 @@ public class Utilities {
public static String cutNumber(float f, int size) {
BiFunction<Float, Integer, String> form = (fl, len) -> {
String ret = Float.toString(fl);
if (ret.endsWith(".0")) ret = ret.substring(0, ret.length() - 2);
if (ret.length() > len) ret = ret.substring(0, len);
if (ret.endsWith(".0"))
ret = ret.substring(0, ret.length() - 2);
if (ret.length() > len)
ret = ret.substring(0, len);
return ret;
};
int scale = (int) Math.log10(f) / 3;
@@ -61,18 +67,22 @@ public class Utilities {
// MOD NAME
@Nullable
public static String getModName(ItemStack stack) {
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
JustEnoughCalculation.logger.warn(String.format("item name: %s", name)); // "minecraft:stone" or "jecalculation:item.item_calculator"
// TODO check
return name;
name = name.substring(0, name.indexOf(":"));
if (name.equals("minecraft"))
return "Minecraft";
else
return dictionary.get(name);
}
public static String getModName(FluidStack stack) {
String name = GameData.getItemRegistry().getNameForObject(stack.getFluid());
JustEnoughCalculation.logger.warn(String.format("fluid name: %s", name));
// TODO check
return name;
String name = stack.getFluid().getName();
if (name.equals("lava") || name.equals("water"))
return "Minecraft";
else
return dictionary.get(stack.getFluid().getStillIcon().getIconName().split(":")[0]);
}
public static boolean contains(String s1, String s2) {
@@ -112,17 +122,37 @@ public class Utilities {
}
public int next() {
current = current + 1 == total ? 0 : current + 1;
return current;
return current + 1 == total ? 0 : current + 1;
}
public int prev() {
current = current == 0 ? total - 1 : current - 1;
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 int index() {
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);
}
}
@@ -134,7 +164,8 @@ public class Utilities {
}
public ReversedIterator(ListIterator<T> i) {
while (i.hasNext()) i.next();
while (i.hasNext())
i.next();
this.i = i;
}
@@ -172,6 +203,7 @@ public class Utilities {
}
}
@SideOnly(Side.CLIENT)
public static class L18n {
public static Pair<String, Boolean> search(String translateKey, Object... parameters) {
Pair<String, Boolean> ret = new Pair<>(null, null);
@@ -186,4 +218,25 @@ public class Utilities {
return search(translateKey, parameters).one;
}
}
public static class Recent<T> {
LinkedList<T> data = new LinkedList<>();
int limit;
public Recent(int limit) {
this.limit = limit;
}
public void push(T obj) {
data.removeIf(t -> t.equals(obj));
data.push(obj);
if (data.size() > limit)
data.pop();
}
public List<T> toList() {
//noinspection unchecked
return (List<T>) data.clone();
}
}
}