mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 11:49:06 +00:00
feat: label fluid stack
This commit is contained in:
1 parent
86213bf6c8
commit
542ebbe83b
12 files changed
+225
-91
No files matched your search
@@ -193,6 +193,11 @@ public class JecGui extends GuiContainer {
|
||||
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
|
||||
IIcon fluidStillIcon = f.getStillIcon();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
int color = f.getColor();
|
||||
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
GlStateManager.color(red, green, blue, 1.0F);
|
||||
if (fluidStillIcon != null)
|
||||
drawTexturedModelRectFromIcon(xPos, yPos, fluidStillIcon, xSize, ySize);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Resource {
|
||||
public static final Resource ICN_HELP_N = new Resource(84, 42, 14, 14);
|
||||
public static final Resource ICN_HELP_F = new Resource(84, 28, 14, 14);
|
||||
public static final Resource LBL_ORE_DICT = new Resource(0, 56, 16, 16);
|
||||
public static final Resource LBL_FLUID = new Resource(16, 56, 16, 16);
|
||||
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected ResourceLocation rl;
|
||||
|
||||
@@ -48,14 +48,16 @@ public class DLabel implements IDrawable {
|
||||
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
|
||||
label.drawEntry(gui, xPos + xSize / 2, yPos + ySize / 2, true);
|
||||
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
|
||||
gui.drawText(xPos + xSize / 2 + 7.5f,
|
||||
yPos + ySize / 2 + 7 - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font,
|
||||
label.getAmountString());
|
||||
if (label != ILabel.EMPTY && mouseIn(xMouse, yMouse)) {
|
||||
gui.drawText(xPos + xSize / 2 + 7.5f, yPos + ySize / 2 + 7 -
|
||||
(int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, label.getAmountString());
|
||||
if (mouseIn(xMouse, yMouse)) {
|
||||
gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
|
||||
ArrayList<String> buf = new ArrayList<>();
|
||||
buf.add(label.getDisplayName());
|
||||
gui.drawTooltip(xMouse, yMouse, label.getToolTip(buf));
|
||||
if (label != ILabel.EMPTY) {
|
||||
ArrayList<String> buf = new ArrayList<>();
|
||||
buf.add(label.getDisplayName());
|
||||
gui.drawTooltip(xMouse, yMouse,
|
||||
label.getToolTip(buf, mode == enumMode.EDITOR || mode == enumMode.RESULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GuiLabel extends DContainer {
|
||||
Single<Integer> index = new Single<>(0);
|
||||
ILabel.EDITOR.getRecords().forEach(r -> {
|
||||
int i = index.value;
|
||||
add(new DPage(0, r, false).setListener(() -> refresh(i)));
|
||||
add(new DPage(i, r, false).setListener(() -> refresh(i)));
|
||||
index.value += 1;
|
||||
});
|
||||
add(new DPanel());
|
||||
|
||||
@@ -3,6 +3,8 @@ package me.towdium.jecalculation.core.labels;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DContainer;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelItemStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
@@ -12,6 +14,7 @@ import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.*;
|
||||
@@ -24,7 +27,7 @@ import java.util.stream.Collectors;
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public interface ILabel {
|
||||
RegistryEntryMerger MERGER = RegistryEntryMerger.INSTANCE;
|
||||
RegistryMerger MERGER = RegistryMerger.INSTANCE;
|
||||
RegistryDeserializer DESERIALIZER = RegistryDeserializer.INSTANCE;
|
||||
RegistryConverterItem CONVERTER_ITEM = RegistryConverterItem.INSTANCE;
|
||||
RegistryConverterFluid CONVERTER_FLUID = RegistryConverterFluid.INSTANCE;
|
||||
@@ -32,6 +35,7 @@ public interface ILabel {
|
||||
ILabel EMPTY = new LabelItemStack(ItemStackHelper.EMPTY_ITEM_STACK, 0);
|
||||
|
||||
String FORMAT_BLUE = "\u00A79";
|
||||
String FORMAT_GREY = "\u00A78";
|
||||
String FORMAT_ITALIC = "\u00A7o";
|
||||
|
||||
ILabel increaseAmount();
|
||||
@@ -46,16 +50,18 @@ public interface ILabel {
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
default List<String> getToolTip(List<String> existing) {
|
||||
return existing;
|
||||
static String getIdentifier(ILabel c) {
|
||||
return getIdentifier(c.getClass());
|
||||
}
|
||||
|
||||
default String getIdentifier() {
|
||||
String s = this.getClass().getSimpleName();
|
||||
static String getIdentifier(Class<? extends ILabel> c) {
|
||||
String s = c.getSimpleName();
|
||||
if (s.startsWith("Label")) s = s.substring(5);
|
||||
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, s);
|
||||
}
|
||||
|
||||
List<String> getToolTip(List<String> existing, boolean detailed);
|
||||
|
||||
ILabel copy();
|
||||
|
||||
NBTTagCompound toNBTTagCompound();
|
||||
@@ -78,18 +84,18 @@ public interface ILabel {
|
||||
* to operate the {@link ILabel}.
|
||||
* For registering, see {@link RegistryDeserializer}.
|
||||
*/
|
||||
class RegistryEntryMerger {
|
||||
public static final RegistryEntryMerger INSTANCE;
|
||||
class RegistryMerger {
|
||||
public static final RegistryMerger INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryEntryMerger();
|
||||
INSTANCE = new RegistryMerger();
|
||||
// registerGuess functions here
|
||||
}
|
||||
|
||||
private Relation<String, MergerFunction> functions = new Relation<>();
|
||||
|
||||
|
||||
private RegistryEntryMerger() {
|
||||
private RegistryMerger() {
|
||||
}
|
||||
|
||||
public void register(String a, String b, MergerFunction func) {
|
||||
@@ -97,12 +103,12 @@ public interface ILabel {
|
||||
}
|
||||
|
||||
public Pair<ILabel, ILabel> merge(ILabel a, ILabel b, boolean add) {
|
||||
return functions.get(a.getIdentifier(), b.getIdentifier())
|
||||
.orElse((x, y, f) -> new Pair<>(x, y)).merge(a, b, add);
|
||||
return functions.get(ILabel.getIdentifier(a), ILabel.getIdentifier(b))
|
||||
.orElse((x, y, f) -> new Pair<>(x, y)).merge(a, b, add);
|
||||
}
|
||||
|
||||
public boolean test(ILabel a, ILabel b) {
|
||||
Optional<MergerFunction> f = functions.get(a.getIdentifier(), b.getIdentifier());
|
||||
Optional<MergerFunction> f = functions.get(ILabel.getIdentifier(a), ILabel.getIdentifier(b));
|
||||
if (!f.isPresent()) return false;
|
||||
else {
|
||||
Pair<ILabel, ILabel> p = f.get().merge(a, b, true);
|
||||
@@ -125,7 +131,7 @@ public interface ILabel {
|
||||
/**
|
||||
* This class is used to registerGuess an {@link ILabel} type.
|
||||
* Here you can find the identifier and deserializer of one type.
|
||||
* For {@link ILabel} operations, see {@link RegistryEntryMerger}
|
||||
* For {@link ILabel} operations, see {@link RegistryMerger}
|
||||
*/
|
||||
class RegistryDeserializer {
|
||||
public static final String KEY_IDENTIFIER = "identifier";
|
||||
@@ -135,7 +141,9 @@ public interface ILabel {
|
||||
static {
|
||||
INSTANCE = new RegistryDeserializer();
|
||||
|
||||
INSTANCE.register("itemStack", LabelOreDict::new);
|
||||
INSTANCE.register(ILabel.getIdentifier(LabelOreDict.class), LabelOreDict::new);
|
||||
INSTANCE.register(ILabel.getIdentifier(LabelItemStack.class), LabelItemStack::new);
|
||||
INSTANCE.register(ILabel.getIdentifier(LabelFluidStack.class), LabelFluidStack::new);
|
||||
}
|
||||
|
||||
private HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
|
||||
@@ -168,9 +176,8 @@ public interface ILabel {
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverter<T> {
|
||||
List<Function<List<T>, List<ILabel>>> handlersGuess = new ArrayList<>();
|
||||
List<Function<T, ILabel>> handlersRaw = new ArrayList<>();
|
||||
abstract class RegistryConverter<T> {
|
||||
List<Function<List<T>, List<ILabel>>> handlers = new ArrayList<>();
|
||||
|
||||
private RegistryConverter() {
|
||||
}
|
||||
@@ -179,26 +186,19 @@ public interface ILabel {
|
||||
* @param ingredient the ingredient, possibly itemStack or FluidStack
|
||||
* @return the identical representation
|
||||
*/
|
||||
public ILabel toLabel(T ingredient) {
|
||||
return handlersRaw.stream().map(h -> h.apply(ingredient))
|
||||
.filter(Objects::nonNull).findFirst().orElse(ILabel.EMPTY);
|
||||
}
|
||||
public abstract ILabel toLabel(T ingredient);
|
||||
|
||||
/**
|
||||
* @param ingredients the list of ingredient, possibly itemStack or FluidStack
|
||||
* @return list of guessed representation, sorted by possibility
|
||||
*/
|
||||
public List<ILabel> toLabel(List<T> ingredients) {
|
||||
return new ReversedIterator<>(handlersGuess).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void registerGuess(Function<List<T>, List<ILabel>> handler) {
|
||||
handlersGuess.add(handler);
|
||||
}
|
||||
|
||||
void registerRaw(Function<T, ILabel> handler) {
|
||||
handlersRaw.add(handler);
|
||||
void register(Function<List<T>, List<ILabel>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,14 +208,15 @@ public interface ILabel {
|
||||
static {
|
||||
INSTANCE = new RegistryConverterItem();
|
||||
|
||||
INSTANCE.registerRaw(RegistryConverterItem::convertRawItemStack);
|
||||
INSTANCE.register(LabelOreDict::guess);
|
||||
}
|
||||
|
||||
private RegistryConverterItem() {
|
||||
}
|
||||
|
||||
public static ILabel convertRawItemStack(ItemStack is) {
|
||||
return new LabelItemStack(is);
|
||||
@Override
|
||||
public ILabel toLabel(ItemStack ingredient) {
|
||||
return new LabelItemStack(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +229,11 @@ public interface ILabel {
|
||||
|
||||
private RegistryConverterFluid() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel toLabel(FluidStack ingredient) {
|
||||
return new LabelFluidStack(new FluidStack(ingredient.getFluid(), 1000), ingredient.amount);
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryEditor {
|
||||
@@ -237,8 +243,11 @@ public interface ILabel {
|
||||
INSTANCE = new RegistryEditor();
|
||||
|
||||
INSTANCE.register(LabelOreDict.getEditor(), "common.label.ore_dict", new LabelOreDict("ingotIron"));
|
||||
INSTANCE.register(LabelFluidStack.getEditor(), "common.label.fluid_stack",
|
||||
new LabelFluidStack(new FluidStack(FluidRegistry.WATER, 1000), 1000));
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Record> records = new ArrayList<>();
|
||||
|
||||
private RegistryEditor() {
|
||||
@@ -256,6 +265,16 @@ public interface ILabel {
|
||||
IEditor setCallback(Consumer<ILabel> callback);
|
||||
}
|
||||
|
||||
public static class Editor extends DContainer implements RegistryEditor.IEditor {
|
||||
protected Consumer<ILabel> callback;
|
||||
|
||||
@Override
|
||||
public RegistryEditor.IEditor setCallback(Consumer<ILabel> callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Record {
|
||||
public IEditor editor;
|
||||
public String localizeKey;
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DText;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-27.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class LabelFluidStack implements ILabel {
|
||||
public static final String KEY_FLUID = "name";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
FluidStack fluid;
|
||||
int amount;
|
||||
|
||||
public LabelFluidStack(FluidStack fluid, int amount) {
|
||||
this.fluid = fluid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelFluidStack(NBTTagCompound nbt) {
|
||||
fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag(KEY_FLUID));
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
public static RegistryEditor.Editor getEditor() {
|
||||
return new Editor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel increaseAmount() {
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel increaseAmountLarge() {
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel decreaseAmount() {
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel decreaseAmountLarge() {
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAmountString() {
|
||||
return amount >= 1000 ? Utilities.cutNumber(amount / 1000f, 4) + "B" : Integer.toString(amount) + "mB";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return fluid.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel copy() {
|
||||
return new LabelFluidStack(fluid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setTag(KEY_AMOUNT, fluid.writeToNBT(new NBTTagCompound()));
|
||||
ret.setInteger(KEY_AMOUNT, amount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(List<String> existing, boolean detailed) {
|
||||
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid));
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
gui.drawResource(Resource.LBL_FLUID, 0, 0);
|
||||
gui.drawFluid(fluid.getFluid(), 2, 2, 12, 12);
|
||||
}
|
||||
|
||||
public static class Editor extends RegistryEditor.Editor {
|
||||
public Editor() {
|
||||
add(new DText(5, 5, JecGui.Font.DEFAULT_NO_SHADOW, "fluid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
callback.accept(new LabelFluidStack(new FluidStack(FluidRegistry.WATER, 1000), 1000));
|
||||
return super.onClicked(gui, xMouse, yMouse, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,14 @@ import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class LabelItemStack extends LabelSimpleAmount {
|
||||
public static final String IDENTIFIER = "oreDict";
|
||||
public static final String KEY_STACK = "stack";
|
||||
@@ -39,9 +41,9 @@ public class LabelItemStack extends LabelSimpleAmount {
|
||||
amount = eis.amount;
|
||||
itemStack = eis.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(List<String> existing) {
|
||||
public List<String> getToolTip(List<String> existing, boolean detailed) {
|
||||
super.getToolTip(existing, detailed);
|
||||
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(itemStack));
|
||||
return existing;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -54,14 +56,14 @@ public class LabelOreDict extends LabelSimpleAmount {
|
||||
return Utilities.L18n.format("label.ore_dict.name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(List<String> existing) {
|
||||
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
|
||||
return existing;
|
||||
}
|
||||
|
||||
public static RegistryEditor.IEditor getEditor() {
|
||||
return new Editor();
|
||||
public static List<ILabel> guess(List<ItemStack> iss) {
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
for (int i : OreDictionary.getOreIDs(iss.get(0))) ids.add(i);
|
||||
iss.forEach(is -> {
|
||||
for (int i : OreDictionary.getOreIDs(is))
|
||||
if (!ids.contains(i)) ids.remove(i);
|
||||
});
|
||||
return ids.stream().map(i -> new LabelOreDict(OreDictionary.getOreName(i))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,19 +97,22 @@ public class LabelOreDict extends LabelSimpleAmount {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static class Editor extends DContainer implements RegistryEditor.IEditor {
|
||||
Consumer<ILabel> callback;
|
||||
public static RegistryEditor.IEditor getEditor() {
|
||||
return new Editor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(List<String> existing, boolean detailed) {
|
||||
super.getToolTip(existing, detailed);
|
||||
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
|
||||
return existing;
|
||||
}
|
||||
|
||||
public static class Editor extends RegistryEditor.Editor {
|
||||
public Editor() {
|
||||
add(new DText(5, 5, JecGui.Font.DEFAULT_NO_SHADOW, "hello"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryEditor.IEditor setCallback(Consumer<ILabel> callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
callback.accept(new LabelOreDict("plankWood"));
|
||||
|
||||
@@ -3,10 +3,14 @@ package me.towdium.jecalculation.core.labels.labels;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-11.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract class LabelSimpleAmount implements ILabel {
|
||||
protected int amount;
|
||||
|
||||
@@ -40,9 +44,16 @@ public abstract class LabelSimpleAmount implements ILabel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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)));
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAmountString() {
|
||||
return amount == 0 ? "" : Utilities.cutLong(amount, 5);
|
||||
return amount == 0 ? "" : Utilities.cutNumber(amount, 5);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,55 +35,35 @@ public class Utilities {
|
||||
}
|
||||
|
||||
// FLOAT FORMATTING
|
||||
public static String cutFloat(float f, int size) {
|
||||
public static String cutNumber(float f, int size) {
|
||||
BiFunction<Float, Integer, String> form = (fl, len) -> {
|
||||
// here 2 means floating point and unit character
|
||||
// represents for maximum acceptable decimal digits
|
||||
int scale = len - 2 - String.valueOf(fl.intValue()).length();
|
||||
// maximum decimal limits to 2
|
||||
int cut = Math.min(scale, 2);
|
||||
return String.format("%." + (Math.max(cut, 0)) + 'f', fl);
|
||||
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);
|
||||
return ret;
|
||||
};
|
||||
int scale = (int) Math.log10(f) / 3;
|
||||
switch (scale) {
|
||||
case 0:
|
||||
return form.apply(f, size);
|
||||
case 1:
|
||||
return form.apply(f / 1000.0f, size) + 'K';
|
||||
return form.apply(f / 1000.0f, size - 1) + 'K';
|
||||
case 2:
|
||||
return form.apply(f / 1000000.0f, size) + 'M';
|
||||
return form.apply(f / 1000000.0f, size - 1) + 'M';
|
||||
case 3:
|
||||
return form.apply(f / 1000000000.0f, size) + 'B';
|
||||
return form.apply(f / 1000000000.0f, size - 1) + 'B';
|
||||
case 4:
|
||||
return form.apply(f / 1000000000000.0f, size) + 'G';
|
||||
return form.apply(f / 1000000000000.0f, size - 1) + 'G';
|
||||
default:
|
||||
return form.apply(f / 1000000000000000.0f, size) + 'T';
|
||||
return form.apply(f / 1000000000000000.0f, size - 1) + 'T';
|
||||
}
|
||||
}
|
||||
|
||||
public static String cutLong(long i, int size) {
|
||||
if (i < 1000) {
|
||||
return String.valueOf(i);
|
||||
} else {
|
||||
return cutFloat(i, size);
|
||||
}
|
||||
}
|
||||
|
||||
// CIRCULATE STRUCTURE
|
||||
public static int circulate(int current, int total, boolean forward) {
|
||||
if (forward) {
|
||||
if (current == total - 1) return 0;
|
||||
else return current + 1;
|
||||
} else {
|
||||
if (current == 0) return total - 1;
|
||||
else return current - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// MOD NAME
|
||||
public static String getModName(ItemStack stack) {
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
|
||||
JustEnoughCalculation.logger.warn(String.format("item name: %s", name));
|
||||
JustEnoughCalculation.logger.warn(String.format("item name: %s", name)); // "minecraft:stone" or "jecalculation:item.item_calculator"
|
||||
// TODO check
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user