mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 02:45:08 +00:00
add fluid terminal
This commit is contained in:
1 parent
87d7f699e8
commit
238fd317e4
31 files changed
+2275
-60
No files matched your search
@@ -0,0 +1,109 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CPacketFluidUpdate implements IMessage {
|
||||
|
||||
private Map<Integer, IAEFluidStack> list;
|
||||
private ItemStack itemStack;
|
||||
private int slotIndex;
|
||||
|
||||
public CPacketFluidUpdate() {
|
||||
}
|
||||
|
||||
public CPacketFluidUpdate(Map<Integer, IAEFluidStack> data, ItemStack itemStack) {
|
||||
this.list = data;
|
||||
this.itemStack = itemStack;
|
||||
this.slotIndex = -1;
|
||||
}
|
||||
|
||||
public CPacketFluidUpdate(Map<Integer, IAEFluidStack> data) {
|
||||
this.list = data;
|
||||
}
|
||||
|
||||
public CPacketFluidUpdate(Map<Integer, IAEFluidStack> data, ItemStack itemStack, int slotIndex) {
|
||||
this.list = data;
|
||||
this.itemStack = itemStack;
|
||||
this.slotIndex = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
this.list = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int id = buf.readInt();
|
||||
boolean isNull = buf.readBoolean();
|
||||
if (!isNull)
|
||||
list.put(id, null);
|
||||
else {
|
||||
IAEFluidStack fluid = AEFluidStack.loadFluidStackFromPacket(buf);
|
||||
list.put(id, fluid);
|
||||
}
|
||||
}
|
||||
if (buf.readBoolean()) {
|
||||
this.itemStack = AEItemStack.loadItemStackFromPacket(buf).getItemStack();
|
||||
this.slotIndex = buf.readInt();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (Map.Entry<Integer, IAEFluidStack> fs : list.entrySet()) {
|
||||
buf.writeInt(fs.getKey());
|
||||
if (fs.getValue() == null)
|
||||
buf.writeBoolean(false);
|
||||
else {
|
||||
buf.writeBoolean(true);
|
||||
fs.getValue().writeToPacket(buf);
|
||||
}
|
||||
}
|
||||
if (this.itemStack != null) {
|
||||
buf.writeBoolean(true);
|
||||
AEItemStack.create(itemStack).writeToPacket(buf);
|
||||
buf.writeInt(this.slotIndex);
|
||||
} else {
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketFluidUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketFluidUpdate message, MessageContext ctx) {
|
||||
Container container = ctx.getServerHandler().playerEntity.openContainer;
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
if (container instanceof FCBaseFluidMonitorContain) {
|
||||
ItemStack item = player.inventory.getItemStack();
|
||||
((FCBaseFluidMonitorContain) container).postChange(new ArrayList<IAEFluidStack>(message.list.values()), message.itemStack == null ? item : message.itemStack, player, message.slotIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import com.glodblock.github.client.gui.GuiFluidIO;
|
||||
import com.glodblock.github.client.gui.GuiFluidInterface;
|
||||
import com.glodblock.github.client.gui.GuiIngredientBuffer;
|
||||
import com.glodblock.github.client.gui.GuiLargeIngredientBuffer;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.client.gui.*;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -20,12 +20,24 @@ import java.util.Map;
|
||||
public class SPacketFluidUpdate implements IMessage {
|
||||
|
||||
private Map<Integer, IAEFluidStack> list;
|
||||
private IAEItemStack itemStack;
|
||||
|
||||
public SPacketFluidUpdate() {
|
||||
}
|
||||
|
||||
public SPacketFluidUpdate(Map<Integer, IAEFluidStack> data) {
|
||||
this.list = data;
|
||||
this.itemStack = null;
|
||||
}
|
||||
|
||||
public SPacketFluidUpdate(Map<Integer, IAEFluidStack> data, IAEItemStack itemStack) {
|
||||
this.list = data;
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
public SPacketFluidUpdate(Map<Integer, IAEFluidStack> data, ItemStack itemStack) {
|
||||
this.list = data;
|
||||
this.itemStack = AEItemStack.create(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +45,7 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
int size = buf.readInt();
|
||||
this.list = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < size; i ++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int id = buf.readInt();
|
||||
boolean isNull = buf.readBoolean();
|
||||
if (!isNull)
|
||||
@@ -43,6 +55,9 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
list.put(id, fluid);
|
||||
}
|
||||
}
|
||||
if (buf.readBoolean()) {
|
||||
this.itemStack = AEItemStack.loadItemStackFromPacket(buf);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -61,6 +76,13 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
fs.getValue().writeToPacket(buf);
|
||||
}
|
||||
}
|
||||
if (this.itemStack != null) {
|
||||
buf.writeBoolean(true);
|
||||
this.itemStack.writeToPacket(buf);
|
||||
} else {
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -86,8 +108,14 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
( (GuiFluidIO) gs ).update(e.getKey(), e.getValue());
|
||||
}
|
||||
} else if (gs instanceof GuiFluidInterface) {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet() ) {
|
||||
( (GuiFluidInterface) gs ).update(e.getKey(), e.getValue());
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet()) {
|
||||
((GuiFluidInterface) gs).update(e.getKey(), e.getValue());
|
||||
}
|
||||
} else if (gs instanceof GuiFluidTerminal) {
|
||||
if (message.itemStack != null) {
|
||||
((GuiFluidTerminal) gs).update(message.itemStack.getItemStack());
|
||||
} else {
|
||||
((GuiFluidTerminal) gs).update(null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.client.gui.GuiFCBaseFluidMonitor;
|
||||
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
@@ -18,27 +21,39 @@ import java.util.List;
|
||||
|
||||
public class SPacketMEInventoryUpdate implements IMessage {
|
||||
|
||||
private List<IAEItemStack> list;
|
||||
private List<Object> list;
|
||||
private byte ref;
|
||||
private boolean isFluid = false;
|
||||
|
||||
public SPacketMEInventoryUpdate() {
|
||||
ref = 0;
|
||||
list = new LinkedList<>();
|
||||
}
|
||||
|
||||
public SPacketMEInventoryUpdate(Boolean isFluid) {
|
||||
ref = 0;
|
||||
list = new LinkedList<>();
|
||||
this.isFluid = isFluid;
|
||||
}
|
||||
|
||||
public SPacketMEInventoryUpdate(byte b) {
|
||||
this.ref = b;
|
||||
ref = b;
|
||||
list = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
isFluid = buf.readBoolean();
|
||||
long amount = buf.readLong();
|
||||
ref = buf.readByte();
|
||||
list = new LinkedList<>();
|
||||
try {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
list.add(AEItemStack.loadItemStackFromPacket(buf));
|
||||
if (isFluid) {
|
||||
list.add(AEFluidStack.loadFluidStackFromPacket(buf));
|
||||
} else {
|
||||
list.add(AEItemStack.loadItemStackFromPacket(buf));
|
||||
}
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
@@ -47,18 +62,28 @@ public class SPacketMEInventoryUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
if (isFluid) {
|
||||
buf.writeBoolean(true);
|
||||
} else {
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
buf.writeLong(list.size());
|
||||
buf.writeByte(ref);
|
||||
try {
|
||||
for (IAEItemStack itemStack : list) {
|
||||
itemStack.writeToPacket(buf);
|
||||
for (Object is : list) {
|
||||
if (is instanceof IAEItemStack) ((IAEItemStack) is).writeToPacket(buf);
|
||||
if (is instanceof IAEFluidStack) ((IAEFluidStack) is).writeToPacket(buf);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void appendItem( final IAEItemStack is ) throws BufferOverflowException {
|
||||
public void appendItem(final IAEItemStack is) throws BufferOverflowException {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
public void appendFluid(final IAEFluidStack is) throws BufferOverflowException {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
@@ -71,12 +96,12 @@ public class SPacketMEInventoryUpdate implements IMessage {
|
||||
@Override
|
||||
public IMessage onMessage(SPacketMEInventoryUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if( gs instanceof GuiFCBaseMonitor)
|
||||
{
|
||||
( (GuiFCBaseMonitor) gs ).postUpdate(message.list);
|
||||
}
|
||||
else if ( gs instanceof GuiFluidCraftConfirm) {
|
||||
( (GuiFluidCraftConfirm) gs ).postUpdate( message.list, message.ref );
|
||||
if (gs instanceof GuiFCBaseFluidMonitor) {
|
||||
((GuiFCBaseFluidMonitor) gs).postUpdate((List<IAEFluidStack>) (List<?>) message.list);
|
||||
} else if (gs instanceof GuiFCBaseMonitor) {
|
||||
((GuiFCBaseMonitor) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list, message.ref);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user