diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 392bb3feb..27bb53123 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -179,6 +179,7 @@ public class Core { event.registerPacket(PacketIdsu.class, Side.SERVER); event.registerPacket(PacketSetRecipe.class, Side.SERVER); event.registerPacket(PacketRollingMachineLock.class, Side.SERVER); + event.registerPacket(PacketFusionControlSize.class, Side.SERVER); } @Mod.EventHandler diff --git a/src/main/java/techreborn/blocks/BlockFusionControlComputer.java b/src/main/java/techreborn/blocks/BlockFusionControlComputer.java index d31400951..7a229cdf6 100644 --- a/src/main/java/techreborn/blocks/BlockFusionControlComputer.java +++ b/src/main/java/techreborn/blocks/BlockFusionControlComputer.java @@ -69,7 +69,9 @@ public class BlockFusionControlComputer extends BlockMachineBase { } if(world.isAirBlock(coil) && !tileFusionControlComputer.isCoil(coil)){ world.setBlockState(coil, ModBlocks.FUSION_COIL.getDefaultState()); - player.getHeldItem(hand).shrink(1); + if(!player.isCreative()){ + player.getHeldItem(hand).shrink(1); + } placed = true; } } diff --git a/src/main/java/techreborn/client/gui/GuiFusionReactor.java b/src/main/java/techreborn/client/gui/GuiFusionReactor.java index 871364e4d..553ec49e3 100644 --- a/src/main/java/techreborn/client/gui/GuiFusionReactor.java +++ b/src/main/java/techreborn/client/gui/GuiFusionReactor.java @@ -31,9 +31,12 @@ import net.minecraft.util.math.BlockPos; import reborncore.client.multiblock.Multiblock; import reborncore.client.multiblock.MultiblockRenderEvent; import reborncore.client.multiblock.MultiblockSet; +import reborncore.common.network.NetworkManager; import reborncore.common.util.Torus; import techreborn.client.gui.widget.GuiButtonHologram; +import techreborn.client.gui.widget.GuiButtonUpDown; import techreborn.init.ModBlocks; +import techreborn.packets.PacketFusionControlSize; import techreborn.proxies.ClientProxy; import techreborn.tiles.fusionReactor.TileFusionControlComputer; @@ -47,7 +50,13 @@ public class GuiFusionReactor extends GuiBase { super(player, tile, tile.createContainer(player)); this.tile = tile; } - + + @Override + public void initGui() { + super.initGui(); + + } + @Override protected void drawGuiContainerBackgroundLayer(final float partialTicks, final int mouseX, final int mouseY) { super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY); @@ -58,6 +67,7 @@ public class GuiFusionReactor extends GuiBase { this.drawOutputSlot(80, 47, layer); this.builder.drawJEIButton(this, 150, 4, layer); + } @Override @@ -76,6 +86,13 @@ public class GuiFusionReactor extends GuiBase { addHologramButton(76, 56, 212, layer); builder.drawHologramButton(this, 76, 56, mouseX, mouseY, layer); } + this.builder.drawUpDownButtons(this, 121, 79, layer); + drawString("Size: " + tile.size, 83, 81, 0xFFFFFF, layer); + + buttonList.add(new GuiButtonUpDown(300, 121, 79, this, GuiBase.Layer.FOREGROUND)); + buttonList.add(new GuiButtonUpDown(301, 121 + 12, 79, this, GuiBase.Layer.FOREGROUND)); + buttonList.add(new GuiButtonUpDown(302, 121 + 24, 79, this, GuiBase.Layer.FOREGROUND)); + buttonList.add(new GuiButtonUpDown(303, 121 + 36, 79, this, GuiBase.Layer.FOREGROUND)); } public void addHologramButton(int x, int y, int id, Layer layer) { @@ -110,8 +127,22 @@ public class GuiFusionReactor extends GuiBase { } else { ClientProxy.multiblockRenderEvent.setMultiblock(null); } + } else if (button.id == 300){ + sendSizeChange(5); + } else if (button.id == 301){ + sendSizeChange(1); + } else if (button.id == 302){ + sendSizeChange(-1); + } else if (button.id == 303){ + sendSizeChange(-5); } } + + private void sendSizeChange(int sizeDelta){ + NetworkManager.sendToServer(new PacketFusionControlSize(sizeDelta, tile.getPos())); + //Reset the multiblock as it will be wrong now. + ClientProxy.multiblockRenderEvent.setMultiblock(null); + } public void addComponent(final int x, final int y, final int z, final IBlockState blockState, final Multiblock multiblock) { multiblock.addComponent(new BlockPos(x, y, z), blockState); diff --git a/src/main/java/techreborn/client/gui/TRBuilder.java b/src/main/java/techreborn/client/gui/TRBuilder.java index 8786b9d79..d2bef4c7f 100644 --- a/src/main/java/techreborn/client/gui/TRBuilder.java +++ b/src/main/java/techreborn/client/gui/TRBuilder.java @@ -293,6 +293,21 @@ public class TRBuilder extends GuiBuilder { gui.drawTexturedModalRect(x + 24, y, 150, 94, 12, 12); gui.drawTexturedModalRect(x + 36, y, 150, 106, 12, 12); } + + public void drawUpDownButtonsSmall(GuiBase gui, int x, int y, GuiBase.Layer layer){ + if(GuiBase.showSlotConfig){ + return; + } + if (layer == GuiBase.Layer.BACKGROUND) { + x += gui.getGuiLeft(); + y += gui.getGuiTop(); + } + gui.mc.getTextureManager().bindTexture(GUI_SHEET); + //gui.drawTexturedModalRect(x, y, 150, 70, 12, 12); + gui.drawTexturedModalRect(x + 12, y, 150, 82, 12, 12); + gui.drawTexturedModalRect(x + 24, y, 150, 94, 12, 12); + //gui.drawTexturedModalRect(x + 36, y, 150, 106, 12, 12); + } public void drawEnergyOutput(GuiBase gui, int right, int top, int maxOutput, GuiBase.Layer layer){ if(GuiBase.showSlotConfig){ diff --git a/src/main/java/techreborn/packets/PacketFusionControlSize.java b/src/main/java/techreborn/packets/PacketFusionControlSize.java new file mode 100644 index 000000000..e1b8983bf --- /dev/null +++ b/src/main/java/techreborn/packets/PacketFusionControlSize.java @@ -0,0 +1,44 @@ +package techreborn.packets; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import reborncore.common.network.ExtendedPacketBuffer; +import reborncore.common.network.INetworkPacket; +import techreborn.tiles.fusionReactor.TileFusionControlComputer; + +import java.io.IOException; + +public class PacketFusionControlSize implements INetworkPacket { + + int sizeDelta; + BlockPos pos; + + public PacketFusionControlSize(int sizeDelta, BlockPos pos) { + this.sizeDelta = sizeDelta; + this.pos = pos; + } + + public PacketFusionControlSize() { + } + + @Override + public void writeData(ExtendedPacketBuffer buffer) throws IOException { + buffer.writeInt(sizeDelta); + buffer.writeBlockPos(pos); + } + + @Override + public void readData(ExtendedPacketBuffer buffer) throws IOException { + sizeDelta = buffer.readInt(); + pos = buffer.readBlockPos(); + } + + @Override + public void processData(PacketFusionControlSize message, MessageContext context) { + TileEntity tile = context.getServerHandler().player.world.getTileEntity(message.pos); + if(tile instanceof TileFusionControlComputer){ + ((TileFusionControlComputer) tile).changeSize(sizeDelta); + } + } +} diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java index b51884f99..ef21691ae 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java @@ -57,6 +57,8 @@ public class TileFusionControlComputer extends TilePowerAcceptor public static int maxOutput = 1_000_000; @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxEnergy", comment = "Fusion Reactor Max Energy (Value in EU)") public static int maxEnergy = 100_000_000; + @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxCoilSize", comment = "Fusion Reactor Max Coil size (Radius)") + public static int maxCoilSize = 50; public Inventory inventory; @@ -352,6 +354,7 @@ public class TileFusionControlComputer extends TilePowerAcceptor .syncIntegerValue(this::getCoilStatus, this::setCoilStatus) .syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime) .syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime) + .syncIntegerValue(this::getSize, this::setSize) .syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this); } @@ -386,4 +389,17 @@ public class TileFusionControlComputer extends TilePowerAcceptor public void setNeededPower(final int neededPower) { this.neededPower = neededPower; } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public void changeSize(int sizeDelta){ + int newSize = size + sizeDelta; + this.size = Math.max(6, Math.min(maxCoilSize, newSize)); + } }