Add gui and packets for locking the rolling machine. #1412
This commit is contained in:
parent
d8f3a8b9b0
commit
c17f232bf8
6 changed files with 98 additions and 10 deletions
|
@ -55,10 +55,7 @@ import techreborn.events.TRRecipeHandler;
|
|||
import techreborn.events.TRTickHandler;
|
||||
import techreborn.init.*;
|
||||
import techreborn.lib.ModInfo;
|
||||
import techreborn.packets.PacketAesu;
|
||||
import techreborn.packets.PacketIdsu;
|
||||
import techreborn.packets.PacketSetRecipe;
|
||||
import techreborn.packets.PacketSyncSideConfig;
|
||||
import techreborn.packets.*;
|
||||
import techreborn.proxies.CommonProxy;
|
||||
import techreborn.utils.StackWIPHandler;
|
||||
import techreborn.world.OilLakeGenerator;
|
||||
|
@ -181,6 +178,7 @@ public class Core {
|
|||
event.registerPacket(PacketAesu.class, Side.SERVER);
|
||||
event.registerPacket(PacketIdsu.class, Side.SERVER);
|
||||
event.registerPacket(PacketSetRecipe.class, Side.SERVER);
|
||||
event.registerPacket(PacketRollingMachineLock.class, Side.SERVER);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -25,8 +25,12 @@
|
|||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import techreborn.packets.PacketRollingMachineLock;
|
||||
import techreborn.tiles.TileRollingMachine;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiRollingMachine extends GuiBase {
|
||||
|
||||
TileRollingMachine rollingMachine;
|
||||
|
@ -50,6 +54,7 @@ public class GuiRollingMachine extends GuiBase {
|
|||
this.drawOutputSlot(124, gridYPos + 18, layer);
|
||||
|
||||
this.builder.drawJEIButton(this, 150, 4, layer);
|
||||
this.builder.drawLockButton(this, 130, 4, mouseX, mouseY, layer,rollingMachine.locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,4 +65,13 @@ public class GuiRollingMachine extends GuiBase {
|
|||
this.builder.drawProgressBar(this, this.rollingMachine.getProgressScaled(100), 100, 92, 43, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
|
||||
this.builder.drawMultiEnergyBar(this, 9, 17, (int) this.rollingMachine.getEnergy(), (int) this.rollingMachine.getMaxPower(), mouseX, mouseY, 0, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if(this.builder.isInRect(130 + getGuiLeft(), 4 + getGuiTop(), 20, 12, mouseX, mouseY)){
|
||||
NetworkManager.sendToServer(new PacketRollingMachineLock(rollingMachine, !rollingMachine.locked));
|
||||
return;
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,30 @@ public class TRBuilder extends GuiBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
public void drawLockButton(GuiBase gui, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer, boolean locked) {
|
||||
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, 204, 70 + (locked ? 12 : 0) , 20, 12);
|
||||
if (isInRect(x, y, 20, 12, mouseX, mouseY)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if(locked){
|
||||
list.add("Unlock items");
|
||||
} else {
|
||||
list.add("Lock Items");
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, 80, gui.mc.fontRenderer);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHologramButton(GuiBase gui, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer) {
|
||||
if(GuiBase.showSlotConfig){
|
||||
return;
|
||||
|
|
|
@ -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.TileRollingMachine;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PacketRollingMachineLock implements INetworkPacket<PacketRollingMachineLock> {
|
||||
|
||||
BlockPos machinePos;
|
||||
boolean locked;
|
||||
|
||||
public PacketRollingMachineLock(TileRollingMachine machine, boolean locked) {
|
||||
this.machinePos = machine.getPos();
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public PacketRollingMachineLock() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ExtendedPacketBuffer buffer) throws IOException {
|
||||
buffer.writeBlockPos(machinePos);
|
||||
buffer.writeBoolean(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(ExtendedPacketBuffer buffer) throws IOException {
|
||||
machinePos = buffer.readBlockPos();
|
||||
locked = buffer.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processData(PacketRollingMachineLock message, MessageContext context) {
|
||||
TileEntity tileEntity = context.getServerHandler().player.world.getTileEntity(machinePos);
|
||||
if(tileEntity instanceof TileRollingMachine){
|
||||
((TileRollingMachine) tileEntity).locked = locked;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -68,6 +68,7 @@ public class TileRollingMachine extends TilePowerAcceptor
|
|||
@Nonnull
|
||||
public ItemStack currentRecipe;
|
||||
private int outputSlot;
|
||||
public boolean locked = false;
|
||||
|
||||
public TileRollingMachine() {
|
||||
super();
|
||||
|
@ -175,19 +176,17 @@ public class TileRollingMachine extends TilePowerAcceptor
|
|||
ItemUtils.readInvFromNBT(this.craftMatrix, "Crafting", tagCompound);
|
||||
this.isRunning = tagCompound.getBoolean("isRunning");
|
||||
this.tickTime = tagCompound.getInteger("tickTime");
|
||||
this.locked = tagCompound.getBoolean("locked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
ItemUtils.writeInvToNBT(this.craftMatrix, "Crafting", tagCompound);
|
||||
this.writeUpdateToNBT(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public void writeUpdateToNBT(final NBTTagCompound tagCompound) {
|
||||
tagCompound.setBoolean("isRunning", this.isRunning);
|
||||
tagCompound.setInteger("tickTime", this.tickTime);
|
||||
tagCompound.setBoolean("locked", locked);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,7 +231,16 @@ public class TileRollingMachine extends TilePowerAcceptor
|
|||
.addInventory().tile(this)
|
||||
.outputSlot(0, 124, 40)
|
||||
.energySlot(2, 8, 70)
|
||||
.syncEnergyValue().syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create(this);
|
||||
.syncEnergyValue().syncIntegerValue(this::getBurnTime, this::setBurnTime).syncIntegerValue(this::getLockedInt, this::setLockedInt).addInventory().create(this);
|
||||
}
|
||||
|
||||
//Easyest way to sync back to the client
|
||||
public int getLockedInt(){
|
||||
return locked ? 1 : 0;
|
||||
}
|
||||
|
||||
public void setLockedInt(int lockedInt){
|
||||
locked = lockedInt == 1;
|
||||
}
|
||||
|
||||
public int getProgressScaled(final int scale) {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 18 KiB |
Loading…
Reference in a new issue