diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java index 3c64629a..ede0b401 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java @@ -57,7 +57,8 @@ private static List getAddActionInfo() { // It was truly a beautiful sight... if (isShiftDown() && isControlDown()) { - String keyCombination = "SHIFT + CTRL"; + String keyCombination = + "SHIFT + CTRL"; tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.multiply", keyCombination)); tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.divide", diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBus.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBus.java index 9897a277..c5d21109 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBus.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBus.java @@ -1,22 +1,54 @@ package github.kasuminova.mmce.client.gui; +import appeng.api.config.ActionItems; +import appeng.api.config.Settings; +import appeng.client.gui.widgets.GuiImgButton; import appeng.core.localization.GuiText; import github.kasuminova.mmce.common.container.ContainerMEItemOutputBus; +import github.kasuminova.mmce.common.network.PktSwitchGuiMEOutputBus; import github.kasuminova.mmce.common.tile.MEItemOutputBus; +import hellfirepvp.modularmachinery.ModularMachinery; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import java.io.IOException; public class GuiMEItemOutputBus extends GuiMEItemBus { - // For convenience, the Sky Chest resource was used :P private static final ResourceLocation TEXTURES_OUTPUT_BUS = new ResourceLocation("appliedenergistics2", "textures/guis/skychest.png"); + private CustomStackSizeButton stackSizeBtn; + private final MEItemOutputBus outputBus; + public GuiMEItemOutputBus(final MEItemOutputBus te, final EntityPlayer player) { super(new ContainerMEItemOutputBus(te, player)); + this.outputBus = te; this.ySize = 195; } + @Override + public void initGui() { + super.initGui(); + + this.stackSizeBtn = new CustomStackSizeButton( + this.guiLeft - 18, + this.guiTop + 8 + ); + this.buttonList.add(this.stackSizeBtn); + } + + @Override + protected void actionPerformed(final GuiButton btn) throws IOException { + super.actionPerformed(btn); + + if (btn == this.stackSizeBtn) { + ModularMachinery.NET_CHANNEL.sendToServer( + new PktSwitchGuiMEOutputBus(this.outputBus.getPos(), 1) + ); + } + } + @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { this.fontRenderer.drawString(I18n.format("gui.meitemoutputbus.title"), 8, 8, 0x404040); @@ -30,4 +62,14 @@ public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); } -} + private static class CustomStackSizeButton extends GuiImgButton { + public CustomStackSizeButton(int x, int y) { + super(x, y, Settings.ACTIONS, ActionItems.WRENCH); + } + + @Override + public String getMessage() { + return "Configure Stack Size"; + } + } +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBusStackSize.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBusStackSize.java new file mode 100644 index 00000000..523e2d92 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemOutputBusStackSize.java @@ -0,0 +1,315 @@ +package github.kasuminova.mmce.client.gui; + +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.MathExpressionParser; +import appeng.client.gui.widgets.GuiTabButton; +import github.kasuminova.mmce.common.container.ContainerMEItemOutputBusStackSize; +import github.kasuminova.mmce.common.network.PktMEOutputBusStackSizeChange; +import github.kasuminova.mmce.common.network.PktSwitchGuiMEOutputBus; +import github.kasuminova.mmce.common.tile.MEItemOutputBus; +import hellfirepvp.modularmachinery.ModularMachinery; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import java.io.IOException; + +public class GuiMEItemOutputBusStackSize extends AEBaseGui { + + private static final ResourceLocation TEXTURES = new ResourceLocation("modularmachinery", "textures/gui/stacksize.png"); + + private GuiTextField stackSizeBox; + private GuiTabButton originalGuiBtn; + private final MEItemOutputBus outputBus; + + private GuiButton plus1; + private GuiButton plus10; + private GuiButton plus100; + private GuiButton plus1000; + private GuiButton minus1; + private GuiButton minus10; + private GuiButton minus100; + private GuiButton minus1000; + + public GuiMEItemOutputBusStackSize(final InventoryPlayer inventoryPlayer, final MEItemOutputBus outputBus) { + super(new ContainerMEItemOutputBusStackSize(inventoryPlayer, outputBus)); + this.outputBus = outputBus; + this.ySize = 105; + } + + @Override + public void initGui() { + Keyboard.enableRepeatEvents(true); + super.initGui(); + + this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 32, 22, 20, "+1")); + this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 32, 28, 20, "+10")); + this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 32, 32, 20, "+100")); + this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 32, 38, 20, "+1000")); + + this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 69, 22, 20, "-1")); + this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 69, 28, 20, "-10")); + this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 69, 32, 20, "-100")); + this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 69, 38, 20, "-1000")); + + final ContainerMEItemOutputBusStackSize container = (ContainerMEItemOutputBusStackSize) this.inventorySlots; + final ItemStack busIcon = new ItemStack(this.outputBus.getBlockType()); + + if (!busIcon.isEmpty()) { + this.buttonList.add(this.originalGuiBtn = new GuiTabButton( + this.guiLeft + 154, + this.guiTop, + busIcon, + "ME Machinery Item Output Bus", + this.itemRender + )); + } + + this.stackSizeBox = new GuiTextField( + 0, + this.fontRenderer, + this.guiLeft + 62, + this.guiTop + 57, + 75, + this.fontRenderer.FONT_HEIGHT + ); + this.stackSizeBox.setEnableBackgroundDrawing(false); + this.stackSizeBox.setMaxStringLength(32); + this.stackSizeBox.setTextColor(0xFFFFFF); + this.stackSizeBox.setVisible(true); + this.stackSizeBox.setFocused(true); + + this.stackSizeBox.setText(String.valueOf(container.getStackSize())); + } + + @Override + protected void actionPerformed(final GuiButton btn) throws IOException { + super.actionPerformed(btn); + + if (btn == this.originalGuiBtn) { + String text = this.stackSizeBox.getText(); + if (!text.isEmpty()) { + try { + long value = parseValue(text); + if (value > Integer.MAX_VALUE) { + value = Integer.MAX_VALUE; + } else if (value < 1) { + value = 1; + } + this.sendStackSizeToServer((int) value); + } catch (NumberFormatException e) { + } + } + + ModularMachinery.NET_CHANNEL.sendToServer( + new PktSwitchGuiMEOutputBus(this.outputBus.getPos(), 0) + ); + } + + if (btn == this.plus1) this.addQty(1); + else if (btn == this.plus10) this.addQty(10); + else if (btn == this.plus100) this.addQty(100); + else if (btn == this.plus1000) this.addQty(1000); + else if (btn == this.minus1) this.addQty(-1); + else if (btn == this.minus10) this.addQty(-10); + else if (btn == this.minus100) this.addQty(-100); + else if (btn == this.minus1000) this.addQty(-1000); + } + + private void addQty(final int amount) { + try { + String text = this.stackSizeBox.getText(); + + long currentValue = text.isEmpty() ? 0 : parseValue(text); + long newValue = currentValue + amount; + + if (newValue > Integer.MAX_VALUE) { + newValue = Integer.MAX_VALUE; + } else if (newValue < 1) { + newValue = 1; + } + + this.stackSizeBox.setText(String.valueOf(newValue)); + this.sendStackSizeToServer((int) newValue); + } catch (final NumberFormatException e) { + this.stackSizeBox.setText("1"); + this.sendStackSizeToServer(1); + } + } + + private void sendStackSizeToServer(int stackSize) { + ModularMachinery.NET_CHANNEL.sendToServer( + new PktMEOutputBusStackSizeChange(this.outputBus.getPos(), stackSize) + ); + } + + private long parseValue(String text) { + try { + return Long.parseLong(text); + } catch (NumberFormatException e) { + try { + text = preprocessExponents(text); + + double result = MathExpressionParser.parse(text); + if (Double.isNaN(result) || Double.isInfinite(result)) { + throw new NumberFormatException("Invalid expression"); + } + + return (long) Math.round(result); + } catch (Exception ex) { + throw new NumberFormatException("Invalid number or expression"); + } + } + } + + private String preprocessExponents(String expression) { + while (expression.contains("^")) { + int caretIndex = expression.indexOf('^'); + + int baseStart = caretIndex - 1; + while (baseStart > 0 && (Character.isDigit(expression.charAt(baseStart - 1)) || expression.charAt(baseStart - 1) == '.')) { + baseStart--; + } + + int expEnd = caretIndex + 2; + while (expEnd < expression.length() && (Character.isDigit(expression.charAt(expEnd)) || expression.charAt(expEnd) == '.')) { + expEnd++; + } + + String baseStr = expression.substring(baseStart, caretIndex); + String expStr = expression.substring(caretIndex + 1, expEnd); + + double base = Double.parseDouble(baseStr); + double exponent = Double.parseDouble(expStr); + double result = Math.pow(base, exponent); + + expression = expression.substring(0, baseStart) + result + expression.substring(expEnd); + } + + return expression; + } + + @Override + protected void keyTyped(final char character, final int key) throws IOException { + if (!this.checkHotbarKeys(key)) { + boolean isValidChar = Character.isDigit(character) || + character == '+' || character == '-' || + character == '*' || character == '/' || + character == '^' || + character == '(' || character == ')' || + character == '.' || character == 'E' || character == 'e'; + boolean isControlKey = key == 14 || key == 211 || key == 203 || key == 205; + + if ((isValidChar || isControlKey) && this.stackSizeBox.textboxKeyTyped(character, key)) { + } else { + super.keyTyped(character, key); + } + } + } + + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + + final int wheel = Mouse.getEventDWheel(); + if (wheel != 0) { + final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; + final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + + int boxX = this.guiLeft + 62; + int boxY = this.guiTop + 57; + int boxWidth = 75; + int boxHeight = this.fontRenderer.FONT_HEIGHT; + + if (x >= boxX && x <= boxX + boxWidth && y >= boxY && y <= boxY + boxHeight) { + this.onMouseWheelEvent(wheel); + } + } + } + + private void onMouseWheelEvent(int wheel) { + boolean isShiftHeld = GuiScreen.isShiftKeyDown(); + boolean isCtrlHeld = GuiScreen.isCtrlKeyDown(); + + String text = this.stackSizeBox.getText(); + long currentValue; + + try { + currentValue = text.isEmpty() ? 1 : parseValue(text); + } catch (NumberFormatException e) { + currentValue = 1; + } + + long newValue = currentValue; + + if (isShiftHeld && isCtrlHeld) { + if (wheel > 0) { + newValue = currentValue * 2; + } else { + newValue = currentValue / 2; + } + } else if (isShiftHeld) { + if (wheel > 0) { + newValue = currentValue + 1; + } else { + newValue = currentValue - 1; + } + } + + if (newValue > Integer.MAX_VALUE) { + newValue = Integer.MAX_VALUE; + } else if (newValue < 1) { + newValue = 1; + } + + this.stackSizeBox.setText(String.valueOf(newValue)); + this.sendStackSizeToServer((int) newValue); + } + + @Override + public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { + this.fontRenderer.drawString("Stack Size", 8, 6, 0x404040); + } + + @Override + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { + this.mc.getTextureManager().bindTexture(TEXTURES); + this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); + + this.stackSizeBox.drawTextBox(); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + Keyboard.enableRepeatEvents(false); + + String text = this.stackSizeBox.getText(); + if (!text.isEmpty()) { + try { + long value = parseValue(text); + int finalValue; + if (value > Integer.MAX_VALUE) { + finalValue = Integer.MAX_VALUE; + } else if (value < 1) { + finalValue = 1; + } else { + finalValue = (int) value; + } + + sendStackSizeToServer(finalValue); + + } catch (NumberFormatException e) { + try { + ContainerMEItemOutputBusStackSize container = (ContainerMEItemOutputBusStackSize) this.inventorySlots; + sendStackSizeToServer(container.getStackSize()); + } catch (Exception ex) { + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/block/appeng/BlockMEItemOutputBus.java b/src/main/java/github/kasuminova/mmce/common/block/appeng/BlockMEItemOutputBus.java index 5fd4507b..abebcb84 100644 --- a/src/main/java/github/kasuminova/mmce/common/block/appeng/BlockMEItemOutputBus.java +++ b/src/main/java/github/kasuminova/mmce/common/block/appeng/BlockMEItemOutputBus.java @@ -1,5 +1,6 @@ package github.kasuminova.mmce.common.block.appeng; +import appeng.api.implementations.items.IMemoryCard; import github.kasuminova.mmce.common.tile.MEItemOutputBus; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.CommonProxy; @@ -22,16 +23,23 @@ import javax.annotation.Nullable; public class BlockMEItemOutputBus extends BlockMEItemBus { - @Override public boolean onBlockActivated( - @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, - @Nonnull EntityPlayer playerIn, @Nonnull EnumHand hand, - @Nonnull EnumFacing facing, - float hitX, float hitY, float hitZ) { + @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, + @Nonnull EntityPlayer playerIn, @Nonnull EnumHand hand, + @Nonnull EnumFacing facing, + float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); - if (te instanceof MEItemOutputBus) { + if (te instanceof MEItemOutputBus outputBus) { + ItemStack heldItem = playerIn.getHeldItem(hand); + if (heldItem.getItem() instanceof IMemoryCard memoryCard) { + boolean handled = handleSettingsTransfer(outputBus, memoryCard, playerIn, heldItem); + if (handled) { + return true; + } + } + playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.ME_ITEM_OUTPUT_BUS.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); } } @@ -103,4 +111,4 @@ public void onBlockPlacedBy(@Nonnull final World worldIn, ((MEItemOutputBus) te).readInventoryNBT(tag.getCompoundTag("inventory")); } } -} +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/container/ContainerMEItemOutputBusStackSize.java b/src/main/java/github/kasuminova/mmce/common/container/ContainerMEItemOutputBusStackSize.java new file mode 100644 index 00000000..bf4dbc55 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/container/ContainerMEItemOutputBusStackSize.java @@ -0,0 +1,46 @@ +package github.kasuminova.mmce.common.container; + +import appeng.api.config.SecurityPermissions; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import github.kasuminova.mmce.common.tile.MEItemOutputBus; +import net.minecraft.entity.player.InventoryPlayer; + +public class ContainerMEItemOutputBusStackSize extends AEBaseContainer { + + private final MEItemOutputBus outputBus; + + @GuiSync(0) + public int stackSize = Integer.MAX_VALUE; + + public ContainerMEItemOutputBusStackSize(final InventoryPlayer inventoryPlayer, final MEItemOutputBus outputBus) { + super(inventoryPlayer, outputBus); + this.outputBus = outputBus; + + this.stackSize = outputBus.getConfiguredStackSize(); + } + + public int getStackSize() { + return this.stackSize; + } + + public MEItemOutputBus getOwner() { + return this.outputBus; + } + + @Override + public void detectAndSendChanges() { + this.verifyPermissions(SecurityPermissions.BUILD, false); + + super.detectAndSendChanges(); + } + + @Override + public void onContainerClosed(net.minecraft.entity.player.EntityPlayer playerIn) { + super.onContainerClosed(playerIn); + + if (!playerIn.world.isRemote) { + this.outputBus.setConfiguredStackSize(this.stackSize); + } + } +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusInvAction.java b/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusInvAction.java index 118fe5ca..74c4cc2b 100644 --- a/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusInvAction.java +++ b/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusInvAction.java @@ -62,4 +62,4 @@ public IMessage onMessage(final PktMEInputBusInvAction message, final MessageCon return null; } -} +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/network/PktMEOutputBusStackSizeChange.java b/src/main/java/github/kasuminova/mmce/common/network/PktMEOutputBusStackSizeChange.java new file mode 100644 index 00000000..73a253d1 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/network/PktMEOutputBusStackSizeChange.java @@ -0,0 +1,58 @@ +package github.kasuminova.mmce.common.network; + +import github.kasuminova.mmce.common.tile.MEItemOutputBus; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class PktMEOutputBusStackSizeChange implements IMessage, IMessageHandler { + private BlockPos pos = BlockPos.ORIGIN; + private int stackSize = Integer.MAX_VALUE; + + public PktMEOutputBusStackSizeChange() { + } + + public PktMEOutputBusStackSizeChange(final BlockPos pos, final int stackSize) { + this.pos = pos; + this.stackSize = stackSize; + } + + @Override + public void fromBytes(final ByteBuf buf) { + this.pos = BlockPos.fromLong(buf.readLong()); + this.stackSize = buf.readInt(); + } + + @Override + public void toBytes(final ByteBuf buf) { + buf.writeLong(this.pos.toLong()); + buf.writeInt(this.stackSize); + } + + @Override + public IMessage onMessage(final PktMEOutputBusStackSizeChange message, final MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().player; + + player.getServerWorld().addScheduledTask(() -> { + TileEntity te = player.world.getTileEntity(message.pos); + + if (!(te instanceof MEItemOutputBus)) { + return; + } + + MEItemOutputBus outputBus = (MEItemOutputBus) te; + + int validatedStackSize = Math.max(1, message.stackSize); + + outputBus.setConfiguredStackSize(validatedStackSize); + + outputBus.markDirty(); + }); + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/network/PktSwitchGuiMEOutputBus.java b/src/main/java/github/kasuminova/mmce/common/network/PktSwitchGuiMEOutputBus.java new file mode 100644 index 00000000..b3745127 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/network/PktSwitchGuiMEOutputBus.java @@ -0,0 +1,74 @@ +package github.kasuminova.mmce.common.network; + +import github.kasuminova.mmce.common.tile.MEItemOutputBus; +import hellfirepvp.modularmachinery.ModularMachinery; +import hellfirepvp.modularmachinery.common.CommonProxy.GuiType; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class PktSwitchGuiMEOutputBus implements IMessage, IMessageHandler { + private BlockPos pos = BlockPos.ORIGIN; + private int guiType = 0; + + public PktSwitchGuiMEOutputBus() { + } + + public PktSwitchGuiMEOutputBus(final BlockPos pos, final int guiType) { + this.pos = pos; + this.guiType = guiType; + } + + @Override + public void fromBytes(final ByteBuf buf) { + this.pos = BlockPos.fromLong(buf.readLong()); + this.guiType = buf.readInt(); + } + + @Override + public void toBytes(final ByteBuf buf) { + buf.writeLong(this.pos.toLong()); + buf.writeInt(this.guiType); + } + + @Override + public IMessage onMessage(final PktSwitchGuiMEOutputBus message, final MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().player; + + player.getServerWorld().addScheduledTask(() -> { + TileEntity te = player.world.getTileEntity(message.pos); + + if (!(te instanceof MEItemOutputBus)) { + return; + } + + player.closeScreen(); + + if (message.guiType == 0) { + player.openGui( + ModularMachinery.MODID, + GuiType.ME_ITEM_OUTPUT_BUS.ordinal(), + player.world, + message.pos.getX(), + message.pos.getY(), + message.pos.getZ() + ); + } else if (message.guiType == 1) { + player.openGui( + ModularMachinery.MODID, + GuiType.ME_ITEM_OUTPUT_BUS_STACK_SIZE.ordinal(), + player.world, + message.pos.getX(), + message.pos.getY(), + message.pos.getZ() + ); + } + }); + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/github/kasuminova/mmce/common/tile/MEItemOutputBus.java b/src/main/java/github/kasuminova/mmce/common/tile/MEItemOutputBus.java index 7d8f92af..676ab65c 100644 --- a/src/main/java/github/kasuminova/mmce/common/tile/MEItemOutputBus.java +++ b/src/main/java/github/kasuminova/mmce/common/tile/MEItemOutputBus.java @@ -13,12 +13,15 @@ import hellfirepvp.modularmachinery.common.machine.MachineComponent; import hellfirepvp.modularmachinery.common.util.IOInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.concurrent.locks.ReadWriteLock; -public class MEItemOutputBus extends MEItemBus { +public class MEItemOutputBus extends MEItemBus implements SettingsTransfer { + + private int configuredStackSize = Integer.MAX_VALUE; @Override public IOInventory buildInventory() { @@ -29,7 +32,7 @@ public IOInventory buildInventory() { slotIDs[slotID] = slotID; } IOInventory inv = new IOInventory(this, new int[]{}, slotIDs); - inv.setStackLimit(Integer.MAX_VALUE, slotIDs); + inv.setStackLimit(this.configuredStackSize, slotIDs); inv.setListener(slot -> { synchronized (this) { changedSlots[slot] = true; @@ -135,4 +138,62 @@ public void markNoUpdate() { super.markNoUpdate(); } + + public int getConfiguredStackSize() { + return this.configuredStackSize; + } + + public void setConfiguredStackSize(int size) { + this.configuredStackSize = Math.max(1, size); + this.applyStackSizeToInventory(); + this.markForUpdate(); + } + + private void applyStackSizeToInventory() { + if (this.inventory != null) { + int[] slotIDs = new int[this.inventory.getSlots()]; + for (int slotID = 0; slotID < slotIDs.length; slotID++) { + slotIDs[slotID] = slotID; + } + this.inventory.setStackLimit(this.configuredStackSize, slotIDs); + } + } + + @Override + public void readCustomNBT(final NBTTagCompound compound) { + super.readCustomNBT(compound); + + if (compound.hasKey("configuredStackSize")) { + this.configuredStackSize = compound.getInteger("configuredStackSize"); + } + + this.applyStackSizeToInventory(); + } + + @Override + public void writeCustomNBT(final NBTTagCompound compound) { + super.writeCustomNBT(compound); + + compound.setInteger("configuredStackSize", this.configuredStackSize); + } + + @Override + public NBTTagCompound downloadSettings() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("configuredStackSize", this.configuredStackSize); + return tag; + } + + @Override + public void uploadSettings(NBTTagCompound settings) { + if (settings.hasKey("configuredStackSize")) { + setConfiguredStackSize(settings.getInteger("configuredStackSize")); + + try { + proxy.getTick().alertDevice(proxy.getNode()); + } catch (GridAccessException e) { + // NO-OP + } + } + } } \ No newline at end of file diff --git a/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java b/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java index d335ff9b..8a405622 100644 --- a/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java +++ b/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java @@ -10,6 +10,13 @@ import github.kasuminova.mmce.common.concurrent.TaskExecutor; import github.kasuminova.mmce.common.network.*; +import github.kasuminova.mmce.common.network.PktAutoAssemblyRequest; +import github.kasuminova.mmce.common.network.PktMEInputBusInvAction; +import github.kasuminova.mmce.common.network.PktMEOutputBusStackSizeChange; +import github.kasuminova.mmce.common.network.PktMEPatternProviderAction; +import github.kasuminova.mmce.common.network.PktMEPatternProviderHandlerItems; +import github.kasuminova.mmce.common.network.PktPerformanceReport; +import github.kasuminova.mmce.common.network.PktSwitchGuiMEOutputBus; import hellfirepvp.modularmachinery.common.CommonProxy; import hellfirepvp.modularmachinery.common.base.Mods; import hellfirepvp.modularmachinery.common.command.CommandGetBluePrint; @@ -43,23 +50,23 @@ /** * This class is part of the Modular Machinery Mod - * The complete source code for this mod can be found on GitHub. + * The complete source code for this mod can be found on Github. * Class: ModularMachinery * Created by HellFirePvP * Date: 26.06.2017 / 20:26 */ @Mod(modid = ModularMachinery.MODID, name = ModularMachinery.NAME, version = ModularMachinery.VERSION, - dependencies = "required-after:forge@[14.21.0.2371,);" + - "required-after:crafttweaker@[4.0.4,);" + - "after:zenutils@[1.12.8,);" + - "after:jei@[4.13.1.222,);" + - "after:gregtech@[2.7.4-beta,);" + - "after:appliedenergistics2@[rv6-stable-7,);" + - "after:fluxnetworks@[4.1.0,);" + - "after:tconstruct@[1.12.2-2.12.0.157,);" + - "after:thermalexpansion@[5.5.0,);", - acceptedMinecraftVersions = "[1.12, 1.13)", - acceptableRemoteVersions = "[2.1.0, 2.3.0)" + dependencies = "required-after:forge@[14.21.0.2371,);" + + "required-after:crafttweaker@[4.0.4,);" + + "after:zenutils@[1.12.8,);" + + "after:jei@[4.13.1.222,);" + + "after:gregtech@[2.7.4-beta,);" + + "after:appliedenergistics2@[rv6-stable-7,);" + + "after:fluxnetworks@[4.1.0,);" + + "after:tconstruct@[1.12.2-2.12.0.157,);" + + "after:thermalexpansion@[5.5.0,);", + acceptedMinecraftVersions = "[1.12, 1.13)", + acceptableRemoteVersions = "[2.1.0, 2.3.0)" ) public class ModularMachinery { @@ -122,6 +129,10 @@ public void preInit(FMLPreInitializationEvent event) { if (Mods.ASTRAL_SORCERY.isPresent()) { NET_CHANNEL.registerMessage(StarlightMessage.StarlightMessageHandler.class, StarlightMessage.class, 106, Side.SERVER); } + if (Mods.AE2.isPresent()) { + NET_CHANNEL.registerMessage(PktMEOutputBusStackSizeChange.class, PktMEOutputBusStackSizeChange.class, 107, Side.SERVER); + NET_CHANNEL.registerMessage(PktSwitchGuiMEOutputBus.class, PktSwitchGuiMEOutputBus.class, 108, Side.SERVER); + } CommonProxy.loadModData(event.getModConfigurationDirectory()); proxy.preInit(); diff --git a/src/main/java/hellfirepvp/modularmachinery/client/ClientProxy.java b/src/main/java/hellfirepvp/modularmachinery/client/ClientProxy.java index 9165cd72..59b1e0e3 100644 --- a/src/main/java/hellfirepvp/modularmachinery/client/ClientProxy.java +++ b/src/main/java/hellfirepvp/modularmachinery/client/ClientProxy.java @@ -8,13 +8,7 @@ package hellfirepvp.modularmachinery.client; -import github.kasuminova.mmce.client.gui.GuiMEFluidInputBus; -import github.kasuminova.mmce.client.gui.GuiMEFluidOutputBus; -import github.kasuminova.mmce.client.gui.GuiMEGasInputBus; -import github.kasuminova.mmce.client.gui.GuiMEGasOutputBus; -import github.kasuminova.mmce.client.gui.GuiMEItemInputBus; -import github.kasuminova.mmce.client.gui.GuiMEItemOutputBus; -import github.kasuminova.mmce.client.gui.GuiMEPatternProvider; +import github.kasuminova.mmce.client.gui.*; import github.kasuminova.mmce.client.renderer.MachineControllerRenderer; import github.kasuminova.mmce.client.resource.GeoModelExternalLoader; import github.kasuminova.mmce.common.handler.ClientHandler; @@ -118,13 +112,13 @@ private static void registerPendingIBlockColorBlocks() { colors.registerBlockColorHandler(dynamicColor::getColorMultiplier, (Block) dynamicColor); } BlockController.MACHINE_CONTROLLERS.values().forEach(block -> - colors.registerBlockColorHandler(block::getColorMultiplier, block) + colors.registerBlockColorHandler(block::getColorMultiplier, block) ); BlockController.MOC_MACHINE_CONTROLLERS.values().forEach(block -> - colors.registerBlockColorHandler(block::getColorMultiplier, block) + colors.registerBlockColorHandler(block::getColorMultiplier, block) ); BlockFactoryController.FACTORY_CONTROLLERS.values().forEach(block -> - colors.registerBlockColorHandler(block::getColorMultiplier, block) + colors.registerBlockColorHandler(block::getColorMultiplier, block) ); } @@ -134,13 +128,13 @@ private static void registerPendingIItemColorItems() { colors.registerItemColorHandler(dynamicColor::getColorFromItemstack, (Item) dynamicColor); } BlockController.MACHINE_CONTROLLERS.values().forEach(block -> - colors.registerItemColorHandler(block::getColorFromItemstack, block) + colors.registerItemColorHandler(block::getColorFromItemstack, block) ); BlockController.MOC_MACHINE_CONTROLLERS.values().forEach(block -> - colors.registerItemColorHandler(block::getColorFromItemstack, block) + colors.registerItemColorHandler(block::getColorFromItemstack, block) ); BlockFactoryController.FACTORY_CONTROLLERS.values().forEach(block -> - colors.registerItemColorHandler(block::getColorFromItemstack, block) + colors.registerItemColorHandler(block::getColorFromItemstack, block) ); } @@ -150,11 +144,11 @@ private static void registryItemModel(final Item item, final String name) { if (!list.isEmpty()) { for (ItemStack i : list) { ModelLoader.setCustomModelResourceLocation(item, i.getItemDamage(), - new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); + new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); } } else { ModelLoader.setCustomModelResourceLocation(item, 0, - new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); + new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); } } @@ -199,12 +193,12 @@ private void registerModels() { String name = unlocName + "_" + ((BlockVariants) block).getBlockStateName(state); ModelBakery.registerItemVariants(i, new ResourceLocation(ModularMachinery.MODID, name)); ModelLoader.setCustomModelResourceLocation(i, block.getMetaFromState(state), - new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); + new ModelResourceLocation(ModularMachinery.MODID + ":" + name, "inventory")); } } else { ModelBakery.registerItemVariants(i, new ResourceLocation(ModularMachinery.MODID, block.getClass().getSimpleName().toLowerCase())); ModelLoader.setCustomModelResourceLocation(i, 0, - new ModelResourceLocation(ModularMachinery.MODID + ":" + block.getClass().getSimpleName().toLowerCase(), "inventory")); + new ModelResourceLocation(ModularMachinery.MODID + ":" + block.getClass().getSimpleName().toLowerCase(), "inventory")); } } for (Item item : itemModelsToRegister) { @@ -324,6 +318,9 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int } return new GuiMEItemInputBus((MEItemInputBus) present, player); } + case ME_ITEM_OUTPUT_BUS_STACK_SIZE -> { + return new GuiMEItemOutputBusStackSize(player.inventory, (MEItemOutputBus) present); + } case ME_FLUID_OUTPUT_BUS -> { if (!Mods.AE2.isPresent()) { return null; @@ -361,8 +358,6 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int return new GuiContainerLifeEssence((TileLifeEssenceProvider) present, player); } } - return null; } - -} +} \ No newline at end of file diff --git a/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java b/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java index cf5495fc..3a470128 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java @@ -17,6 +17,7 @@ import github.kasuminova.mmce.common.container.ContainerMEGasOutputBus; import github.kasuminova.mmce.common.container.ContainerMEItemInputBus; import github.kasuminova.mmce.common.container.ContainerMEItemOutputBus; +import github.kasuminova.mmce.common.container.ContainerMEItemOutputBusStackSize; import github.kasuminova.mmce.common.container.ContainerMEPatternProvider; import github.kasuminova.mmce.common.handler.EventHandler; import github.kasuminova.mmce.common.handler.UpgradeEventHandler; @@ -302,6 +303,12 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int } return new ContainerLifeEssence((TileLifeEssenceProvider) present, player); } + case ME_ITEM_OUTPUT_BUS_STACK_SIZE -> { + if (aeSecurityCheck(player, present)) { + return null; + } + return new ContainerMEItemOutputBusStackSize(player.inventory, (MEItemOutputBus) present); + } } return null; @@ -325,6 +332,7 @@ public enum GuiType { UPGRADE_BUS(TileUpgradeBus.class), BLUEPRINT_PREVIEW(null), ME_ITEM_OUTPUT_BUS(Mods.AE2.isPresent() ? MEItemOutputBus.class : null), + ME_ITEM_OUTPUT_BUS_STACK_SIZE(Mods.AE2.isPresent() ? MEItemOutputBus.class : null), ME_ITEM_INPUT_BUS(Mods.AE2.isPresent() ? MEItemInputBus.class : null), ME_FLUID_OUTPUT_BUS(Mods.AE2.isPresent() ? MEFluidOutputBus.class : null), ME_FLUID_INPUT_BUS(Mods.AE2.isPresent() ? MEFluidInputBus.class : null), @@ -340,4 +348,4 @@ public enum GuiType { this.requiredTileEntity = requiredTileEntity; } } -} +} \ No newline at end of file diff --git a/src/main/resources/assets/modularmachinery/textures/gui/stacksize.png b/src/main/resources/assets/modularmachinery/textures/gui/stacksize.png new file mode 100644 index 00000000..1ee1fa1a Binary files /dev/null and b/src/main/resources/assets/modularmachinery/textures/gui/stacksize.png differ