mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 01:54:59 +00:00
add buffer
This commit is contained in:
1 parent
2d585bd280
commit
67abd1ec9e
21 files changed
+1895
-9
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import com.glodblock.github.client.gui.TankDumpable;
|
||||
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.EntityPlayerMP;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CPacketDumpTank implements IMessage {
|
||||
|
||||
private int index;
|
||||
|
||||
public CPacketDumpTank(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public CPacketDumpTank() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
index = buf.readShort();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketDumpTank, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketDumpTank message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if (player.openContainer instanceof TankDumpable) {
|
||||
((TankDumpable)player.openContainer).dumpTank(message.index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import com.glodblock.github.client.gui.GuiIngredientBuffer;
|
||||
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 java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SPacketFluidUpdate implements IMessage {
|
||||
|
||||
private Map<Integer, IAEFluidStack> list;
|
||||
|
||||
public SPacketFluidUpdate() {
|
||||
}
|
||||
|
||||
public SPacketFluidUpdate(Map<Integer, IAEFluidStack> data) {
|
||||
this.list = data;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketFluidUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketFluidUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if( gs instanceof GuiIngredientBuffer)
|
||||
{
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet() ) {
|
||||
( (GuiIngredientBuffer) gs ).update(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user