aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainer.java15
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_SetLockedFluid.java91
2 files changed, 106 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer.java b/src/main/java/gregtech/api/gui/GT_GUIContainer.java
index b122b33a73..af6c37a8dd 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainer.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainer.java
@@ -3,9 +3,12 @@ package gregtech.api.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.inventory.Container;
+import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Mouse;
+import static gregtech.GT_Mod.GT_FML_LOGGER;
+
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
@@ -69,6 +72,18 @@ public class GT_GUIContainer extends GuiContainer {
protected void onMouseWheel(int mx, int my, int delta) {
}
+ public boolean isMouseOverSlot(int slotIndex, int mx, int my)
+ {
+ int size = inventorySlots.inventorySlots.size();
+ if (slotIndex < 0 || slotIndex >= size) {
+ // slot does not exist somehow. log and carry on
+ GT_FML_LOGGER.error("Slot {} required where only {} is present", slotIndex, size);
+ return false;
+ }
+ Slot slot = inventorySlots.getSlot(slotIndex);
+ return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mx, my);
+ }
+
/*
@Override
protected void drawSlotInventory(Slot par1Slot) {
diff --git a/src/main/java/gregtech/api/net/GT_Packet_SetLockedFluid.java b/src/main/java/gregtech/api/net/GT_Packet_SetLockedFluid.java
new file mode 100644
index 0000000000..deea71feab
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_SetLockedFluid.java
@@ -0,0 +1,91 @@
+package gregtech.api.net;
+
+import com.google.common.io.ByteArrayDataInput;
+import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
+import gregtech.api.util.GT_LanguageManager;
+import gregtech.api.util.GT_Utility;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+
+public class GT_Packet_SetLockedFluid extends GT_Packet_New {
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected int mFluidID;
+
+ private EntityPlayerMP mPlayer;
+
+ public GT_Packet_SetLockedFluid() {
+ super(true);
+ }
+
+ public GT_Packet_SetLockedFluid(IGregTechTileEntity aTile, FluidStack aSource) {
+ this(aTile.getXCoord(), aTile.getYCoord(), aTile.getZCoord(), aSource.getFluidID());
+ }
+
+ public GT_Packet_SetLockedFluid(int x, short y, int z, int aFluidID) {
+ super(false);
+
+ this.mX = x;
+ this.mY = y;
+ this.mZ = z;
+
+ this.mFluidID = aFluidID;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 14;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeInt(mFluidID);
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_SetLockedFluid(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (mPlayer == null) return;
+ World world = mPlayer.worldObj;
+ TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (!(tile instanceof IGregTechTileEntity) || ((IGregTechTileEntity) tile).isDead()) return;
+ IMetaTileEntity mte = ((IGregTechTileEntity) tile).getMetaTileEntity();
+ if (!(mte instanceof GT_MetaTileEntity_Hatch_Output)) return;
+ Fluid tFluid = FluidRegistry.getFluid(mFluidID);
+ if (tFluid == null) return;
+ ((GT_MetaTileEntity_Hatch_Output) mte).setLockedFluidName(tFluid.getName());
+ GT_Utility.sendChatToPlayer(mPlayer, String.format(GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_151.4", "Sucessfully locked Fluid to %s", false), new FluidStack(tFluid, 1).getLocalizedName()));
+ }
+}