Merge pull request #1506 from Dimach/flask_fix
Fix flask crash on server
This commit is contained in:
commit
cf57e09437
3 changed files with 46 additions and 25 deletions
|
@ -6,7 +6,6 @@ import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import gregtech.api.enums.GT_Values;
|
import gregtech.api.enums.GT_Values;
|
||||||
import gregtech.api.net.*;
|
import gregtech.api.net.*;
|
||||||
|
@ -31,13 +30,10 @@ public class GT_Network
|
||||||
implements IGT_NetworkHandler {
|
implements IGT_NetworkHandler {
|
||||||
private final EnumMap<Side, FMLEmbeddedChannel> mChannel;
|
private final EnumMap<Side, FMLEmbeddedChannel> mChannel;
|
||||||
private final GT_Packet[] mSubChannels;
|
private final GT_Packet[] mSubChannels;
|
||||||
public final SimpleNetworkWrapper networkWrapper;
|
|
||||||
|
|
||||||
public GT_Network() {
|
public GT_Network() {
|
||||||
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("gregtech_network_wrapper");
|
|
||||||
networkWrapper.registerMessage(MessageSetFlaskCapacity.Handler.class, MessageSetFlaskCapacity.class, 0, Side.SERVER);
|
|
||||||
this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", new ChannelHandler[]{this, new HandlerShared()});
|
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()};
|
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()};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput)
|
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput)
|
||||||
|
|
|
@ -4,9 +4,9 @@ package gregtech.common.gui;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import gregtech.api.enums.GT_Values;
|
import gregtech.api.enums.GT_Values;
|
||||||
import gregtech.common.GT_Network;
|
|
||||||
import gregtech.common.items.GT_VolumetricFlask;
|
import gregtech.common.items.GT_VolumetricFlask;
|
||||||
import gregtech.common.net.MessageSetFlaskCapacity;
|
import gregtech.common.net.MessageSetFlaskCapacity;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
|
@ -115,7 +115,7 @@ public final class GT_GUIContainerVolumetricFlask extends GuiContainer {
|
||||||
protected void actionPerformed(GuiButton btn) {
|
protected void actionPerformed(GuiButton btn) {
|
||||||
try {
|
try {
|
||||||
if (btn == apply) {
|
if (btn == apply) {
|
||||||
((GT_Network) GT_Values.NW).networkWrapper.sendToServer(new MessageSetFlaskCapacity(Integer.parseInt(amount.getText())));
|
GT_Values.NW.sendToServer(new MessageSetFlaskCapacity(Integer.parseInt(amount.getText()), Minecraft.getMinecraft().thePlayer));
|
||||||
mc.thePlayer.closeScreen();
|
mc.thePlayer.closeScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,67 @@
|
||||||
package gregtech.common.net;
|
package gregtech.common.net;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import gregtech.api.net.GT_Packet;
|
||||||
import gregtech.common.items.GT_VolumetricFlask;
|
import gregtech.common.items.GT_VolumetricFlask;
|
||||||
import io.netty.buffer.ByteBuf;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
|
||||||
public final class MessageSetFlaskCapacity implements IMessage {
|
public final class MessageSetFlaskCapacity extends GT_Packet {
|
||||||
private int capacity;
|
private int capacity, dimID, playerID;
|
||||||
|
|
||||||
public MessageSetFlaskCapacity() {
|
public MessageSetFlaskCapacity() {
|
||||||
|
super(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageSetFlaskCapacity(int capacity) {
|
public MessageSetFlaskCapacity(int capacity, int dimID, int playerID) {
|
||||||
|
super(false);
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
|
this.dimID = dimID;
|
||||||
|
this.playerID = playerID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageSetFlaskCapacity(int capacity, EntityPlayer p) {
|
||||||
public void fromBytes(ByteBuf buf) {
|
super(false);
|
||||||
this.capacity = buf.readInt();
|
this.capacity = capacity;
|
||||||
|
this.dimID = p.worldObj.provider.dimensionId;
|
||||||
|
this.playerID = p.getEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf) {
|
@Override
|
||||||
buf.writeInt(this.capacity);
|
public byte getPacketID() {
|
||||||
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Handler
|
@Override
|
||||||
implements IMessageHandler<MessageSetFlaskCapacity, IMessage> {
|
public byte[] encode() {
|
||||||
public IMessage onMessage(MessageSetFlaskCapacity message, MessageContext ctx) {
|
ByteArrayDataOutput tOut = ByteStreams.newDataOutput(10);
|
||||||
ItemStack stack = ctx.getServerHandler().playerEntity.getHeldItem();
|
tOut.writeInt(capacity);
|
||||||
|
tOut.writeInt(dimID);
|
||||||
|
tOut.writeInt(playerID);
|
||||||
|
return tOut.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GT_Packet decode(ByteArrayDataInput aData) {
|
||||||
|
return new MessageSetFlaskCapacity(aData.readInt(), aData.readInt(), aData.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(IBlockAccess aWorld) {
|
||||||
|
World w = DimensionManager.getWorld(dimID);
|
||||||
|
if (w != null && w.getEntityByID(playerID) instanceof EntityPlayer) {
|
||||||
|
ItemStack stack = ((EntityPlayer) w.getEntityByID(playerID)).getHeldItem();
|
||||||
if ((stack != null) && (stack.stackSize > 0)) {
|
if ((stack != null) && (stack.stackSize > 0)) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if ((item instanceof GT_VolumetricFlask))
|
if ((item instanceof GT_VolumetricFlask))
|
||||||
((GT_VolumetricFlask) item).setCapacity(stack, message.capacity);
|
((GT_VolumetricFlask) item).setCapacity(stack, capacity);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue