mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 19:49:38 +00:00
feat: label universal
This commit is contained in:
1 parent
82cdf8fbe2
commit
6180605442
15 files changed
+268
-95
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-28.
|
||||
*/
|
||||
public interface IWPicker extends IWidget {
|
||||
IWPicker setCallback(Consumer<ILabel> callback);
|
||||
|
||||
class Simple extends WContainer implements IWPicker {
|
||||
protected Single<Consumer<ILabel>> callback = new Single<>(null);
|
||||
|
||||
@Override
|
||||
public IWPicker setCallback(Consumer<ILabel> callback) {
|
||||
this.callback.value = callback;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,8 @@ public class JecGui extends GuiContainer {
|
||||
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
|
||||
this.parent = parent;
|
||||
this.root = root;
|
||||
if (inventorySlots instanceof JecContainer) ((JecContainer) inventorySlots).setGui(this);
|
||||
if (inventorySlots instanceof JecContainer)
|
||||
((JecContainer) inventorySlots).setGui(this);
|
||||
}
|
||||
|
||||
public static boolean mouseIn(int xPos, int yPos, int xSize, int ySize, int xMouse, int yMouse) {
|
||||
@@ -88,10 +89,14 @@ public class JecGui extends GuiContainer {
|
||||
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IWidget root) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
JecGui parent;
|
||||
if (mc.currentScreen == null) parent = null;
|
||||
else if (!(mc.currentScreen instanceof JecGui)) parent = getCurrent();
|
||||
else if (updateParent) parent = (JecGui) mc.currentScreen;
|
||||
else parent = ((JecGui) mc.currentScreen).parent;
|
||||
if (mc.currentScreen == null)
|
||||
parent = null;
|
||||
else if (!(mc.currentScreen instanceof JecGui))
|
||||
parent = getCurrent();
|
||||
else if (updateParent)
|
||||
parent = (JecGui) mc.currentScreen;
|
||||
else
|
||||
parent = ((JecGui) mc.currentScreen).parent;
|
||||
JecGui toShow = new JecGui(parent, acceptsTransfer, root);
|
||||
mc.displayGuiScreen(toShow);
|
||||
}
|
||||
@@ -131,6 +136,21 @@ public class JecGui extends GuiContainer {
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles events within the interface.
|
||||
* Specifically, handles mouse wheel within interface.
|
||||
* Different from {@link #handleMouseEvent()}, which is
|
||||
* used to handle mouse event outside.
|
||||
*/
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int diff = Mouse.getEventDWheel() / 120;
|
||||
if (diff != 0)
|
||||
root.onScroll(this, Mouse.getEventX() * width / mc.displayWidth - guiLeft,
|
||||
height - Mouse.getEventY() * height / mc.displayHeight - 1 - guiTop, diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the event is canceled
|
||||
* This function handles click outside the normal region,
|
||||
@@ -170,7 +190,11 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void drawResource(Resource r, int xPos, int yPos) {
|
||||
drawTexture(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize());
|
||||
drawResource(r, xPos, yPos, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public void drawResource(Resource r, int xPos, int yPos, int color) {
|
||||
drawTexture(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize(), color);
|
||||
}
|
||||
|
||||
public void drawResourceContinuous(Resource r,
|
||||
@@ -193,7 +217,22 @@ public class JecGui extends GuiContainer {
|
||||
int sourceYPos,
|
||||
int sourceXSize,
|
||||
int sourceYSize) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
drawTexture(l, destXPos, destYPos, sourceXPos, sourceYPos, sourceXSize, sourceYSize, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public void drawTexture(ResourceLocation l,
|
||||
int destXPos,
|
||||
int destYPos,
|
||||
int sourceXPos,
|
||||
int sourceYPos,
|
||||
int sourceXSize,
|
||||
int sourceYSize,
|
||||
int color) {
|
||||
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
float alpha = (~(color >> 24) & 0xFF) / 255.0F;
|
||||
GlStateManager.color(red, green, blue, alpha);
|
||||
mc.getTextureManager().bindTexture(l);
|
||||
drawTexturedModalRect(destXPos, destYPos, sourceXPos, sourceYPos, sourceXSize, sourceYSize);
|
||||
}
|
||||
@@ -383,7 +422,7 @@ public class JecGui extends GuiContainer {
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
if(!inGui) {
|
||||
if (!inGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
@@ -445,6 +484,11 @@ public class JecGui extends GuiContainer {
|
||||
super.drawHoveringText(textLines, x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
public int getXSize() { return xSize; }
|
||||
public int getYSize() { return ySize; }
|
||||
public int getXSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
public int getYSize() {
|
||||
return ySize;
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ public class Resource {
|
||||
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);
|
||||
public static final Resource LBL_UNIV_B = new Resource(32, 56, 16, 16);
|
||||
public static final Resource LBL_UNIV_F = new Resource(48, 56, 16, 16);
|
||||
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected ResourceLocation rl;
|
||||
|
||||
@@ -41,10 +41,14 @@ public class WTextField implements IWidget {
|
||||
@Override
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
boolean ret = textField.textboxKeyTyped(ch, code);
|
||||
if (ret) lsnrText.accept(textField.getText());
|
||||
if (ret && lsnrText != null) lsnrText.accept(textField.getText());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return textField.getText();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public WTextField setLsnrText(Consumer<String> lsnrText) {
|
||||
this.lsnrText = lsnrText;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.drawables.WLabel;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WLabelScroll;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WSearch;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WTextField;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelFluidStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-28.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class GuiEditorFluidStack extends ILabel.RegistryEditor.Editor {
|
||||
public GuiEditorFluidStack() {
|
||||
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true).setLabels(
|
||||
FluidRegistry.getRegisteredFluids().entrySet().stream()
|
||||
.map(e -> new LabelFluidStack(e.getValue(), 1000)).collect(Collectors.toList()));
|
||||
WTextField tf = new WTextField(25, 7, 90);
|
||||
add(new WSearch(l -> callback.value.accept(l), tf, ls));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.towdium.jecalculation.client.gui.guis.pickers;
|
||||
|
||||
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.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-28.
|
||||
*/
|
||||
public class PickerSimple extends IWPicker.Simple {
|
||||
/**
|
||||
* @param labels labels to be displayed for selection
|
||||
* @param l18nKey localization key for help string,
|
||||
* entire key should be "gui.l18nKey.help.tooltip"
|
||||
*/
|
||||
public PickerSimple(List<ILabel> labels, String l18nKey) {
|
||||
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true).setLabels(labels);
|
||||
WTextField tf = new WTextField(25, 7, 90);
|
||||
add(new WSearch(l -> callback.value.accept(l), tf, ls));
|
||||
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, l18nKey + ".help"));
|
||||
}
|
||||
|
||||
public static class FluidStack extends PickerSimple {
|
||||
public FluidStack() {
|
||||
super(FluidRegistry.getRegisteredFluids().entrySet().stream()
|
||||
.map(e -> new LabelFluidStack(e.getValue(), 1000)).collect(Collectors.toList()),
|
||||
"picker_fluid_stack");
|
||||
}
|
||||
}
|
||||
|
||||
public static class OreDict extends PickerSimple {
|
||||
public OreDict() {
|
||||
super(Arrays.stream(OreDictionary.getOreNames()).map(LabelOreDict::new).collect(Collectors.toList()),
|
||||
"picker_ore_dict");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.towdium.jecalculation.client.gui.guis.pickers;
|
||||
|
||||
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.labels.labels.LabelUniversal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-29.
|
||||
*/
|
||||
public class PickerUniversal extends IWPicker.Simple {
|
||||
public PickerUniversal() {
|
||||
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.enumMode.PICKER, true).setLabels(new ArrayList<>());
|
||||
WTextField search = new WTextField(25, 45, 90);
|
||||
WTextField create = new WTextField(25, 7, 70);
|
||||
create.setLsnrText(s -> create.setColor(s.equals("") ? JecGui.COLOR_TEXT_RED : JecGui.COLOR_TEXT_WHITE));
|
||||
add(new WSearch(l -> callback.value.accept(l), search, scroll));
|
||||
add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_universal.help_search"));
|
||||
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_universal.help_create"));
|
||||
add(new WLine(36));
|
||||
add(new WButtonIcon(95, 7, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F).setListenerLeft(() -> {
|
||||
if (!create.getText().equals("")) callback.value.accept(new LabelUniversal(create.getText(), 1));
|
||||
}));
|
||||
add(create);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,24 @@
|
||||
package me.towdium.jecalculation.core.labels;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiEditorFluidStack;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerSimple;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerUniversal;
|
||||
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.core.labels.labels.LabelUniversal;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -223,7 +221,7 @@ public interface ILabel {
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverterFluid extends RegistryConverter<FluidStack> {
|
||||
class RegistryConverterFluid extends RegistryConverter<net.minecraftforge.fluids.FluidStack> {
|
||||
public static final RegistryConverterFluid INSTANCE;
|
||||
|
||||
static {
|
||||
@@ -234,8 +232,8 @@ public interface ILabel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel toLabel(FluidStack ingredient) {
|
||||
return new LabelFluidStack(new FluidStack(ingredient.getFluid(), 1000), ingredient.amount);
|
||||
public ILabel toLabel(net.minecraftforge.fluids.FluidStack ingredient) {
|
||||
return new LabelFluidStack(new net.minecraftforge.fluids.FluidStack(ingredient.getFluid(), 1000), ingredient.amount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,45 +243,35 @@ public interface ILabel {
|
||||
static {
|
||||
INSTANCE = new RegistryEditor();
|
||||
|
||||
INSTANCE.register(LabelOreDict::getEditor, "common.label.ore_dict",
|
||||
INSTANCE.register(PickerSimple.OreDict::new, "common.label.ore_dict",
|
||||
new LabelOreDict("ingotIron"));
|
||||
INSTANCE.register(GuiEditorFluidStack::new, "common.label.fluid_stack",
|
||||
new LabelFluidStack(new FluidStack(FluidRegistry.WATER, 1000), 1000));
|
||||
INSTANCE.register(PickerSimple.FluidStack::new, "common.label.fluid_stack",
|
||||
new LabelFluidStack(FluidRegistry.WATER, 1000));
|
||||
INSTANCE.register(PickerUniversal::new, "common.label.universal",
|
||||
new LabelUniversal("example", 1));
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Record> records = new ArrayList<>();
|
||||
|
||||
private RegistryEditor() {
|
||||
}
|
||||
|
||||
public void register(Supplier<IEditor> editor, String unlocalizedName, ILabel representation) {
|
||||
public void register(Supplier<IWPicker> editor, String unlocalizedName, ILabel representation) {
|
||||
records.add(new Record(editor, unlocalizedName, representation));
|
||||
}
|
||||
|
||||
|
||||
public List<Record> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
public interface IEditor extends IWidget {
|
||||
IEditor setCallback(Consumer<ILabel> callback);
|
||||
}
|
||||
|
||||
public static class Editor extends WContainer implements RegistryEditor.IEditor {
|
||||
protected Single<Consumer<ILabel>> callback = new Single<>(null);
|
||||
|
||||
@Override
|
||||
public RegistryEditor.IEditor setCallback(Consumer<ILabel> callback) {
|
||||
this.callback.value = callback;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Record {
|
||||
public Supplier<IEditor> editor;
|
||||
public Supplier<IWPicker> editor;
|
||||
public String localizeKey;
|
||||
public ILabel representation;
|
||||
|
||||
public Record(Supplier<IEditor> editor, String localizeKey, ILabel representation) {
|
||||
public Record(Supplier<IWPicker> editor, String localizeKey, ILabel representation) {
|
||||
this.editor = editor;
|
||||
this.localizeKey = localizeKey;
|
||||
this.representation = representation;
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.List;
|
||||
public class LabelItemStack extends LabelSimpleAmount {
|
||||
public static final String IDENTIFIER = "oreDict";
|
||||
public static final String KEY_STACK = "stack";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
ItemStack itemStack;
|
||||
|
||||
@@ -28,19 +27,20 @@ public class LabelItemStack extends LabelSimpleAmount {
|
||||
|
||||
// I will copy it!
|
||||
public LabelItemStack(ItemStack is, int amount) {
|
||||
super(amount);
|
||||
itemStack = is.copy();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelItemStack(NBTTagCompound nbt) {
|
||||
super(nbt);
|
||||
itemStack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(KEY_STACK));
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
private LabelItemStack(LabelItemStack eis) {
|
||||
amount = eis.amount;
|
||||
itemStack = eis.itemStack;
|
||||
private LabelItemStack(LabelItemStack lis) {
|
||||
super(lis);
|
||||
itemStack = lis.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(List<String> existing, boolean detailed) {
|
||||
super.getToolTip(existing, detailed);
|
||||
|
||||
@@ -35,18 +35,18 @@ public class LabelOreDict extends LabelSimpleAmount {
|
||||
}
|
||||
|
||||
public LabelOreDict(String name, int amount) {
|
||||
super(amount);
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelOreDict(LabelOreDict eod) {
|
||||
this.name = eod.name;
|
||||
this.amount = eod.amount;
|
||||
public LabelOreDict(LabelOreDict lod) {
|
||||
super(lod);
|
||||
this.name = lod.name;
|
||||
}
|
||||
|
||||
public LabelOreDict(NBTTagCompound nbt) {
|
||||
super(nbt);
|
||||
name = nbt.getString(KEY_NAME);
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,26 +95,10 @@ public class LabelOreDict extends LabelSimpleAmount {
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 WText(5, 5, JecGui.Font.DEFAULT_NO_SHADOW, "hello"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
callback.value.accept(new LabelOreDict("plankWood"));
|
||||
return super.onClicked(gui, xMouse, yMouse, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.core.labels.labels;
|
||||
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
@@ -12,8 +13,22 @@ import java.util.List;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract class LabelSimpleAmount implements ILabel {
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
protected int amount;
|
||||
|
||||
public LabelSimpleAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelSimpleAmount(LabelSimpleAmount lsa) {
|
||||
this(lsa.amount);
|
||||
}
|
||||
|
||||
public LabelSimpleAmount(NBTTagCompound nbt) {
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel increaseAmount() {
|
||||
amount++;
|
||||
@@ -56,4 +71,10 @@ public abstract class LabelSimpleAmount implements ILabel {
|
||||
return amount == 0 ? "" : Utilities.cutNumber(amount, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger(KEY_AMOUNT, amount);
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-28.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class LabelUniversal extends LabelSimpleAmount {
|
||||
public static final String KEY_NAME = "name";
|
||||
|
||||
String name;
|
||||
|
||||
public LabelUniversal(String name, int amount) {
|
||||
super(amount);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LabelUniversal(LabelUniversal lu) {
|
||||
super(lu);
|
||||
name = lu.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return Utilities.L18n.format("label.universal.name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel copy() {
|
||||
return new LabelUniversal(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound nbt = super.toNBTTagCompound();
|
||||
nbt.setString(KEY_NAME, name);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLabel(JecGui gui) {
|
||||
gui.drawResource(Resource.LBL_UNIV_B, 0, 0);
|
||||
gui.drawResource(Resource.LBL_UNIV_F, 0, 0, (name.hashCode() * 0x131723) & 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class Utilities {
|
||||
|
||||
public static String getModName(FluidStack stack) {
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getFluid());
|
||||
JustEnoughCalculation.logger.warn(String.format("fluid name: %s", stack.getFluid()));
|
||||
JustEnoughCalculation.logger.warn(String.format("fluid name: %s", name));
|
||||
// TODO check
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user