aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Robertz <dream-master@gmx.net>2021-05-15 21:24:09 +0200
committerGitHub <noreply@github.com>2021-05-15 21:24:09 +0200
commit6feb32e8eecd39b8140df4dc3c0fafc989420bc0 (patch)
treeb7d05c815dc387aed400fc2896ae33833bd8a368 /src
parentf81b0b4b5a0d2e74c9cbb420e74b9e217d0cc6ec (diff)
parent9239ed33b195a59561e9a74bd7063640a97ab514 (diff)
downloadGT5-Unofficial-6feb32e8eecd39b8140df4dc3c0fafc989420bc0.tar.gz
GT5-Unofficial-6feb32e8eecd39b8140df4dc3c0fafc989420bc0.tar.bz2
GT5-Unofficial-6feb32e8eecd39b8140df4dc3c0fafc989420bc0.zip
Merge pull request #533 from GTNewHorizons/update-fluid-display
Allow client to proactively request fluid display updates
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/GT_Mod.java1
-rw-r--r--src/main/java/gregtech/api/enums/GT_Values.java1
-rw-r--r--src/main/java/gregtech/api/interfaces/IHasFluidDisplayItem.java5
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java6
-rw-r--r--src/main/java/gregtech/common/GT_Client.java25
-rw-r--r--src/main/java/gregtech/common/GT_Network.java5
-rw-r--r--src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java64
8 files changed, 104 insertions, 5 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index 07362a87af..080dc13fc8 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -265,6 +265,7 @@ public class GT_Mod implements IGT_Mod {
GT_Values.D1 = tMainConfig.get(aTextGeneral, "Debug", false).getBoolean(false);
GT_Values.D2 = tMainConfig.get(aTextGeneral, "Debug2", false).getBoolean(false);
GT_Values.hideAssLineRecipes = tMainConfig.get(aTextGeneral, "hide assline recipes", false).getBoolean(false);
+ GT_Values.updateFluidDisplayItems = tMainConfig.get(aTextGeneral, "update fluid display items", true).getBoolean(true);
GT_Values.allow_broken_recipemap = tMainConfig.get(aTextGeneral, "debug allow broken recipemap", false).getBoolean(false);
GT_Values.debugCleanroom = tMainConfig.get(aTextGeneral, "debugCleanroom", false).getBoolean(false);
GT_Values.debugDriller = tMainConfig.get(aTextGeneral, "debugDriller", false).getBoolean(false);
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java
index a0ccd107a6..7152663c42 100644
--- a/src/main/java/gregtech/api/enums/GT_Values.java
+++ b/src/main/java/gregtech/api/enums/GT_Values.java
@@ -300,5 +300,6 @@ public class GT_Values {
public static boolean cls_enabled;
public static boolean hideAssLineRecipes = false;
+ public static boolean updateFluidDisplayItems = true;
public static final int STEAM_PER_WATER = 160;
}
diff --git a/src/main/java/gregtech/api/interfaces/IHasFluidDisplayItem.java b/src/main/java/gregtech/api/interfaces/IHasFluidDisplayItem.java
new file mode 100644
index 0000000000..dc844b8a85
--- /dev/null
+++ b/src/main/java/gregtech/api/interfaces/IHasFluidDisplayItem.java
@@ -0,0 +1,5 @@
+package gregtech.api.interfaces;
+
+public interface IHasFluidDisplayItem {
+ void updateFluidDisplayItem();
+}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
index d940ff6602..7d79d2b93f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
@@ -579,7 +579,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
}
@Override
- protected void updateFluidDisplayItem() {
+ public void updateFluidDisplayItem() {
super.updateFluidDisplayItem();
if (displaysInputFluid()) {
int tDisplayStackSlot = OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length;
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java
index a4e13ae321..6a65eaf5d8 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java
@@ -3,6 +3,7 @@ package gregtech.api.metatileentity.implementations;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.GT_Container_BasicTank;
import gregtech.api.gui.GT_GUIContainer_BasicTank;
+import gregtech.api.interfaces.IHasFluidDisplayItem;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Utility;
@@ -18,7 +19,7 @@ import net.minecraftforge.fluids.FluidTankInfo;
* <p/>
* This is the main construct for my generic Tanks. Filling and emptying behavior have to be implemented manually
*/
-public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_TieredMachineBlock {
+public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_TieredMachineBlock implements IHasFluidDisplayItem {
public FluidStack mFluid;
protected int mOpenerCount;
@@ -190,7 +191,8 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier
}
}
- protected void updateFluidDisplayItem() {
+ @Override
+ public void updateFluidDisplayItem() {
if (displaysItemStack() && getStackDisplaySlot() >= 0 && getStackDisplaySlot() < mInventory.length) {
if (getDisplayedFluid() == null) {
if (ItemList.Display_Fluid.isStackEqual(mInventory[getStackDisplaySlot()], true, true))
diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java
index 6ce360c017..8a5b0a85be 100644
--- a/src/main/java/gregtech/common/GT_Client.java
+++ b/src/main/java/gregtech/common/GT_Client.java
@@ -13,13 +13,16 @@ import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.Materials;
+import gregtech.api.interfaces.IHasFluidDisplayItem;
import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.ITurnable;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.util.*;
import gregtech.common.entities.GT_Entity_Arrow;
import gregtech.common.entities.GT_Entity_Arrow_Potion;
+import gregtech.common.net.MessageUpdateFluidDisplayItem;
import gregtech.common.render.*;
import ic2.api.tile.IWrenchable;
import net.minecraft.block.Block;
@@ -29,6 +32,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatFileWriter;
import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
@@ -76,6 +80,9 @@ public class GT_Client extends GT_Proxy
/**This is the place to def the value used below**/
private long afterSomeTime;
private boolean mAnimationDirection;
+ private int mLastUpdatedBlockX;
+ private int mLastUpdatedBlockY;
+ private int mLastUpdatedBlockZ;
private boolean isFirstClientPlayerTick;
private String mMessage;
public GT_Client() {
@@ -406,6 +413,24 @@ public class GT_Client extends GT_Proxy
tKey = (GT_PlayedSound) i$.next();
}
if(!GregTech_API.mServerStarted) GregTech_API.mServerStarted = true;
+ if (GT_Values.updateFluidDisplayItems) {
+ MovingObjectPosition trace = Minecraft.getMinecraft().objectMouseOver;
+ if (trace.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK &&
+ (mLastUpdatedBlockX != trace.blockX &&
+ mLastUpdatedBlockY != trace.blockY &&
+ mLastUpdatedBlockZ != trace.blockZ || afterSomeTime % 10 == 0)) {
+ mLastUpdatedBlockX = trace.blockX;
+ mLastUpdatedBlockY = trace.blockY;
+ mLastUpdatedBlockZ = trace.blockZ;
+ TileEntity tileEntity = aEvent.player.worldObj.getTileEntity(trace.blockX, trace.blockY, trace.blockZ);
+ if (tileEntity instanceof IGregTechTileEntity) {
+ IGregTechTileEntity gtTile = (IGregTechTileEntity) tileEntity;
+ if (gtTile.getMetaTileEntity() instanceof IHasFluidDisplayItem) {
+ GT_Values.NW.sendToServer(new MessageUpdateFluidDisplayItem(trace.blockX, trace.blockY, trace.blockZ, gtTile.getWorld().provider.dimensionId));
+ }
+ }
+ }
+ }
}
}
diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java
index fcd81ed988..b0e6f5d35e 100644
--- a/src/main/java/gregtech/common/GT_Network.java
+++ b/src/main/java/gregtech/common/GT_Network.java
@@ -11,6 +11,7 @@ import gregtech.api.enums.GT_Values;
import gregtech.api.net.*;
import gregtech.common.blocks.GT_Packet_Ores;
import gregtech.common.net.MessageSetFlaskCapacity;
+import gregtech.common.net.MessageUpdateFluidDisplayItem;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
@@ -32,8 +33,8 @@ public class GT_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet>
private final GT_Packet[] mSubChannels;
public GT_Network() {
- this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", new ChannelHandler[]{this, new HandlerShared()});
- this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores(), new GT_Packet_Pollution(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI()};
+ this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", this, new HandlerShared());
+ this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores(), new GT_Packet_Pollution(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI(), new MessageUpdateFluidDisplayItem()};
}
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput)
diff --git a/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java b/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java
new file mode 100644
index 0000000000..46af08134d
--- /dev/null
+++ b/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java
@@ -0,0 +1,64 @@
+package gregtech.common.net;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import gregtech.api.interfaces.IHasFluidDisplayItem;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.net.GT_Packet;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.WorldServer;
+import net.minecraftforge.common.DimensionManager;
+
+public class MessageUpdateFluidDisplayItem extends GT_Packet {
+ private int mBlockX, mBlockY, mBlockZ, mDim;
+
+ public MessageUpdateFluidDisplayItem() {
+ super(true);
+ }
+
+ public MessageUpdateFluidDisplayItem(int mBlockX, int mBlockY, int mBlockZ, int mDim) {
+ super(false);
+ this.mBlockX = mBlockX;
+ this.mBlockY = mBlockY;
+ this.mBlockZ = mBlockZ;
+ this.mDim = mDim;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 8;
+ }
+
+ @Override
+ public byte[] encode() {
+ ByteArrayDataOutput os = ByteStreams.newDataOutput(32);
+ os.writeInt(mBlockX);
+ os.writeInt(mBlockY);
+ os.writeInt(mBlockZ);
+ os.writeInt(mDim);
+ return os.toByteArray();
+ }
+
+ @Override
+ public GT_Packet decode(ByteArrayDataInput aData) {
+ return new MessageUpdateFluidDisplayItem(aData.readInt(), aData.readInt(), aData.readInt(), aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ WorldServer world = DimensionManager.getWorld(mDim);
+ if (world != null) {
+ if (world.blockExists(mBlockX, mBlockY, mBlockZ)) {
+ TileEntity tileEntity = world.getTileEntity(mBlockX, mBlockY, mBlockZ);
+ if (tileEntity instanceof IGregTechTileEntity) {
+ IGregTechTileEntity gtTile = (IGregTechTileEntity) tileEntity;
+ if (gtTile.getMetaTileEntity() instanceof IHasFluidDisplayItem) {
+ ((IHasFluidDisplayItem) gtTile.getMetaTileEntity()).updateFluidDisplayItem();
+ }
+ }
+ }
+ }
+ }
+}