diff --git a/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java b/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java index e571e3c4e..8917516bf 100644 --- a/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java +++ b/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java @@ -27,6 +27,7 @@ import javax.annotation.Nonnull; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; +import appeng.api.networking.IGrid; /** * Used to access information about AE's various power accepting blocks for @@ -78,6 +79,10 @@ public interface IAEPowerStorage extends IEnergySource { * A higher value means it is more likely to be extracted from first, and less * likely to be inserted into first. * + * The value needs to be constant once added to a {@link IGrid}. Should it ever + * need to be changed, it has to be removed from the grid, then update the + * value, and finally added back to the grid. + * * This should never use {@link Integer#MIN_VALUE} or {@link Integer#MAX_VALUE}. * * @return the priority for this storage diff --git a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java b/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java index 0abcd27ab..1a800c5d6 100644 --- a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java +++ b/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java @@ -23,10 +23,13 @@ import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.StateManager; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; +import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import appeng.block.AEBaseTileBlock; @@ -54,6 +57,16 @@ public abstract class AbstractCraftingUnitBlock e builder.add(FORMED); } + @Override + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, + BlockPos currentPos, BlockPos facingPos) { + TileEntity te = worldIn.getTileEntity(currentPos); + if (te != null) { + te.requestModelDataUpdate(); + } + return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + @Override public void neighborUpdate(final BlockState state, final World worldIn, final BlockPos pos, final Block blockIn, final BlockPos fromPos, boolean isMoving) { diff --git a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java b/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java index 31f04e3ab..d675b20f9 100644 --- a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java +++ b/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java @@ -43,9 +43,9 @@ class QnbFormedBakedModel implements BakedModel, FabricBakedModel { private static final SpriteIdentifier TEXTURE_RING_LIGHT_CORNER = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier(AppEng.MOD_ID, "block/quantum_ring_light_corner")); private static final SpriteIdentifier TEXTURE_CABLE_GLASS = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, - new Identifier(AppEng.MOD_ID, "parts/cable/glass/transparent")); + new Identifier(AppEng.MOD_ID, "part/cable/glass/transparent")); private static final SpriteIdentifier TEXTURE_COVERED_CABLE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, - new Identifier(AppEng.MOD_ID, "parts/cable/covered/transparent")); + new Identifier(AppEng.MOD_ID, "part/cable/covered/transparent")); private static final float DEFAULT_RENDER_MIN = 2.0f; private static final float DEFAULT_RENDER_MAX = 14.0f; diff --git a/src/main/java/appeng/client/gui/AEBaseScreen.java b/src/main/java/appeng/client/gui/AEBaseScreen.java index f7b6c6e25..85d3cc858 100644 --- a/src/main/java/appeng/client/gui/AEBaseScreen.java +++ b/src/main/java/appeng/client/gui/AEBaseScreen.java @@ -58,6 +58,7 @@ import net.minecraft.text.Text; 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 +87,8 @@ import appeng.fluids.container.slots.IMEFluidSlot; import appeng.helpers.InventoryAction; public abstract class AEBaseScreen extends HandledScreen { + + public static final int COLOR_DARK_GRAY = 4210752; private final List meSlots = new ArrayList<>(); // drag y private final Set drag_click = new HashSet<>(); @@ -186,7 +189,7 @@ public abstract class AEBaseScreen extends HandledScr } final Text msg = tooltip.getMessage(); - if (msg != null) { + if (msg != null && !msg.isEmpty()) { this.drawTooltip(matrices, x + 11, y + 4, msg); } } @@ -780,4 +783,14 @@ public abstract class AEBaseScreen extends HandledScr protected List getMeSlots() { return this.meSlots; } + + public void tick() { + super.tick(); + for (IGuiEventListener child : children) { + if (child instanceof ITickingWidget) { + ((ITickingWidget) child).tick(); + } + } + } + } diff --git a/src/main/java/appeng/client/gui/NumberEntryType.java b/src/main/java/appeng/client/gui/NumberEntryType.java new file mode 100644 index 000000000..10b079b5e --- /dev/null +++ b/src/main/java/appeng/client/gui/NumberEntryType.java @@ -0,0 +1,16 @@ +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 inputType; + + NumberEntryType(Class inputType) { + this.inputType = inputType; + } + + public Class getInputType() { + return inputType; + } + +} diff --git a/src/main/java/appeng/client/gui/implementations/CraftAmountScreen.java b/src/main/java/appeng/client/gui/implementations/CraftAmountScreen.java index e86e0af61..dd1d95246 100644 --- a/src/main/java/appeng/client/gui/implementations/CraftAmountScreen.java +++ b/src/main/java/appeng/client/gui/implementations/CraftAmountScreen.java @@ -20,15 +20,15 @@ package appeng.client.gui.implementations; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.widget.button.Button; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import appeng.client.gui.AEBaseScreen; -import appeng.client.gui.widgets.NumberBox; +import appeng.client.gui.NumberEntryType; 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; @@ -36,7 +36,7 @@ import appeng.core.sync.packets.CraftRequestPacket; public class CraftAmountScreen extends AEBaseScreen { private final AESubScreen subGui; - private NumberBox amountToCraft; + private NumberEntryWidget amountToCraft; private ButtonWidget next; @@ -49,39 +49,22 @@ public class CraftAmountScreen extends AEBaseScreen { 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 ButtonWidget(this.x + 20, this.y + 26, 22, 20, new LiteralText("+" + a), btn -> addQty(a))); - this.addButton(new ButtonWidget(this.x + 48, this.y + 26, 28, 20, new LiteralText("+" + b), btn -> addQty(b))); - this.addButton(new ButtonWidget(this.x + 82, this.y + 26, 32, 20, new LiteralText("+" + c), btn -> addQty(c))); - this.addButton(new ButtonWidget(this.x + 120, this.y + 26, 38, 20, new LiteralText("+" + d), btn -> addQty(d))); - - this.addButton(new ButtonWidget(this.x + 20, this.y + 75, 22, 20, new LiteralText("-" + a), btn -> addQty(-a))); - this.addButton(new ButtonWidget(this.x + 48, this.y + 75, 28, 20, new LiteralText("-" + b), btn -> addQty(-b))); - this.addButton(new ButtonWidget(this.x + 82, this.y + 75, 32, 20, new LiteralText("-" + c), btn -> addQty(-c))); - this.addButton(new ButtonWidget(this.x + 120, this.y + 75, 38, 20, new LiteralText("-" + 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 ButtonWidget(this.x + 128, this.y + 51, 38, 20, GuiText.Next.text(), this::confirm)); subGui.addBackButton(this::addButton, 154, 0); - - this.amountToCraft = new NumberBox(this.textRenderer, this.x + 62, this.y + 57, 59, this.textRenderer.fontHeight, - Integer.class); - this.amountToCraft.setHasBorder(false); - this.amountToCraft.setMaxLength(16); - this.amountToCraft.setEditableColor(0xFFFFFF); - this.amountToCraft.setVisible(true); - this.amountToCraft.setFocused(true); - this.amountToCraft.setText("1"); } private void confirm(ButtonWidget button) { NetworkHandler.instance() - .sendToServer(new CraftRequestPacket(Integer.parseInt(this.amountToCraft.getText()), hasShiftDown())); + .sendToServer(new CraftRequestPacket((int) this.amountToCraft.getValue(), hasShiftDown())); } @Override @@ -96,99 +79,23 @@ public class CraftAmountScreen extends AEBaseScreen { this.bindTexture("guis/craft_amt.png"); drawTexture(matrices, offsetX, offsetY, 0, 0, this.backgroundWidth, this.backgroundHeight); - 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(matrices, 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(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"; } + } diff --git a/src/main/java/appeng/client/gui/implementations/LevelEmitterScreen.java b/src/main/java/appeng/client/gui/implementations/LevelEmitterScreen.java index cf1a117f5..33688879e 100644 --- a/src/main/java/appeng/client/gui/implementations/LevelEmitterScreen.java +++ b/src/main/java/appeng/client/gui/implementations/LevelEmitterScreen.java @@ -26,32 +26,22 @@ import net.minecraft.text.Text; import appeng.api.config.FuzzyMode; import appeng.api.config.LevelType; +import appeng.api.config.PowerUnits; import appeng.api.config.RedstoneMode; import appeng.api.config.Settings; import appeng.api.config.Upgrades; import appeng.api.config.YesNo; -import appeng.client.gui.widgets.NumberBox; +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.AEConfig; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; public class LevelEmitterScreen extends UpgradeableScreen { - private NumberBox level; - - private ButtonWidget plus1; - private ButtonWidget plus10; - private ButtonWidget plus100; - private ButtonWidget plus1000; - private ButtonWidget minus1; - private ButtonWidget minus10; - private ButtonWidget minus100; - private ButtonWidget minus1000; - + private NumberEntryWidget level; private SettingToggleButton levelMode; private SettingToggleButton craftingMode; @@ -63,14 +53,15 @@ public class LevelEmitterScreen extends UpgradeableScreen public void init() { super.init(); - this.level = new NumberBox(this.textRenderer, this.x + 24, this.y + 43, 79, this.textRenderer.fontHeight, - Long.class); - this.level.setHasBorder(false); - this.level.setMaxLength(16); - this.level.setEditableColor(0xFFFFFF); - this.level.setVisible(true); - this.level.setFocused(true); - handler.setTextField(this.level); + this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_ITEM_COUNT, + this::onLevelChange); + this.level.setTextFieldBounds(25, 44, 75); + this.level.addButtons(children::add, this::addButton); + container.setTextField(this.level); + } + + private void onLevelChange(long level) { + NetworkHandler.instance().sendToServer(new ConfigValuePacket("LevelEmitter.Value", String.valueOf(level))); } @Override @@ -83,29 +74,6 @@ public class LevelEmitterScreen extends UpgradeableScreen FuzzyMode.IGNORE_ALL); this.craftingMode = new ServerSettingToggleButton<>(this.x - 18, this.y + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO); - - 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); - - this.addButton(this.plus1 = new ButtonWidget(this.x + 20, this.y + 17, 22, 20, new LiteralText("+" + a), btn -> addQty(a))); - this.addButton( - this.plus10 = new ButtonWidget(this.x + 48, this.y + 17, 28, 20, new LiteralText("+" + b), btn -> addQty(b))); - this.addButton( - this.plus100 = new ButtonWidget(this.x + 82, this.y + 17, 32, 20, new LiteralText("+" + c), btn -> addQty(c))); - this.addButton( - this.plus1000 = new ButtonWidget(this.x + 120, this.y + 17, 38, 20, new LiteralText("+" + d), btn -> addQty(d))); - - this.addButton( - this.minus1 = new ButtonWidget(this.x + 20, this.y + 59, 22, 20, new LiteralText("-" + a), btn -> addQty(-a))); - this.addButton( - this.minus10 = new ButtonWidget(this.x + 48, this.y + 59, 28, 20, new LiteralText("-" + b), btn -> addQty(-b))); - this.addButton( - this.minus100 = new ButtonWidget(this.x + 82, this.y + 59, 32, 20, new LiteralText("-" + c), btn -> addQty(-c))); - this.addButton( - this.minus1000 = new ButtonWidget(this.x + 120, this.y + 59, 38, 20, new LiteralText("-" + d), btn -> addQty(-d))); - this.addButton(this.levelMode); this.addButton(this.redstoneMode); this.addButton(this.craftingMode); @@ -116,15 +84,7 @@ public class LevelEmitterScreen extends UpgradeableScreen final boolean notCraftingMode = this.bc.getInstalledUpgrades(Upgrades.CRAFTING) == 0; // configure enabled status... - this.level.active = notCraftingMode; - this.plus1.active = notCraftingMode; - this.plus10.active = notCraftingMode; - this.plus100.active = notCraftingMode; - this.plus1000.active = notCraftingMode; - this.minus1.active = notCraftingMode; - this.minus10.active = notCraftingMode; - this.minus100.active = notCraftingMode; - this.minus1000.active = notCraftingMode; + this.level.setActive(notCraftingMode); this.levelMode.active = notCraftingMode; this.redstoneMode.active = notCraftingMode; @@ -135,7 +95,14 @@ public class LevelEmitterScreen extends UpgradeableScreen } if (this.levelMode != null) { - this.levelMode.set(((LevelEmitterContainer) this.cvb).getLevelMode()); + LevelType currentLevelMode = ((LevelEmitterContainer) this.cvb).getLevelMode(); + this.levelMode.set(currentLevelMode); + + if (notCraftingMode) { + if (currentLevelMode == LevelType.ENERGY_LEVEL) { + this.font.drawString(PowerUnits.AE.textComponent().getString(), 110, 44, COLOR_DARK_GRAY); + } + } } } @@ -161,70 +128,4 @@ public class LevelEmitterScreen extends UpgradeableScreen return GuiText.LevelEmitter; } - 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("LevelEmitter.Value", Out)); - } catch (final NumberFormatException e) { - // nope.. - this.level.setText("0"); - } - } - - @Override - public boolean charTyped(char character, int key) { - // Forward entered characters to the number-text-field - return level.charTyped(character, key); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { - if (!this.checkHotbarKeys(keyCode, scanCode)) { - if (keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14) { - 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("LevelEmitter.Value", Out)); - return true; - } - } - - return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); - } } diff --git a/src/main/java/appeng/client/gui/implementations/NumberEntryWidget.java b/src/main/java/appeng/client/gui/implementations/NumberEntryWidget.java new file mode 100644 index 000000000..ccabecad7 --- /dev/null +++ b/src/main/java/appeng/client/gui/implementations/NumberEntryWidget.java @@ -0,0 +1,130 @@ +package appeng.client.gui.implementations; + +import java.util.function.Consumer; +import java.util.function.LongConsumer; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.IGuiEventListener; +import net.minecraft.client.gui.widget.button.Button; + +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; + +/** + * 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 implements ITickingWidget { + + private final AEBaseScreen parent; + + private final int x; + private final int y; + + private final NumberBox level; + private final NumberEntryType type; + private Button plus1; + private Button plus10; + private Button plus100; + private Button plus1000; + private Button minus1; + private Button minus10; + private Button minus100; + private Button minus1000; + + 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; + 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); + this.level.setVisible(true); + this.level.setFocused2(true); + parent.setFocusedDefault(this.level); + } + + public void setActive(boolean active) { + this.level.setEnabled(active); + this.plus1.active = active; + this.plus10.active = active; + this.plus100.active = active; + this.plus1000.active = active; + this.minus1.active = active; + this.minus10.active = active; + this.minus100.active = active; + 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 addChildren, Consumer