Ported the other number entry dialogs over to the shared widget.
This commit is contained in:
@@ -18,48 +18,10 @@
|
||||
|
||||
package appeng.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.widgets.CustomSlotWidget;
|
||||
import appeng.client.gui.widgets.ITickingWidget;
|
||||
import appeng.client.gui.widgets.ITooltip;
|
||||
import appeng.client.gui.widgets.Scrollbar;
|
||||
import appeng.client.me.InternalSlotME;
|
||||
@@ -86,6 +48,43 @@ import appeng.core.sync.packets.SwapSlotsPacket;
|
||||
import appeng.fluids.client.render.FluidStackSizeRenderer;
|
||||
import appeng.fluids.container.slots.IMEFluidSlot;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class AEBaseScreen<T extends AEBaseContainer> extends ContainerScreen<T> {
|
||||
private final List<InternalSlotME> meSlots = new ArrayList<>();
|
||||
@@ -781,4 +780,14 @@ public abstract class AEBaseScreen<T extends AEBaseContainer> extends ContainerS
|
||||
protected List<InternalSlotME> getMeSlots() {
|
||||
return this.meSlots;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
for (IGuiEventListener child : children) {
|
||||
if (child instanceof ITickingWidget) {
|
||||
((ITickingWidget) child).tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package appeng.client.gui;
|
||||
|
||||
public enum NumberEntryType {
|
||||
CRAFT_ITEM_COUNT(Long.class),
|
||||
PRIORITY(Long.class),
|
||||
LEVEL_ITEM_COUNT(Long.class),
|
||||
LEVEL_FLUID_VOLUME(Long.class);
|
||||
|
||||
private final Class<? extends Number> inputType;
|
||||
|
||||
NumberEntryType(Class<? extends Number> inputType) {
|
||||
this.inputType = inputType;
|
||||
}
|
||||
|
||||
public Class<? extends Number> getInputType() {
|
||||
return inputType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,24 +18,21 @@
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.container.implementations.CraftAmountContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.CraftRequestPacket;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.NumberBox;
|
||||
import appeng.container.implementations.CraftAmountContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.CraftRequestPacket;
|
||||
|
||||
public class CraftAmountScreen extends AEBaseScreen<CraftAmountContainer> {
|
||||
private final AESubScreen subGui;
|
||||
|
||||
private NumberBox amountToCraft;
|
||||
private NumberEntryWidget amountToCraft;
|
||||
|
||||
private Button next;
|
||||
|
||||
@@ -48,34 +45,16 @@ public class CraftAmountScreen extends AEBaseScreen<CraftAmountContainer> {
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final int a = AEConfig.instance().craftItemsByStackAmounts(0);
|
||||
final int b = AEConfig.instance().craftItemsByStackAmounts(1);
|
||||
final int c = AEConfig.instance().craftItemsByStackAmounts(2);
|
||||
final int d = AEConfig.instance().craftItemsByStackAmounts(3);
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a, btn -> addQty(a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b, btn -> addQty(b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c, btn -> addQty(c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d, btn -> addQty(d)));
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a, btn -> addQty(-a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b, btn -> addQty(-b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c, btn -> addQty(-c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d, btn -> addQty(-d)));
|
||||
this.amountToCraft = new NumberEntryWidget(this, 20, 30, 138, 62, NumberEntryType.CRAFT_ITEM_COUNT, value -> {});
|
||||
this.amountToCraft.setValue(1);
|
||||
this.amountToCraft.setTextFieldBounds(62, 57, 50);
|
||||
this.amountToCraft.setMinValue(1);
|
||||
this.amountToCraft.addButtons(children::add, this::addButton);
|
||||
|
||||
this.next = this.addButton(
|
||||
new Button(this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal(), this::confirm));
|
||||
|
||||
subGui.addBackButton(this::addButton, 154, 0);
|
||||
|
||||
this.amountToCraft = new NumberBox(this.font, this.guiLeft + 62, this.guiTop + 57, 59, this.font.FONT_HEIGHT,
|
||||
Integer.class, value -> {});
|
||||
this.amountToCraft.setEnableBackgroundDrawing(false);
|
||||
this.amountToCraft.setMaxStringLength(16);
|
||||
this.amountToCraft.setTextColor(0xFFFFFF);
|
||||
this.amountToCraft.setVisible(true);
|
||||
this.amountToCraft.setFocused2(true);
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
|
||||
private void confirm(Button button) {
|
||||
@@ -95,99 +74,23 @@ public class CraftAmountScreen extends AEBaseScreen<CraftAmountContainer> {
|
||||
this.bindTexture("guis/craft_amt.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
|
||||
try {
|
||||
Long.parseLong(this.amountToCraft.getText());
|
||||
this.next.active = !this.amountToCraft.getText().isEmpty();
|
||||
} catch (final NumberFormatException e) {
|
||||
this.next.active = false;
|
||||
}
|
||||
this.next.active = this.amountToCraft.getValue() > 0;
|
||||
|
||||
this.amountToCraft.render(offsetX, offsetY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char ch, int p_charTyped_2_) {
|
||||
// Forward entered text to the craft amount text-field
|
||||
return this.amountToCraft.charTyped(ch, p_charTyped_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
if (!this.checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode))) {
|
||||
if (keyCode == 28) {
|
||||
this.next.onPress();
|
||||
}
|
||||
if ((keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14)
|
||||
&& this.amountToCraft.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
final long result = Long.parseLong(out);
|
||||
if (result < 0) {
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
|
||||
private void addQty(final int i) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
long result = Integer.parseInt(out);
|
||||
|
||||
if (result == 1 && i > 1) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
result += i;
|
||||
if (result < 1) {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
out = Long.toString(result);
|
||||
Integer.parseInt(out);
|
||||
this.amountToCraft.setText(out);
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
if (keyCode == 28) {
|
||||
this.next.onPress();
|
||||
return true;
|
||||
} else {
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "guis/craftAmt.png";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,21 +18,21 @@
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.LevelType;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.client.gui.widgets.ServerSettingToggleButton;
|
||||
import appeng.client.gui.widgets.SettingToggleButton;
|
||||
import appeng.container.implementations.LevelEmitterContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class LevelEmitterScreen extends UpgradeableScreen<LevelEmitterContainer> {
|
||||
|
||||
@@ -48,7 +48,8 @@ public class LevelEmitterScreen extends UpgradeableScreen<LevelEmitterContainer>
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 79, this::onLevelChange);
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_ITEM_COUNT, this::onLevelChange);
|
||||
this.level.setTextFieldBounds(25, 44, 79);
|
||||
this.level.addButtons(children::add, this::addButton);
|
||||
container.setTextField(this.level);
|
||||
}
|
||||
@@ -114,14 +115,4 @@ public class LevelEmitterScreen extends UpgradeableScreen<LevelEmitterContainer>
|
||||
return GuiText.LevelEmitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int key) {
|
||||
return super.charTyped(character, key);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.level.tick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.client.gui.widgets.ITickingWidget;
|
||||
import appeng.client.gui.widgets.NumberBox;
|
||||
import appeng.core.AEConfig;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -14,7 +16,7 @@ import java.util.function.LongConsumer;
|
||||
* A utility widget that consists of a text-field to enter a number with attached buttons to
|
||||
* increment/decrement the number in fixed intervals.
|
||||
*/
|
||||
public class NumberEntryWidget {
|
||||
public class NumberEntryWidget implements ITickingWidget {
|
||||
|
||||
private final AEBaseScreen<?> parent;
|
||||
|
||||
@@ -22,6 +24,7 @@ public class NumberEntryWidget {
|
||||
private final int y;
|
||||
|
||||
private final NumberBox level;
|
||||
private final NumberEntryType type;
|
||||
private Button plus1;
|
||||
private Button plus10;
|
||||
private Button plus100;
|
||||
@@ -31,14 +34,18 @@ public class NumberEntryWidget {
|
||||
private Button minus100;
|
||||
private Button minus1000;
|
||||
|
||||
public NumberEntryWidget(AEBaseScreen<?> parent, int x, int y, int width, LongConsumer changeListener) {
|
||||
public NumberEntryWidget(AEBaseScreen<?> parent, int x, int y, int width, int height,
|
||||
NumberEntryType type,
|
||||
LongConsumer changeListener) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.type = type;
|
||||
|
||||
FontRenderer font = parent.getMinecraft().fontRenderer;
|
||||
this.level = new NumberBox(font, parent.getGuiLeft() + x + 5, parent.getGuiTop() + y + 27, width, font.FONT_HEIGHT,
|
||||
Long.class, changeListener);
|
||||
int inputX = parent.getGuiLeft() + x;
|
||||
int inputY = parent.getGuiTop() + y;
|
||||
this.level = new NumberBox(font, inputX, inputY, width, font.FONT_HEIGHT, type.getInputType(), changeListener);
|
||||
this.level.setEnableBackgroundDrawing(false);
|
||||
this.level.setMaxStringLength(16);
|
||||
this.level.setTextColor(0xFFFFFF);
|
||||
@@ -59,11 +66,22 @@ public class NumberEntryWidget {
|
||||
this.minus1000.active = active;
|
||||
}
|
||||
|
||||
public void setTextFieldBounds(int x, int y, int width) {
|
||||
this.level.x = parent.getGuiLeft() + x;
|
||||
this.level.y = parent.getGuiTop() + y;
|
||||
this.level.setWidth(width);
|
||||
}
|
||||
|
||||
public void setMinValue(long minValue) {
|
||||
this.level.setMinValue(minValue);
|
||||
}
|
||||
|
||||
public void addButtons(Consumer<IGuiEventListener> addChildren, Consumer<Button> addButton) {
|
||||
final int a = AEConfig.instance().levelByStackAmounts(0);
|
||||
final int b = AEConfig.instance().levelByStackAmounts(1);
|
||||
final int c = AEConfig.instance().levelByStackAmounts(2);
|
||||
final int d = AEConfig.instance().levelByStackAmounts(3);
|
||||
final int[] steps = AEConfig.instance().getNumberEntrySteps(type);
|
||||
int a = steps[0];
|
||||
int b = steps[1];
|
||||
int c = steps[2];
|
||||
int d = steps[3];
|
||||
|
||||
int left = parent.getGuiLeft() + x;
|
||||
int top = parent.getGuiTop() + y;
|
||||
@@ -91,21 +109,29 @@ public class NumberEntryWidget {
|
||||
|
||||
private void addQty(final long i) {
|
||||
long currentValue = this.level.getValue();
|
||||
this.level.setText(String.valueOf(Math.max(0, currentValue + i)));
|
||||
long minValue = this.level.getMinValue();
|
||||
this.level.setText(String.valueOf(Math.max(minValue, currentValue + i)));
|
||||
}
|
||||
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
this.level.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
public void setValue(long value) {
|
||||
// This check avoid changing the cursor position needlessly
|
||||
if (value != this.level.getValue()) {
|
||||
this.level.setText(String.valueOf(value));
|
||||
}
|
||||
public void setValue(long value, boolean skipNotify) {
|
||||
this.level.setValue(value, skipNotify);
|
||||
}
|
||||
|
||||
public void setValue(long value) {
|
||||
setValue(value, false);
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
return level.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.level.tick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,24 +18,20 @@
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.NumberBox;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.container.implementations.PriorityContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class PriorityScreen extends AEBaseScreen<PriorityContainer> {
|
||||
|
||||
private final AESubScreen subGui;
|
||||
|
||||
private NumberBox priority;
|
||||
private NumberEntryWidget priority;
|
||||
|
||||
public PriorityScreen(PriorityContainer container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
@@ -46,31 +42,17 @@ public class PriorityScreen extends AEBaseScreen<PriorityContainer> {
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final int a = AEConfig.instance().priorityByStacksAmounts(0);
|
||||
final int b = AEConfig.instance().priorityByStacksAmounts(1);
|
||||
final int c = AEConfig.instance().priorityByStacksAmounts(2);
|
||||
final int d = AEConfig.instance().priorityByStacksAmounts(3);
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a, btn -> addQty(a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b, btn -> addQty(b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c, btn -> addQty(c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d, btn -> addQty(d)));
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a, btn -> addQty(-a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b, btn -> addQty(-b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c, btn -> addQty(-c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d, btn -> addQty(-d)));
|
||||
this.priority = new NumberEntryWidget(this, 20, 30, 138, 62, NumberEntryType.PRIORITY, this::onPriorityChange);
|
||||
this.priority.setTextFieldBounds(62, 57, 50);
|
||||
this.priority.setMinValue(Integer.MIN_VALUE);
|
||||
container.setTextField(this.priority);
|
||||
this.priority.addButtons(children::add, this::addButton);
|
||||
|
||||
this.subGui.addBackButton(this::addButton, 154, 0);
|
||||
}
|
||||
|
||||
this.priority = new NumberBox(this.font, this.guiLeft + 62, this.guiTop + 57, 59, this.font.FONT_HEIGHT,
|
||||
Long.class, value -> NetworkHandler.instance().sendToServer(new ConfigValuePacket("PriorityHost.Priority", String.valueOf(value))));
|
||||
this.priority.setEnableBackgroundDrawing(false);
|
||||
this.priority.setMaxStringLength(16);
|
||||
this.priority.setTextColor(0xFFFFFF);
|
||||
this.priority.setVisible(true);
|
||||
this.priority.setFocused2(true);
|
||||
container.setTextField(this.priority);
|
||||
private void onPriorityChange(long priority) {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("PriorityHost.Priority", String.valueOf(priority)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,90 +68,6 @@ public class PriorityScreen extends AEBaseScreen<PriorityContainer> {
|
||||
this.priority.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
private void addQty(final int i) {
|
||||
try {
|
||||
String out = this.priority.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.priority.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
long result = Long.parseLong(out);
|
||||
result += i;
|
||||
|
||||
this.priority.setText(out = Long.toString(result));
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("PriorityHost.Priority", out));
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
this.priority.setText("0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int key) {
|
||||
if (priority.charTyped(character, key)) {
|
||||
String out = this.priority.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.priority.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("PriorityHost.Priority", out));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
if (!this.checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode))) {
|
||||
if ((keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14)
|
||||
&& this.priority.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
|
||||
String out = this.priority.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.priority.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("PriorityHost.Priority", out));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "guis/priority.png";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package appeng.client.gui.widgets;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
/**
|
||||
* Indicates that a widget (anything that is in the {@link Screen#children()} list) should receive callbacks every
|
||||
* tick.
|
||||
*/
|
||||
public interface ITickingWidget {
|
||||
|
||||
void tick();
|
||||
|
||||
}
|
||||
@@ -22,36 +22,50 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
|
||||
import java.util.function.LongConsumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class NumberBox extends TextFieldWidget {
|
||||
|
||||
private final Class<?> type;
|
||||
|
||||
private final LongConsumer changeListener;
|
||||
|
||||
private long lastValue;
|
||||
|
||||
private long minValue = 0;
|
||||
|
||||
private long maxValue;
|
||||
|
||||
public NumberBox(final FontRenderer fontRenderer, final int x, final int y, final int width, final int height,
|
||||
final Class<?> type, LongConsumer changeListener) {
|
||||
super(fontRenderer, x, y, width, height, "0");
|
||||
this.type = type;
|
||||
this.setText("0");
|
||||
setResponder(this::onTextChanged);
|
||||
this.lastValue = 0;
|
||||
this.changeListener = changeListener;
|
||||
if (type == int.class || type == Integer.class) {
|
||||
maxValue = Integer.MAX_VALUE;
|
||||
} else {
|
||||
maxValue = Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
private void onTextChanged(String text) {
|
||||
if (text.isEmpty() || !isValidNumber()) {
|
||||
if (text.isEmpty()) {
|
||||
setText("0"); // Will call onTextChanged recursively
|
||||
return;
|
||||
}
|
||||
|
||||
boolean canBeNegative = canBeNegative();
|
||||
if (canBeNegative && text.equals("-")) {
|
||||
// Allow this as a special case to make typing in a negative number easier
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sanitized = new StringBuilder(text);
|
||||
boolean encounteredNonZero = false;
|
||||
for (int i = 0; i < sanitized.length(); i++) {
|
||||
char ch = sanitized.charAt(i);
|
||||
if (canBeNegative && i == 0 && ch == '-') {
|
||||
continue; // Allow leading minus sign
|
||||
}
|
||||
if (ch >= '1' && ch <= '9') {
|
||||
encounteredNonZero = true;
|
||||
continue;
|
||||
@@ -68,6 +82,14 @@ public class NumberBox extends TextFieldWidget {
|
||||
setText(sanitizedStr); // Will call onTextChanged recursively
|
||||
return;
|
||||
}
|
||||
if (getValue() < minValue) {
|
||||
setText(String.valueOf(minValue)); // Will call onTextChanged recursively
|
||||
return;
|
||||
}
|
||||
if (getValue() > maxValue) {
|
||||
setText(String.valueOf(maxValue)); // Will call onTextChanged recursively
|
||||
return;
|
||||
}
|
||||
|
||||
reportChange();
|
||||
}
|
||||
@@ -80,20 +102,23 @@ public class NumberBox extends TextFieldWidget {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidNumber() {
|
||||
try {
|
||||
if (this.type == int.class || this.type == Integer.class) {
|
||||
Integer.parseInt(this.getText());
|
||||
} else if (this.type == long.class || this.type == Long.class) {
|
||||
Long.parseLong(this.getText());
|
||||
}
|
||||
return true;
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
public void setValue(long value, boolean skipNotify) {
|
||||
// This check avoid changing the cursor position needlessly
|
||||
if (value == this.getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skipNotify) {
|
||||
lastValue = value;
|
||||
}
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
if (getText().equals("-") && canBeNegative()) {
|
||||
return lastValue; // Allow this as a special case to type in a negative number more easily
|
||||
}
|
||||
|
||||
return Long.parseLong(getText());
|
||||
}
|
||||
|
||||
@@ -106,4 +131,17 @@ public class NumberBox extends TextFieldWidget {
|
||||
// Swallow key presses for numbers because they would otherwise trigger the hotbar swapping unintentionally
|
||||
return isFocused() && p_keyPressed_1_ >= '0' && p_keyPressed_1_ <= '9';
|
||||
}
|
||||
|
||||
public void setMinValue(long minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
private boolean canBeNegative() {
|
||||
return minValue < 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,14 @@
|
||||
|
||||
package appeng.container.implementations;
|
||||
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.client.gui.implementations.NumberEntryWidget;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -27,14 +34,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PriorityContainer extends AEBaseContainer {
|
||||
|
||||
public static ContainerType<PriorityContainer> TYPE;
|
||||
@@ -53,7 +52,8 @@ public class PriorityContainer extends AEBaseContainer {
|
||||
private final IPriorityHost priHost;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private TextFieldWidget textField;
|
||||
private NumberEntryWidget textField;
|
||||
|
||||
@GuiSync(2)
|
||||
public long PriorityValue = -1;
|
||||
|
||||
@@ -64,9 +64,9 @@ public class PriorityContainer extends AEBaseContainer {
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void setTextField(final TextFieldWidget level) {
|
||||
public void setTextField(final NumberEntryWidget level) {
|
||||
this.textField = level;
|
||||
this.textField.setText(String.valueOf(this.PriorityValue));
|
||||
this.textField.setValue(this.PriorityValue, true);
|
||||
}
|
||||
|
||||
public void setPriority(final int newValue, final PlayerEntity player) {
|
||||
@@ -88,7 +88,7 @@ public class PriorityContainer extends AEBaseContainer {
|
||||
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
|
||||
if (field.equals("PriorityValue")) {
|
||||
if (this.textField != null) {
|
||||
this.textField.setText(String.valueOf(this.PriorityValue));
|
||||
this.textField.setValue(this.PriorityValue, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,29 @@
|
||||
|
||||
package appeng.core;
|
||||
|
||||
import appeng.api.config.CondenserOutput;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.SearchBoxMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.TerminalStyle;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.util.EnumCycler;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.EnumValue;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -31,31 +54,6 @@ import java.util.Set;
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.EnumValue;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
|
||||
import appeng.api.config.CondenserOutput;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.SearchBoxMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.TerminalStyle;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.util.EnumCycler;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AppEng.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class AEConfig {
|
||||
|
||||
@@ -273,20 +271,23 @@ public final class AEConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public int craftItemsByStackAmounts(final int i) {
|
||||
return this.craftByStacks[i];
|
||||
}
|
||||
|
||||
public int priorityByStacksAmounts(final int i) {
|
||||
return this.priorityByStacks[i];
|
||||
}
|
||||
|
||||
public int levelByStackAmounts(final int i) {
|
||||
return this.levelByStacks[i];
|
||||
}
|
||||
|
||||
public int levelByMillyBuckets(final int i) {
|
||||
return this.levelByMillibuckets[i];
|
||||
/**
|
||||
* Returns an array with the quantity-steps for the +/- buttons in number entry dialogs of the given type.
|
||||
* Guaranteed to have 4 entries.
|
||||
*/
|
||||
public int[] getNumberEntrySteps(NumberEntryType type) {
|
||||
switch (type) {
|
||||
case CRAFT_ITEM_COUNT:
|
||||
return craftByStacks;
|
||||
case PRIORITY:
|
||||
return priorityByStacks;
|
||||
case LEVEL_ITEM_COUNT:
|
||||
return levelByStacks;
|
||||
case LEVEL_FLUID_VOLUME:
|
||||
return levelByMillibuckets;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown number entry: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public PowerUnits getSelectedPowerUnit() {
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
|
||||
package appeng.fluids.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.NumberEntryType;
|
||||
import appeng.client.gui.implementations.NumberEntryWidget;
|
||||
import appeng.client.gui.implementations.UpgradeableScreen;
|
||||
import appeng.client.gui.widgets.NumberBox;
|
||||
import appeng.client.gui.widgets.ServerSettingToggleButton;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
|
||||
import appeng.fluids.container.FluidLevelEmitterContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitterContainer> {
|
||||
private NumberBox level;
|
||||
|
||||
private NumberEntryWidget level;
|
||||
|
||||
public FluidLevelEmitterScreen(FluidLevelEmitterContainer container, PlayerInventory playerInventory,
|
||||
ITextComponent title) {
|
||||
@@ -30,14 +28,10 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.level = new NumberBox(this.font, this.guiLeft + 24, this.guiTop + 43, 79, this.font.FONT_HEIGHT,
|
||||
Long.class, value -> NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", String.valueOf(value))));
|
||||
this.level.setEnableBackgroundDrawing(false);
|
||||
this.level.setMaxStringLength(16);
|
||||
this.level.setTextColor(0xFFFFFF);
|
||||
this.level.setVisible(true);
|
||||
this.level.changeFocus(true);
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_FLUID_VOLUME, this::onLevelChange);
|
||||
this.level.setTextFieldBounds(25, 44, 79);
|
||||
container.setTextField(this.level);
|
||||
this.level.addButtons(children::add, this::addButton);
|
||||
|
||||
final int y = 40;
|
||||
final int x = 80 + 44;
|
||||
@@ -48,22 +42,6 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
protected void addButtons() {
|
||||
this.redstoneMode = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 28,
|
||||
Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL);
|
||||
|
||||
final int a = AEConfig.instance().levelByMillyBuckets(0);
|
||||
final int b = AEConfig.instance().levelByMillyBuckets(1);
|
||||
final int c = AEConfig.instance().levelByMillyBuckets(2);
|
||||
final int d = AEConfig.instance().levelByMillyBuckets(3);
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a, btn -> addQty(a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b, btn -> addQty(b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c, btn -> addQty(c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d, btn -> addQty(d)));
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a, btn -> addQty(-a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b, btn -> addQty(-b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c, btn -> addQty(-c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d, btn -> addQty(-d)));
|
||||
|
||||
this.addButton(this.redstoneMode);
|
||||
}
|
||||
|
||||
@@ -92,89 +70,8 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
protected void handleButtonVisibility() {
|
||||
}
|
||||
|
||||
private void addQty(final long i) {
|
||||
try {
|
||||
String Out = this.level.getText();
|
||||
|
||||
boolean Fixed = false;
|
||||
while (Out.startsWith("0") && Out.length() > 1) {
|
||||
Out = Out.substring(1);
|
||||
Fixed = true;
|
||||
}
|
||||
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
long result = Long.parseLong(Out);
|
||||
result += i;
|
||||
if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
this.level.setText(Out = Long.toString(result));
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
this.level.setText("0");
|
||||
}
|
||||
private void onLevelChange(long level) {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", String.valueOf(level)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int keyCode) {
|
||||
if (level.charTyped(character, keyCode)) {
|
||||
String Out = this.level.getText();
|
||||
|
||||
boolean Fixed = false;
|
||||
while (Out.startsWith("0") && Out.length() > 1) {
|
||||
Out = Out.substring(1);
|
||||
Fixed = true;
|
||||
}
|
||||
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
|
||||
return true;
|
||||
}
|
||||
return super.charTyped(character, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
if (!this.checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode))) {
|
||||
if ((keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14)
|
||||
&& this.level.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
|
||||
String Out = this.level.getText();
|
||||
|
||||
boolean Fixed = false;
|
||||
while (Out.startsWith("0") && Out.length() > 1) {
|
||||
Out = Out.substring(1);
|
||||
Fixed = true;
|
||||
}
|
||||
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package appeng.fluids.container;
|
||||
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.implementations.NumberEntryWidget;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import appeng.fluids.parts.FluidLevelEmitterPart;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
public static ContainerType<FluidLevelEmitterContainer> TYPE;
|
||||
@@ -35,7 +34,7 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
private final FluidLevelEmitterPart lvlEmitter;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private TextFieldWidget textField;
|
||||
private NumberEntryWidget textField;
|
||||
@GuiSync(3)
|
||||
public long EmitterValue = -1;
|
||||
|
||||
@@ -45,9 +44,9 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void setTextField(final TextFieldWidget level) {
|
||||
public void setTextField(final NumberEntryWidget level) {
|
||||
this.textField = level;
|
||||
this.textField.setText(String.valueOf(this.EmitterValue));
|
||||
this.textField.setValue(this.EmitterValue);
|
||||
}
|
||||
|
||||
public void setLevel(final long l, final PlayerEntity player) {
|
||||
@@ -87,7 +86,7 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
|
||||
if (field.equals("EmitterValue")) {
|
||||
if (this.textField != null) {
|
||||
this.textField.setText(String.valueOf(this.EmitterValue));
|
||||
this.textField.setValue(this.EmitterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user