diff options
Diffstat (limited to 'src/main/java/GoodGenerator/Common/Container')
-rw-r--r-- | src/main/java/GoodGenerator/Common/Container/NeutronActivatorGUIContainer.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/GoodGenerator/Common/Container/NeutronActivatorGUIContainer.java b/src/main/java/GoodGenerator/Common/Container/NeutronActivatorGUIContainer.java new file mode 100644 index 0000000000..793949e1ff --- /dev/null +++ b/src/main/java/GoodGenerator/Common/Container/NeutronActivatorGUIContainer.java @@ -0,0 +1,79 @@ +package GoodGenerator.Common.Container; + +import GoodGenerator.Blocks.TEs.NeutronActivator; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_Container_MultiMachineEM; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; + +import java.nio.ByteBuffer; + +public class NeutronActivatorGUIContainer extends GT_Container_MultiMachineEM { + + private int KineticE; + + private ByteBuffer buffer; + + public NeutronActivatorGUIContainer(InventoryPlayer inventoryPlayer, IGregTechTileEntity aTileEntity) { + super(inventoryPlayer, aTileEntity, true, true, true); + } + + @Override + public void addCraftingToCrafters(ICrafting clientHandle) { + buffer.putInt(0, KineticE); + sendStateUpdate(clientHandle); + super.addCraftingToCrafters(clientHandle); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (buffer == null) { + buffer = ByteBuffer.allocate(Integer.BYTES); + } + if(mTileEntity.isServerSide()) { + NeutronActivator tile = (NeutronActivator) mTileEntity.getMetaTileEntity(); + int currentKineticE = tile.getCurrentNeutronKineticEnergy(); + boolean isUpdated = false; + if (currentKineticE != KineticE) { + KineticE = currentKineticE; + buffer.putInt(0, KineticE); + isUpdated = true; + } + for (Object clientHandle : this.crafters) { + if (isUpdated) { + sendStateUpdate((ICrafting) clientHandle); + } + } + } + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return true; + } + + private void sendStateUpdate(ICrafting clientHandle) { + final int bytes = Integer.BYTES; + for (int i = 0; i < bytes; i++) { + clientHandle.sendProgressBarUpdate(this, i + 21, buffer.get(i)); + } + } + + @SideOnly(Side.CLIENT) + public void updateProgressBar(int index, int value) { + super.updateProgressBar(index, value); + index = index - 21; + if(index >= 0 && index < buffer.capacity()) { + buffer.put(index, (byte) value); + } + } + + @SideOnly(Side.CLIENT) + public int getKineticE() { + return buffer.getInt(0); + } +} |