mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 06:53:24 +00:00
More packety fun.
This commit is contained in:
1 parent
bd83138a7a
commit
d661be1f70
22 files changed
+379
-481
No files matched your search
@@ -47,7 +47,6 @@ public class ClientProxy extends CommonProxy {
|
||||
// @formatter:on
|
||||
|
||||
static {
|
||||
// AbstractMachineBlock.initIcon();
|
||||
// RedstoneConduit.initIcons();
|
||||
// InsulatedRedstoneConduit.initIcons();
|
||||
// RedstoneSwitch.initIcons();
|
||||
|
||||
@@ -18,6 +18,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import crazypants.enderio.enderface.BlockEnderIO;
|
||||
import crazypants.enderio.enderface.ItemEnderface;
|
||||
import crazypants.enderio.machine.MachineRecipes;
|
||||
import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.alloy.AlloyRecipeManager;
|
||||
import crazypants.enderio.machine.alloy.BlockAlloySmelter;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
@@ -195,6 +196,7 @@ public class EnderIO {
|
||||
|
||||
packetPipeline.initalise();
|
||||
packetPipeline.registerPacket(PacketTileEntity.class);
|
||||
packetPipeline.registerPacket(PacketRedstoneMode.class);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(this, guiHandler);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
@@ -222,8 +224,6 @@ public class EnderIO {
|
||||
new WeightedRandomChestContent(new ItemStack(EnderIO.itemAlloy, 1, Alloy.PHASED_GOLD.ordinal()), 2, 6, 10));
|
||||
ChestGenHooks.getInfo(ChestGenHooks.VILLAGE_BLACKSMITH).addItem(new WeightedRandomChestContent(staff, 1, 1, 5));
|
||||
ChestGenHooks.getInfo(ChestGenHooks.PYRAMID_DESERT_CHEST).addItem(new WeightedRandomChestContent(staff, 1, 1, 20));
|
||||
//
|
||||
// PacketHandler.instance.addPacketProcessor(new RedstoneModePacketProcessor());
|
||||
|
||||
// EnderfaceRecipes.addRecipes();
|
||||
MaterialRecipes.addRecipes();
|
||||
|
||||
@@ -1,57 +1,80 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class RedstoneModeButton extends IconButtonEIO {
|
||||
|
||||
private static IconEIO[] ICONS = new IconEIO[] { IconEIO.REDSTONE_MODE_ALWAYS, IconEIO.REDSTONE_MODE_WITH_SIGNAL, IconEIO.REDSTONE_MODE_WITHOUT_SIGNAL,
|
||||
IconEIO.REDSTONE_MODE_NEVER };
|
||||
|
||||
//TODO:1.7
|
||||
public RedstoneModeButton(IGuiScreen gui, int id, int x, int y, IconEIO icon) {
|
||||
super(gui, id, x, y, icon);
|
||||
IRedstoneModeControlable model;
|
||||
RedstoneControlMode curMode;
|
||||
|
||||
BlockCoord bc;
|
||||
|
||||
String tooltipKey = "enderio.gui.tooltip.redstoneControlMode";
|
||||
|
||||
public RedstoneModeButton(IGuiScreen gui, int id, int x, int y, IRedstoneModeControlable model) {
|
||||
this(gui, id, x, y, model, null);
|
||||
}
|
||||
|
||||
// IRedstoneModeControlable model;
|
||||
// RedstoneControlMode curMode;
|
||||
//
|
||||
// public RedstoneModeButton(IGuiScreen gui, int id, int x, int y, IRedstoneModeControlable model) {
|
||||
// super(gui, id, x, y, ICONS[model.getRedstoneControlMode().ordinal()]);
|
||||
// this.model = model;
|
||||
// curMode = model.getRedstoneControlMode();
|
||||
// setToolTip(Lang.localize("gui.tooltip.redstoneControlMode"), curMode.getTooltip());
|
||||
// setIcon(ICONS[curMode.ordinal()]);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
// boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
// if(result) {
|
||||
// nextMode();
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private void nextMode() {
|
||||
// if(curMode == null) {
|
||||
// curMode = RedstoneControlMode.ON;
|
||||
// }
|
||||
// setMode(curMode.next());
|
||||
// }
|
||||
//
|
||||
// public void setMode(RedstoneControlMode mode) {
|
||||
// if(mode == curMode) {
|
||||
// return;
|
||||
// }
|
||||
// curMode = mode;
|
||||
// setToolTip(Lang.localize("gui.tooltip.redstoneControlMode"), mode.getTooltip());
|
||||
// setIcon(ICONS[mode.ordinal()]);
|
||||
// model.setRedstoneControlMode(mode);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
// super.drawButton(mc, mouseX, mouseY);
|
||||
// }
|
||||
public RedstoneModeButton(IGuiScreen gui, int id, int x, int y, IRedstoneModeControlable model, BlockCoord bc) {
|
||||
super(gui, id, x, y, ICONS[model.getRedstoneControlMode().ordinal()]);
|
||||
this.model = model;
|
||||
this.bc = bc;
|
||||
curMode = model.getRedstoneControlMode();
|
||||
setToolTip(Lang.localize("gui.tooltip.redstoneControlMode"), curMode.getTooltip());
|
||||
setIcon(ICONS[curMode.ordinal()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if(result) {
|
||||
nextMode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTooltipKey() {
|
||||
return tooltipKey;
|
||||
}
|
||||
|
||||
public void setTooltipKey(String tooltipKey) {
|
||||
this.tooltipKey = tooltipKey;
|
||||
setToolTip(Lang.localize(tooltipKey, false), model.getRedstoneControlMode().getTooltip());
|
||||
}
|
||||
|
||||
private void nextMode() {
|
||||
if(curMode == null) {
|
||||
curMode = RedstoneControlMode.ON;
|
||||
}
|
||||
setMode(curMode.next());
|
||||
}
|
||||
|
||||
public void setMode(RedstoneControlMode mode) {
|
||||
if(mode == curMode) {
|
||||
return;
|
||||
}
|
||||
curMode = mode;
|
||||
setToolTip(Lang.localize(tooltipKey, false), mode.getTooltip());
|
||||
setIcon(ICONS[mode.ordinal()]);
|
||||
model.setRedstoneControlMode(mode);
|
||||
if(bc != null) {
|
||||
EnderIO.packetPipeline.sendToServer(new PacketRedstoneMode(model, bc.x, bc.y, bc.z));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -25,39 +24,10 @@ import crazypants.enderio.ClientProxy;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> extends BlockContainer implements IGuiHandler {
|
||||
|
||||
public static final IIcon[] REDSTONE_CONTROL_ICONS = new IIcon[RedstoneControlMode.values().length];
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void initIcon() {
|
||||
IconUtil.addIconProvider(new IconUtil.IIconProvider() {
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister IIconRegister) {
|
||||
REDSTONE_CONTROL_ICONS[RedstoneControlMode.IGNORE.ordinal()] = IIconRegister.registerIcon("enderio:iconRedstoneIgnore");
|
||||
REDSTONE_CONTROL_ICONS[RedstoneControlMode.ON.ordinal()] = IIconRegister.registerIcon("enderio:iconRedstoneOn");
|
||||
REDSTONE_CONTROL_ICONS[RedstoneControlMode.OFF.ordinal()] = IIconRegister.registerIcon("enderio:iconRedstoneOff");
|
||||
REDSTONE_CONTROL_ICONS[RedstoneControlMode.NEVER.ordinal()] = IIconRegister.registerIcon("enderio:iconRedstoneNever");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getRedstoneControlIcon(RedstoneControlMode mode) {
|
||||
return REDSTONE_CONTROL_ICONS[mode.ordinal()];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected IIcon[][] iconBuffer;
|
||||
|
||||
@@ -180,18 +150,6 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
|
||||
}
|
||||
|
||||
//TODO:1.7 is this the correct mapping?
|
||||
@Override
|
||||
public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) {
|
||||
//return Item.getItemFromBlock(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public int idDropped(int par1, Random par2Random, int par3) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
|
||||
@@ -7,12 +7,11 @@ import net.minecraft.inventory.Container;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.gui.IconButton;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
|
||||
@@ -23,11 +22,10 @@ public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
protected static final int BOTTOM_POWER_Y = POWER_Y + POWER_HEIGHT;
|
||||
|
||||
public static final int BUTTON_SIZE = 16;
|
||||
protected static final int REDSTONE_BUTTON_ID = 99;
|
||||
|
||||
private AbstractMachineEntity tileEntity;
|
||||
|
||||
private IconButton redstoneButton;
|
||||
private RedstoneModeButton redstoneButton;
|
||||
|
||||
public GuiMachineBase(AbstractMachineEntity machine, Container container) {
|
||||
super(container);
|
||||
@@ -42,53 +40,15 @@ public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
}
|
||||
|
||||
});
|
||||
addToolTip(new GuiToolTip(new Rectangle(0, 0, 0, 0), "") {
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(Lang.localize("gui.tooltip.redstoneControlMode"));
|
||||
text.add(tileEntity.getRedstoneControlMode().getTooltip());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(int mouseX, int mouseY) {
|
||||
bounds.setBounds(xSize - 5 - BUTTON_SIZE, 5, BUTTON_SIZE, BUTTON_SIZE);
|
||||
super.onTick(mouseX, mouseY);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == REDSTONE_BUTTON_ID) {
|
||||
int ordinal = tileEntity.getRedstoneControlMode().ordinal();
|
||||
ordinal++;
|
||||
if(ordinal >= RedstoneControlMode.values().length) {
|
||||
ordinal = 0;
|
||||
}
|
||||
tileEntity.setRedstoneControlMode(RedstoneControlMode.values()[ordinal]);
|
||||
redstoneButton.setIcon(AbstractMachineBlock.getRedstoneControlIcon(tileEntity.getRedstoneControlMode()));
|
||||
//TODO:1.7
|
||||
// Packet pkt = RedstoneModePacketProcessor.getRedstoneControlPacket(tileEntity);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
int x = xSize - 5 - BUTTON_SIZE;
|
||||
int y = 5;
|
||||
redstoneButton = new RedstoneModeButton(this, -1, x, y, tileEntity, new BlockCoord(tileEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int x = guiLeft + xSize - 5 - BUTTON_SIZE;
|
||||
int y = guiTop + 5;
|
||||
|
||||
redstoneButton = new IconButton(getFontRenderer(), REDSTONE_BUTTON_ID, x, y, AbstractMachineBlock.getRedstoneControlIcon(tileEntity
|
||||
.getRedstoneControlMode()),
|
||||
RenderUtil.BLOCK_TEX);
|
||||
redstoneButton.setSize(BUTTON_SIZE, BUTTON_SIZE);
|
||||
|
||||
buttonList.add(redstoneButton);
|
||||
redstoneButton.onGuiInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import crazypants.enderio.network.IPacketEio;
|
||||
|
||||
public class PacketRedstoneMode implements IPacketEio {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private RedstoneControlMode mode;
|
||||
|
||||
public PacketRedstoneMode() {
|
||||
}
|
||||
|
||||
public PacketRedstoneMode(IRedstoneModeControlable cont, int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
mode = cont.getRedstoneControlMode();
|
||||
}
|
||||
|
||||
public PacketRedstoneMode(AbstractMachineEntity ent) {
|
||||
x = ent.xCoord;
|
||||
y = ent.yCoord;
|
||||
z = ent.zCoord;
|
||||
mode = ent.getRedstoneControlMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeShort((short) mode.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
short ordinal = buf.readShort();
|
||||
mode = RedstoneControlMode.values()[ordinal];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
private void handle(EntityPlayer player) {
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof IRedstoneModeControlable) {
|
||||
IRedstoneModeControlable me = (IRedstoneModeControlable) te;
|
||||
me.setRedstoneControlMode(mode);
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// public static Packet getRedstoneControlPacket(TileCapacitorBank te) {
|
||||
// ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
|
||||
// DataOutputStream dos = new DataOutputStream(bos);
|
||||
// try {
|
||||
// dos.writeInt(PacketHandler.ID_CAP_BANK_REDSTONE_PACKET);
|
||||
// dos.writeInt(te.xCoord);
|
||||
// dos.writeInt(te.yCoord);
|
||||
// dos.writeInt(te.zCoord);
|
||||
// dos.writeShort((short) te.getInputControlMode().ordinal());
|
||||
// dos.writeShort((short) te.getOutputControlMode().ordinal());
|
||||
// } catch (IOException e) {
|
||||
// // never thrown
|
||||
// }
|
||||
//
|
||||
// Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
// pkt.channel = PacketHandler.CHANNEL;
|
||||
// pkt.data = bos.toByteArray();
|
||||
// pkt.length = bos.size();
|
||||
// pkt.isChunkDataPacket = true;
|
||||
// return pkt;
|
||||
// }
|
||||
//
|
||||
// private void handleCapBankRedstoneControlPacket(DataInputStream data, INetworkManager manager, Player player) throws IOException {
|
||||
// int x = data.readInt();
|
||||
// int y = data.readInt();
|
||||
// int z = data.readInt();
|
||||
// short inputOrdinal = data.readShort();
|
||||
// short outputOrdinal = data.readShort();
|
||||
// EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
// TileEntity te = p.worldObj.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapacitorBank) {
|
||||
// TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
// cb.setInputControlMode(RedstoneControlMode.values()[inputOrdinal]);
|
||||
// cb.setOutputControlMode(RedstoneControlMode.values()[outputOrdinal]);
|
||||
// p.worldObj.markBlockForUpdate(x, y, z);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import crazypants.enderio.IPacketProcessor;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.PacketHandler;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
|
||||
public class RedstoneModePacketProcessor implements IPacketProcessor {
|
||||
|
||||
public static Packet getRedstoneControlPacket(AbstractMachineEntity te) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeInt(PacketHandler.ID_MACHINE_REDSTONE_PACKET);
|
||||
dos.writeInt(te.xCoord);
|
||||
dos.writeInt(te.yCoord);
|
||||
dos.writeInt(te.zCoord);
|
||||
dos.writeShort((short) te.getRedstoneControlMode().ordinal());
|
||||
} catch (IOException e) {
|
||||
// never thrown
|
||||
}
|
||||
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.channel = PacketHandler.CHANNEL;
|
||||
pkt.data = bos.toByteArray();
|
||||
pkt.length = bos.size();
|
||||
pkt.isChunkDataPacket = true;
|
||||
return pkt;
|
||||
|
||||
}
|
||||
|
||||
public static Packet getRedstoneControlPacket(TileCapacitorBank te) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeInt(PacketHandler.ID_CAP_BANK_REDSTONE_PACKET);
|
||||
dos.writeInt(te.xCoord);
|
||||
dos.writeInt(te.yCoord);
|
||||
dos.writeInt(te.zCoord);
|
||||
dos.writeShort((short) te.getInputControlMode().ordinal());
|
||||
dos.writeShort((short) te.getOutputControlMode().ordinal());
|
||||
} catch (IOException e) {
|
||||
// never thrown
|
||||
}
|
||||
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.channel = PacketHandler.CHANNEL;
|
||||
pkt.data = bos.toByteArray();
|
||||
pkt.length = bos.size();
|
||||
pkt.isChunkDataPacket = true;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProcessPacket(int packetID) {
|
||||
return packetID == PacketHandler.ID_MACHINE_REDSTONE_PACKET || packetID == PacketHandler.ID_CAP_BANK_REDSTONE_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(int id, INetworkManager manager, DataInputStream data, Player player) throws IOException {
|
||||
if(id == PacketHandler.ID_MACHINE_REDSTONE_PACKET) {
|
||||
handleRedstoneControlPacket(data, manager, player);
|
||||
} else if(id == PacketHandler.ID_CAP_BANK_REDSTONE_PACKET) {
|
||||
handleCapBankRedstoneControlPacket(data, manager, player);
|
||||
|
||||
} else {
|
||||
Log.warn("RedstoneModePacketProcessor: Recieved unknow packet: " + id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleRedstoneControlPacket(DataInputStream data, INetworkManager manager, Player player) throws IOException {
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
short ordinal = data.readShort();
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
TileEntity te = p.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof AbstractMachineEntity) {
|
||||
AbstractMachineEntity me = (AbstractMachineEntity) te;
|
||||
me.setRedstoneControlMode(RedstoneControlMode.values()[ordinal]);
|
||||
p.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleCapBankRedstoneControlPacket(DataInputStream data, INetworkManager manager, Player player) throws IOException {
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
short inputOrdinal = data.readShort();
|
||||
short outputOrdinal = data.readShort();
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
TileEntity te = p.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapacitorBank) {
|
||||
TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
cb.setInputControlMode(RedstoneControlMode.values()[inputOrdinal]);
|
||||
cb.setOutputControlMode(RedstoneControlMode.values()[outputOrdinal]);
|
||||
p.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package crazypants.enderio.machine.alloy;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import crazypants.enderio.IPacketProcessor;
|
||||
import crazypants.enderio.PacketHandler;
|
||||
|
||||
public class AlloySmelterPacketProcessor implements IPacketProcessor {
|
||||
|
||||
@Override
|
||||
public boolean canProcessPacket(int packetID) {
|
||||
return packetID == PacketHandler.ID_ALLOY_SMELTING_MODE_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(int packetID, INetworkManager manager, DataInputStream data, Player player) throws IOException {
|
||||
handleSmeltingModePacket(data, manager, player);
|
||||
}
|
||||
|
||||
private void handleSmeltingModePacket(DataInputStream data, INetworkManager manager, Player player) throws IOException {
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
short val = data.readShort();
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
TileEntity te = p.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof TileAlloySmelter) {
|
||||
TileAlloySmelter me = (TileAlloySmelter) te;
|
||||
me.setMode(TileAlloySmelter.Mode.values()[val]);
|
||||
p.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Packet getSmeltingModePacket(TileAlloySmelter te) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeInt(PacketHandler.ID_ALLOY_SMELTING_MODE_PACKET);
|
||||
dos.writeInt(te.xCoord);
|
||||
dos.writeInt(te.yCoord);
|
||||
dos.writeInt(te.zCoord);
|
||||
dos.writeShort(te.getMode().ordinal());
|
||||
} catch (IOException e) {
|
||||
// never thrown
|
||||
}
|
||||
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.channel = PacketHandler.CHANNEL;
|
||||
pkt.data = bos.toByteArray();
|
||||
pkt.length = bos.size();
|
||||
pkt.isChunkDataPacket = true;
|
||||
return pkt;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
@@ -12,8 +13,9 @@ import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
public class BlockAlloySmelter extends AbstractMachineBlock<TileAlloySmelter> {
|
||||
|
||||
public static BlockAlloySmelter create() {
|
||||
//TODO:1.7
|
||||
//PacketHandler.instance.addPacketProcessor(new AlloySmelterPacketProcessor());
|
||||
|
||||
EnderIO.packetPipeline.registerPacket(PacketClientState.class);
|
||||
|
||||
BlockAlloySmelter ppainter = new BlockAlloySmelter();
|
||||
ppainter.init();
|
||||
return ppainter;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class GuiAlloySmelter extends GuiMachineBase {
|
||||
|
||||
private IconButton vanillaFurnaceButton;
|
||||
|
||||
protected static final int SMELT_MODE_BUTTON_ID = REDSTONE_BUTTON_ID + 1;
|
||||
protected static final int SMELT_MODE_BUTTON_ID = 76;
|
||||
|
||||
public GuiAlloySmelter(InventoryPlayer par1InventoryPlayer, TileAlloySmelter furnaceInventory) {
|
||||
super(furnaceInventory, new ContainerAlloySmelter(par1InventoryPlayer, furnaceInventory));
|
||||
@@ -70,9 +70,7 @@ public class GuiAlloySmelter extends GuiMachineBase {
|
||||
if(par1GuiButton.id == SMELT_MODE_BUTTON_ID) {
|
||||
tileEntity.setMode(tileEntity.getMode().next());
|
||||
vanillaFurnaceButton.setIcon(getIconForMode());
|
||||
//TODO:1.7
|
||||
// Packet pkt = AlloySmelterPacketProcessor.getSmeltingModePacket(tileEntity);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
EnderIO.packetPipeline.sendToServer(new PacketClientState(tileEntity));
|
||||
} else {
|
||||
super.actionPerformed(par1GuiButton);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package crazypants.enderio.machine.alloy;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import crazypants.enderio.network.IPacketEio;
|
||||
|
||||
public class PacketClientState implements IPacketEio {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
private TileAlloySmelter.Mode mode;
|
||||
|
||||
public PacketClientState() {
|
||||
|
||||
}
|
||||
|
||||
public PacketClientState(TileAlloySmelter tile) {
|
||||
x = tile.xCoord;
|
||||
y = tile.yCoord;
|
||||
z = tile.zCoord;
|
||||
mode = tile.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeShort(mode.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
short ordinal = buf.readShort();
|
||||
mode = TileAlloySmelter.Mode.values()[ordinal];
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
private void handle(EntityPlayer player) {
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof TileAlloySmelter) {
|
||||
TileAlloySmelter me = (TileAlloySmelter) te;
|
||||
me.setMode(mode);
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import crazypants.gui.GuiToolTip;
|
||||
import crazypants.gui.ListSelectionListener;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class GuiHyperCube extends GuiScreenBase {
|
||||
@@ -138,7 +139,7 @@ public class GuiHyperCube extends GuiScreenBase {
|
||||
// return cube.getRedstoneControlMode();
|
||||
// }
|
||||
// });
|
||||
rsB = new RedstoneModeButton(this, 99, x, y, IconEIO.REDSTONE_MODE_ALWAYS);
|
||||
rsB = new RedstoneModeButton(this, 99, x, y, te, new BlockCoord(te));
|
||||
|
||||
updateIoButtons();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import buildcraft.api.power.PowerHandler.Type;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
@@ -34,7 +35,7 @@ import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public class TileHyperCube extends TileEntityEio implements IInternalPowerReceptor, IFluidHandler, ISidedInventory {
|
||||
public class TileHyperCube extends TileEntityEio implements IInternalPowerReceptor, IFluidHandler, ISidedInventory, IRedstoneModeControlable {
|
||||
|
||||
private static final float ENERGY_LOSS = (float) Config.transceiverEnergyLoss;
|
||||
|
||||
@@ -138,10 +139,12 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerRecept
|
||||
recieveBuffer = new ItemRecieveBuffer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return redstoneControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstoneControlMode(RedstoneControlMode redstoneControlMode) {
|
||||
this.redstoneControlMode = redstoneControlMode;
|
||||
redstoneStateDirty = true;
|
||||
|
||||
@@ -36,13 +36,10 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler {
|
||||
public static int renderId = -1;
|
||||
|
||||
public static BlockCapacitorBank create() {
|
||||
EnderIO.packetPipeline.registerPacket(PacketClientState.class);
|
||||
|
||||
BlockCapacitorBank res = new BlockCapacitorBank();
|
||||
res.init();
|
||||
|
||||
//TODO:1.7
|
||||
//CapacitorBankPacketHandler pp = new CapacitorBankPacketHandler();
|
||||
//PacketHandler.instance.addPacketProcessor(pp);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package crazypants.enderio.machine.power;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import crazypants.enderio.IPacketProcessor;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.PacketHandler;
|
||||
|
||||
public class CapacitorBankPacketHandler implements IPacketProcessor {
|
||||
|
||||
public CapacitorBankPacketHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProcessPacket(int packetID) {
|
||||
return packetID == PacketHandler.ID_CAP_BANK_IO_PACKET;
|
||||
}
|
||||
|
||||
public static Packet createMaxInputOutputPacket(TileCapacitorBank cb) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeInt(PacketHandler.ID_CAP_BANK_IO_PACKET);
|
||||
dos.writeInt(cb.xCoord);
|
||||
dos.writeInt(cb.yCoord);
|
||||
dos.writeInt(cb.zCoord);
|
||||
dos.writeInt(cb.getMaxInput());
|
||||
dos.writeInt(cb.getMaxOutput());
|
||||
} catch (IOException e) {
|
||||
// never thrown
|
||||
}
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.channel = PacketHandler.CHANNEL;
|
||||
pkt.data = bos.toByteArray();
|
||||
pkt.length = bos.size();
|
||||
pkt.isChunkDataPacket = true;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(int packetID, INetworkManager manager, DataInputStream data, Player player) throws IOException {
|
||||
if(!(player instanceof EntityPlayer)) {
|
||||
Log.warn("CapacitorBankPacketHandler:handleChannelSelectedPacket: Could not handle packet as player not an entity player.");
|
||||
return;
|
||||
}
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
if(world == null) {
|
||||
Log.warn("CapacitorBankPacketHandler:handleChannelSelectedPacket: Could not handle packet as player world was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapacitorBank)) {
|
||||
Log.warn("CapacitorBankPacketHandler:handleChannelSelectedPacket: Could not handle packet as TileEntity was not a CapacitorBank.");
|
||||
return;
|
||||
}
|
||||
TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
cb.setMaxInput(data.readInt());
|
||||
cb.setMaxOutput(data.readInt());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,12 +11,13 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.GuiMachineBase;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.gui.IconButton;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
@@ -41,8 +42,10 @@ public class GuiCapacitorBank extends GuiContainerBase {
|
||||
|
||||
private final TileCapacitorBank capBank;
|
||||
|
||||
private IconButton inputRedstoneButton;
|
||||
private IconButton outputRedstoneButton;
|
||||
// private IconButton inputRedstoneButton;
|
||||
// private IconButton outputRedstoneButton;
|
||||
private RedstoneModeButton inputRsButton;
|
||||
private RedstoneModeButton outputRsButton;
|
||||
|
||||
private GuiTextField maxInputTF;
|
||||
private GuiTextField maxOutputTF;
|
||||
@@ -62,93 +65,51 @@ public class GuiCapacitorBank extends GuiContainerBase {
|
||||
|
||||
});
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(0, 0, 0, 0), "") {
|
||||
int x = xSize - rightMargin - GuiMachineBase.BUTTON_SIZE;
|
||||
int y = inputY;
|
||||
inputRsButton = new RedstoneModeButton(this, -1, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(Lang.localize("gui.capBank.inputRs"));
|
||||
text.add(capBank.getInputControlMode().getTooltip());
|
||||
public void setRedstoneControlMode(RedstoneControlMode mode) {
|
||||
capBank.setInputControlMode(mode);
|
||||
EnderIO.packetPipeline.sendToServer(new PacketClientState(capBank));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(int mouseX, int mouseY) {
|
||||
bounds.setBounds(xSize - rightMargin - GuiMachineBase.BUTTON_SIZE, inputY, GuiMachineBase.BUTTON_SIZE, GuiMachineBase.BUTTON_SIZE);
|
||||
super.onTick(mouseX, mouseY);
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return capBank.getInputControlMode();
|
||||
}
|
||||
|
||||
});
|
||||
inputRsButton.setTooltipKey("enderio.gui.capBank.inputRs");
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(0, 0, 0, 0), "") {
|
||||
y += 20;
|
||||
outputRsButton = new RedstoneModeButton(this, -1, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(Lang.localize("gui.capBank.outputRs"));
|
||||
text.add(capBank.getOutputControlMode().getTooltip());
|
||||
public void setRedstoneControlMode(RedstoneControlMode mode) {
|
||||
capBank.setOutputControlMode(mode);
|
||||
EnderIO.packetPipeline.sendToServer(new PacketClientState(capBank));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(int mouseX, int mouseY) {
|
||||
bounds.setBounds(xSize - rightMargin - GuiMachineBase.BUTTON_SIZE, outputY, GuiMachineBase.BUTTON_SIZE, GuiMachineBase.BUTTON_SIZE);
|
||||
super.onTick(mouseX, mouseY);
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return capBank.getOutputControlMode();
|
||||
}
|
||||
|
||||
});
|
||||
outputRsButton.setTooltipKey("enderio.gui.capBank.outputRs");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == INPUT_BUTTON_ID) {
|
||||
int ordinal = capBank.getInputControlMode().ordinal();
|
||||
ordinal++;
|
||||
if(ordinal >= RedstoneControlMode.values().length) {
|
||||
ordinal = 0;
|
||||
}
|
||||
capBank.setInputControlMode(RedstoneControlMode.values()[ordinal]);
|
||||
inputRedstoneButton.setIcon(AbstractMachineBlock.getRedstoneControlIcon(capBank.getInputControlMode()));
|
||||
//TODO:1.7
|
||||
// Packet pkt = RedstoneModePacketProcessor.getRedstoneControlPacket(capBank);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
} else if(par1GuiButton.id == OUTPUT_BUTTON_ID) {
|
||||
int ordinal = capBank.getOutputControlMode().ordinal();
|
||||
ordinal++;
|
||||
if(ordinal >= RedstoneControlMode.values().length) {
|
||||
ordinal = 0;
|
||||
}
|
||||
capBank.setOutputControlMode(RedstoneControlMode.values()[ordinal]);
|
||||
outputRedstoneButton.setIcon(AbstractMachineBlock.getRedstoneControlIcon(capBank.getOutputControlMode()));
|
||||
//TODO:1.7
|
||||
// Packet pkt = RedstoneModePacketProcessor.getRedstoneControlPacket(capBank);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int x = guiLeft + xSize - rightMargin - GuiMachineBase.BUTTON_SIZE;
|
||||
//int y = guiTop + 5;
|
||||
int y = guiTop + inputY;
|
||||
|
||||
FontRenderer fontRenderer = getFontRenderer();
|
||||
inputRedstoneButton = new IconButton(fontRenderer, INPUT_BUTTON_ID, x, y, AbstractMachineBlock.getRedstoneControlIcon(capBank.getInputControlMode()),
|
||||
RenderUtil.BLOCK_TEX);
|
||||
inputRedstoneButton.setSize(GuiMachineBase.BUTTON_SIZE, GuiMachineBase.BUTTON_SIZE);
|
||||
buttonList.add(inputRedstoneButton);
|
||||
|
||||
//y = y + 5 + GuiMachineBase.BUTTON_SIZE;
|
||||
y = guiTop + outputY;
|
||||
outputRedstoneButton = new IconButton(fontRenderer, OUTPUT_BUTTON_ID, x, y, AbstractMachineBlock.getRedstoneControlIcon(capBank.getOutputControlMode()),
|
||||
RenderUtil.BLOCK_TEX);
|
||||
outputRedstoneButton.setSize(GuiMachineBase.BUTTON_SIZE, GuiMachineBase.BUTTON_SIZE);
|
||||
buttonList.add(outputRedstoneButton);
|
||||
inputRsButton.onGuiInit();
|
||||
outputRsButton.onGuiInit();
|
||||
|
||||
x = guiLeft + inputX;
|
||||
y = guiTop + inputY;
|
||||
@@ -179,37 +140,30 @@ public class GuiCapacitorBank extends GuiContainerBase {
|
||||
}
|
||||
|
||||
private void updateInputOutput() {
|
||||
|
||||
int input = parsePower(maxInputTF);
|
||||
if(input >= 0 && capBank.getMaxInput() != input) {
|
||||
setMaxInput(input);
|
||||
}
|
||||
|
||||
int output = parsePower(maxOutputTF);
|
||||
if(output >= 0 && capBank.getMaxOutput() != output) {
|
||||
setMaxOutput(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setMaxOutput(int output) {
|
||||
capBank.setMaxOutput(output);
|
||||
if(output != capBank.getMaxOutput()) {
|
||||
capBank.setMaxOutput(output);
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(capBank.getMaxOutput()));
|
||||
EnderIO.packetPipeline.sendToServer(new PacketClientState(capBank));
|
||||
}
|
||||
//TODO:1.7
|
||||
// Packet pkt = CapacitorBankPacketHandler.createMaxInputOutputPacket(capBank);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
|
||||
private void setMaxInput(int input) {
|
||||
capBank.setMaxInput(input);
|
||||
if(input != capBank.getMaxInput()) {
|
||||
capBank.setMaxInput(input);
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(capBank.getMaxInput()));
|
||||
EnderIO.packetPipeline.sendToServer(new PacketClientState(capBank));
|
||||
}
|
||||
//TODO:1.7
|
||||
// Packet pkt = CapacitorBankPacketHandler.createMaxInputOutputPacket(capBank);
|
||||
// PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
|
||||
private int parsePower(GuiTextField tf) {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package crazypants.enderio.machine.power;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.network.IPacketEio;
|
||||
|
||||
public class PacketClientState implements IPacketEio {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private RedstoneControlMode inputMode;
|
||||
private RedstoneControlMode outputMode;
|
||||
private int maxInput;
|
||||
private int maxOutput;
|
||||
|
||||
public PacketClientState() {
|
||||
}
|
||||
|
||||
public PacketClientState(TileCapacitorBank capBank) {
|
||||
x = capBank.xCoord;
|
||||
y = capBank.yCoord;
|
||||
z = capBank.zCoord;
|
||||
|
||||
inputMode = capBank.getInputControlMode();
|
||||
outputMode = capBank.getOutputControlMode();
|
||||
|
||||
maxInput = capBank.getMaxInput();
|
||||
maxOutput = capBank.getMaxOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, ByteBuf dos) {
|
||||
dos.writeInt(x);
|
||||
dos.writeInt(y);
|
||||
dos.writeInt(z);
|
||||
dos.writeShort((short) inputMode.ordinal());
|
||||
dos.writeShort((short) outputMode.ordinal());
|
||||
dos.writeInt(maxInput);
|
||||
dos.writeInt(maxOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf data) {
|
||||
x = data.readInt();
|
||||
y = data.readInt();
|
||||
z = data.readInt();
|
||||
short inputOrdinal = data.readShort();
|
||||
short outputOrdinal = data.readShort();
|
||||
outputMode = RedstoneControlMode.values()[outputOrdinal];
|
||||
inputMode = RedstoneControlMode.values()[inputOrdinal];
|
||||
|
||||
maxInput = data.readInt();
|
||||
maxOutput = data.readInt();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
private void handle(EntityPlayer player) {
|
||||
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapacitorBank) {
|
||||
TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
cb.setInputControlMode(inputMode);
|
||||
cb.setOutputControlMode(outputMode);
|
||||
cb.setMaxInput(maxInput);
|
||||
cb.setMaxOutput(maxOutput);
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user