diff --git a/src/resonantinduction/MultipartRI.java b/src/resonantinduction/MultipartRI.java index ea8332c10..37a31f3fd 100644 --- a/src/resonantinduction/MultipartRI.java +++ b/src/resonantinduction/MultipartRI.java @@ -1,7 +1,7 @@ package resonantinduction; import resonantinduction.wire.EnumWireMaterial; -import resonantinduction.wire.multipart.PartWire; +import resonantinduction.wire.PartWire; import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultipartGenerator; diff --git a/src/resonantinduction/PacketHandler.java b/src/resonantinduction/PacketHandler.java deleted file mode 100644 index cf6749b4d..000000000 --- a/src/resonantinduction/PacketHandler.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * - */ -package resonantinduction; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import resonantinduction.base.IPacketReceiver; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; - -import cpw.mods.fml.common.network.IPacketHandler; -import cpw.mods.fml.common.network.PacketDispatcher; -import cpw.mods.fml.common.network.Player; - -/** - * @author AidanBrady - * - */ -public class PacketHandler implements IPacketHandler -{ - @Override - public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) - { - if (packet.channel.equals(ResonantInduction.CHANNEL)) - { - ByteArrayDataInput dataStream = ByteStreams.newDataInput(packet.data); - EntityPlayer entityplayer = (EntityPlayer) player; - World world = entityplayer.worldObj; - - try - { - int packetType = dataStream.readInt(); - - if (packetType == PacketType.TILE.ordinal()) - { - int x = dataStream.readInt(); - int y = dataStream.readInt(); - int z = dataStream.readInt(); - - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - - if (tileEntity instanceof IPacketReceiver) - { - ((IPacketReceiver) tileEntity).handle(dataStream); - } - } - else if (packetType == PacketType.DATA_REQUEST.ordinal()) - { - int x = dataStream.readInt(); - int y = dataStream.readInt(); - int z = dataStream.readInt(); - - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - - if (tileEntity instanceof IPacketReceiver) - { - sendPacketToAllPlayers(tileEntity, ((IPacketReceiver) tileEntity).getNetworkedData(new ArrayList()).toArray()); - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - - public static void encode(Object[] dataValues, DataOutputStream output) - { - try - { - for (Object data : dataValues) - { - if (data instanceof Integer) - { - output.writeInt((Integer) data); - } - else if (data instanceof Boolean) - { - output.writeBoolean((Boolean) data); - } - else if (data instanceof Double) - { - output.writeDouble((Double) data); - } - else if (data instanceof Float) - { - output.writeFloat((Float) data); - } - else if (data instanceof String) - { - output.writeUTF((String) data); - } - else if (data instanceof Byte) - { - output.writeByte((Byte) data); - } - else if (data instanceof Object[]) - { - encode((Object[]) data, output); - } - } - } - catch (Exception e) - { - } - } - - public static void sendDataRequest(TileEntity tileEntity) - { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try - { - data.writeInt(PacketType.DATA_REQUEST.ordinal()); - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - } - catch (Exception e) - { - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = ResonantInduction.CHANNEL; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - PacketDispatcher.sendPacketToServer(packet); - } - - public static void sendPacketToServer(TileEntity tileEntity, Object... dataValues) - { - PacketDispatcher.sendPacketToServer(getTileEntityPacket(tileEntity, dataValues)); - } - - public static void sendPacketToAllPlayers(TileEntity tileEntity, Object... dataValues) - { - PacketDispatcher.sendPacketToAllPlayers(getTileEntityPacket(tileEntity, dataValues)); - } - - public static void sendTileEntityPacketToPlayer(TileEntity tileEntity, EntityPlayer player, Object... dataValues) - { - ((EntityPlayerMP) player).playerNetServerHandler.sendPacketToPlayer(getTileEntityPacket(tileEntity, dataValues)); - } - - public static Packet250CustomPayload getTileEntityPacket(TileEntity tileEntity, Object... dataValues) - { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try - { - data.writeInt(PacketType.TILE.ordinal()); - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - - encode(dataValues, data); - } - catch (Exception e) - { - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = ResonantInduction.CHANNEL; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - return packet; - } - - public static enum PacketType - { - TILE, DATA_REQUEST - } -} diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index bcb9fe852..0567ff65a 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -29,6 +29,8 @@ import resonantinduction.contractor.ItemBlockContractor; import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.entangler.ItemLinker; import resonantinduction.entangler.ItemQuantumEntangler; +import resonantinduction.furnace.BlockAdvancedFurnace; +import resonantinduction.furnace.TileEntityAdvancedFurnace; import resonantinduction.multimeter.BlockMultimeter; import resonantinduction.multimeter.ItemBlockMultimeter; import resonantinduction.multimeter.MultimeterEventHandler; @@ -44,7 +46,9 @@ import universalelectricity.core.item.IItemElectric; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.TranslationHelper; import basiccomponents.api.BasicRegistry; -import calclavia.lib.UniversalRecipes; +import calclavia.lib.UniversalRecipe; +import calclavia.lib.network.PacketHandler; +import calclavia.lib.network.PacketTile; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; @@ -155,6 +159,11 @@ public class ResonantInduction private static Block blockWire; public static Block blockAdvancedFurnaceIdle, blockAdvancedFurnaceBurning; + /** + * Packets + */ + public static final PacketTile PACKET_TILE = new PacketTile(CHANNEL); + public static final Vector3[] DYE_COLORS = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 0.608, 0.232), new Vector3(0.588, 0.294, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 1, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(1, 0.412, 0.706), new Vector3(0.616, 1, 0), new Vector3(1, 1, 0), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) }; @EventHandler @@ -317,25 +326,25 @@ public class ResonantInduction final ItemStack defaultWire = EnumWireMaterial.IRON.getWire(); /** Capacitor **/ - GameRegistry.addRecipe(new ShapedOreRecipe(emptyCapacitor, "RRR", "RIR", "RRR", 'R', Item.redstone, 'I', UniversalRecipes.PRIMARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(emptyCapacitor, "RRR", "RIR", "RRR", 'R', Item.redstone, 'I', UniversalRecipe.PRIMARY_METAL.get())); /** Linker **/ - GameRegistry.addRecipe(new ShapedOreRecipe(itemLinker, " E ", "GCG", " E ", 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'G', UniversalRecipes.SECONDARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(itemLinker, " E ", "GCG", " E ", 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'G', UniversalRecipe.SECONDARY_METAL.get())); /** Quantum Entangler **/ - GameRegistry.addRecipe(new ShapedOreRecipe(itemQuantumEntangler, "EEE", "ILI", "EEE", 'E', Item.eyeOfEnder, 'L', itemLinker, 'I', UniversalRecipes.PRIMARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(itemQuantumEntangler, "EEE", "ILI", "EEE", 'E', Item.eyeOfEnder, 'L', itemLinker, 'I', UniversalRecipe.PRIMARY_METAL.get())); /** Tesla - by Jyzarc */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "WEW", " C ", " I ", 'W', defaultWire, 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'I', UniversalRecipes.PRIMARY_PLATE)); + GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "WEW", " C ", " I ", 'W', defaultWire, 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'I', UniversalRecipe.PRIMARY_PLATE.get())); /** Multimeter */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockMultimeter, "WWW", "ICI", 'W', defaultWire, 'C', emptyCapacitor, 'I', UniversalRecipes.PRIMARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(blockMultimeter, "WWW", "ICI", 'W', defaultWire, 'C', emptyCapacitor, 'I', UniversalRecipe.PRIMARY_METAL.get())); /** Multimeter */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockBattery, "III", "IRI", "III", 'R', Block.blockRedstone, 'I', UniversalRecipes.PRIMARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(blockBattery, "III", "IRI", "III", 'R', Block.blockRedstone, 'I', UniversalRecipe.PRIMARY_METAL.get())); /** EM Contractor */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockEMContractor, " I ", "GCG", "WWW", 'W', UniversalRecipes.PRIMARY_METAL, 'C', emptyCapacitor, 'G', UniversalRecipes.SECONDARY_METAL, 'I', UniversalRecipes.PRIMARY_METAL)); + GameRegistry.addRecipe(new ShapedOreRecipe(blockEMContractor, " I ", "GCG", "WWW", 'W', UniversalRecipe.PRIMARY_METAL.get(), 'C', emptyCapacitor, 'G', UniversalRecipe.SECONDARY_METAL.get(), 'I', UniversalRecipe.PRIMARY_METAL.get())); /** Wires **/ GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.COPPER.getWire(3), "MMM", 'M', "ingotCopper")); diff --git a/src/resonantinduction/base/IPacketReceiver.java b/src/resonantinduction/base/IPacketReceiver.java deleted file mode 100644 index f0838eb24..000000000 --- a/src/resonantinduction/base/IPacketReceiver.java +++ /dev/null @@ -1,12 +0,0 @@ -package resonantinduction.base; - -import java.util.ArrayList; - -import com.google.common.io.ByteArrayDataInput; - -public interface IPacketReceiver -{ - public void handle(ByteArrayDataInput input); - - public ArrayList getNetworkedData(ArrayList data); -} diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index 1234b0592..6040bfa52 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -19,14 +19,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.PacketHandler; +import resonantinduction.ResonantInduction; import resonantinduction.api.ICapacitor; -import resonantinduction.base.IPacketReceiver; import resonantinduction.base.ListUtil; import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.item.IItemElectric; import universalelectricity.core.vector.Vector3; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.network.IPacketSender; import com.google.common.io.ByteArrayDataInput; @@ -38,7 +39,7 @@ import cpw.mods.fml.common.network.Player; * * @author AidanBrady */ -public class TileEntityBattery extends TileEntityUniversalElectrical implements IPacketReceiver, IInventory +public class TileEntityBattery extends TileEntityUniversalElectrical implements IPacketSender, IPacketReceiver, IInventory { public Set playersUsing = new HashSet(); @@ -178,7 +179,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements for (EntityPlayer player : this.playersUsing) { - PacketDispatcher.sendPacketToPlayer(PacketHandler.getTileEntityPacket(this, this.getNetworkedData(new ArrayList()).toArray()), (Player) player); + PacketDispatcher.sendPacketToPlayer(ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(0).toArray()), (Player) player); } this.produce(); @@ -192,7 +193,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements public void updateClient() { - PacketHandler.sendPacketToAllPlayers(this, getNetworkedData(new ArrayList()).toArray()); + PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray())); } public void updateAllClients() @@ -200,18 +201,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements for (Vector3 vec : structure.locations) { TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj); - PacketHandler.sendPacketToAllPlayers(battery, battery.getNetworkedData(new ArrayList()).toArray()); - } - } - - @Override - public void validate() - { - super.validate(); - - if (worldObj.isRemote) - { - PacketHandler.sendDataRequest(this); + PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(battery, battery.getPacketData(0).toArray())); } } @@ -479,28 +469,23 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements } @Override - public void handle(ByteArrayDataInput input) + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player) { - try - { - structure.isMultiblock = input.readBoolean(); + structure.isMultiblock = data.readBoolean(); - clientEnergy = input.readFloat(); - clientCells = input.readInt(); - clientMaxEnergy = input.readFloat(); + clientEnergy = data.readFloat(); + clientCells = data.readInt(); + clientMaxEnergy = data.readFloat(); - structure.height = input.readInt(); - structure.length = input.readInt(); - structure.width = input.readInt(); - } - catch (Exception e) - { - } + structure.height = data.readInt(); + structure.length = data.readInt(); + structure.width = data.readInt(); } @Override - public ArrayList getNetworkedData(ArrayList data) + public ArrayList getPacketData(int type) { + ArrayList data = new ArrayList(); data.add(structure.isMultiblock); data.add(getEnergyStored()); diff --git a/src/resonantinduction/contractor/BlockEMContractor.java b/src/resonantinduction/contractor/BlockEMContractor.java index 2748adf58..558c334a3 100644 --- a/src/resonantinduction/contractor/BlockEMContractor.java +++ b/src/resonantinduction/contractor/BlockEMContractor.java @@ -99,7 +99,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider if (tileEntity instanceof IInventory) { - tileContractor.setFacing(side.getOpposite()); + tileContractor.setDirection(side.getOpposite()); return; } } diff --git a/src/resonantinduction/contractor/ItemBlockContractor.java b/src/resonantinduction/contractor/ItemBlockContractor.java index bb4233e75..039aed77d 100644 --- a/src/resonantinduction/contractor/ItemBlockContractor.java +++ b/src/resonantinduction/contractor/ItemBlockContractor.java @@ -23,7 +23,7 @@ public class ItemBlockContractor extends ItemBlock if (place) { TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z); - tileContractor.setFacing(ForgeDirection.getOrientation(side)); + tileContractor.setDirection(ForgeDirection.getOrientation(side)); if (!tileContractor.isLatched()) { @@ -33,7 +33,7 @@ public class ItemBlockContractor extends ItemBlock if (tileEntity instanceof IInventory) { - tileContractor.setFacing(side1.getOpposite()); + tileContractor.setDirection(side1.getOpposite()); break; } } diff --git a/src/resonantinduction/contractor/TileEntityEMContractor.java b/src/resonantinduction/contractor/TileEntityEMContractor.java index aeedfcb93..8f608b80d 100644 --- a/src/resonantinduction/contractor/TileEntityEMContractor.java +++ b/src/resonantinduction/contractor/TileEntityEMContractor.java @@ -11,6 +11,7 @@ import net.minecraft.block.BlockLadder; import net.minecraft.block.BlockSnow; import net.minecraft.block.BlockVine; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -20,13 +21,13 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.IFluidBlock; -import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; -import resonantinduction.base.IPacketReceiver; -import resonantinduction.base.InventoryUtil; import resonantinduction.tesla.TileEntityTesla; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.tile.TileEntityAdvanced; +import calclavia.lib.InventoryHelper; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.network.IPacketSender; import com.google.common.io.ByteArrayDataInput; @@ -35,7 +36,7 @@ import com.google.common.io.ByteArrayDataInput; * @author AidanBrady * */ -public class TileEntityEMContractor extends TileEntityAdvanced implements IPacketReceiver +public class TileEntityEMContractor extends TileEntityAdvanced implements IPacketReceiver, IPacketSender { public static int MAX_REACH = 40; public static int PUSH_DELAY = 5; @@ -69,7 +70,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke public void initiate() { super.initiate(); - this.updateBounds(); + updateBounds(); } @Override @@ -77,16 +78,16 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke { super.updateEntity(); - this.pushDelay = Math.max(0, this.pushDelay - 1); + pushDelay = Math.max(0, pushDelay - 1); - if (this.tempLinkVector != null) + if (tempLinkVector != null) { - if (this.tempLinkVector.getTileEntity(this.worldObj) instanceof TileEntityEMContractor) + if (tempLinkVector.getTileEntity(worldObj) instanceof TileEntityEMContractor) { - this.setLink((TileEntityEMContractor) this.tempLinkVector.getTileEntity(this.worldObj), true); + setLink((TileEntityEMContractor) tempLinkVector.getTileEntity(worldObj), true); } - this.tempLinkVector = null; + tempLinkVector = null; } if (canFunction()) @@ -96,7 +97,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke if (!suck && pushDelay == 0) { - ItemStack retrieved = InventoryUtil.takeTopItemFromInventory(inventory, this.getDirection().ordinal()); + ItemStack retrieved = InventoryHelper.takeTopItemFromInventory(inventory, getDirection().getOpposite().ordinal()); if (retrieved != null) { @@ -104,7 +105,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke if (!worldObj.isRemote) { - this.worldObj.spawnEntityInWorld(item); + worldObj.spawnEntityInWorld(item); } pushDelay = PUSH_DELAY; @@ -114,124 +115,132 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke { if (suckBounds != null) { - for (EntityItem item : (List) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds)) + if (!worldObj.isRemote) { - ItemStack remains = InventoryUtil.putStackInInventory(inventory, item.getEntityItem(), this.getDirection().ordinal()); + for (EntityItem item : (List) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds)) + { + ItemStack remains = InventoryHelper.putStackInInventory(inventory, item.getEntityItem(), getDirection().getOpposite().ordinal(), false); - if (remains == null) - { - item.setDead(); - } - else - { - item.setEntityItemStack(remains); + if (remains == null) + { + item.setDead(); + } + else + { + item.setEntityItemStack(remains); + } } } } } - if (this.thread != null) + if (thread != null) { - PathfinderEMContractor newPath = this.thread.getPath(); + PathfinderEMContractor newPath = thread.getPath(); if (newPath != null) { - this.pathfinder = newPath; - this.thread = null; + pathfinder = newPath; + thread = null; } } - final int renderFrequency = ResonantInduction.proxy.isFancy() ? 1 + this.worldObj.rand.nextInt(2) : 10 + this.worldObj.rand.nextInt(2); - final boolean renderBeam = this.ticks % renderFrequency == 0 && this.linked != null && !this.linked.isInvalid() && this.linked.suck != this.suck; + final int renderFrequency = ResonantInduction.proxy.isFancy() ? 1 + worldObj.rand.nextInt(2) : 10 + worldObj.rand.nextInt(2); + final boolean renderBeam = ticks % renderFrequency == 0 && hasLink() && linked.suck != suck; - if (!this.suck) + if (hasLink()) { - if (this.linked != null && !this.linked.isInvalid()) + if (!suck) { if (renderBeam) { - ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(this.getDirection())).translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); + ResonantInduction.proxy.renderElectricShock(worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(getDirection())).translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); } - /** - * Push entity along path. - */ - if (this.pathfinder != null) + // Push entity along path. + if (pathfinder != null) { - for (int i = 0; i < this.pathfinder.results.size(); i++) + for (int i = 0; i < pathfinder.results.size(); i++) { - Vector3 result = this.pathfinder.results.get(i).clone(); + Vector3 result = pathfinder.results.get(i).clone(); - if (TileEntityEMContractor.canBePath(this.worldObj, result)) + if (TileEntityEMContractor.canBePath(worldObj, result)) { if (i - 1 >= 0) { - Vector3 prevResult = this.pathfinder.results.get(i - 1).clone(); + Vector3 prevResult = pathfinder.results.get(i - 1).clone(); Vector3 difference = prevResult.clone().difference(result); final ForgeDirection direction = difference.toForgeDirection(); if (renderBeam) { - ResonantInduction.proxy.renderElectricShock(this.worldObj, prevResult.clone().translate(0.5), result.clone().translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); + ResonantInduction.proxy.renderElectricShock(worldObj, prevResult.clone().translate(0.5), result.clone().translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); } AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1); - List entities = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); + List entities = worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); for (EntityItem entityItem : entities) { - this.moveEntity(entityItem, direction, result); + moveEntity(entityItem, direction, result); } } } else { - this.updatePath(); + updatePath(); break; } } } else { - this.updatePath(); + updatePath(); } } - } - else - { - if (renderBeam && this.linked != null && this.linked.pathfinder != null) + else { - ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(this.getDirection())).translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); - } - - this.pathfinder = null; - - AxisAlignedBB searchBounds = this.operationBounds; - - if (this.linked != null) - { - Vector3 searchVec = new Vector3(this).modifyPositionFromSide(this.getDirection()); - searchBounds = AxisAlignedBB.getAABBPool().getAABB(searchVec.x, searchVec.y, searchVec.z, searchVec.x + 1, searchVec.y + 1, searchVec.z + 1); - } - - if (searchBounds != null) - { - for (EntityItem entityItem : (List) worldObj.getEntitiesWithinAABB(EntityItem.class, searchBounds)) + if (renderBeam) { - if (renderBeam) - { - ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(entityItem), ResonantInduction.DYE_COLORS[dyeID], false); - } + ResonantInduction.proxy.renderElectricShock(worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(getDirection())).translate(0.5), ResonantInduction.DYE_COLORS[dyeID], false); + } - this.moveEntity(entityItem, this.getDirection(), new Vector3(this)); + pathfinder = null; + + Vector3 searchVec = new Vector3(this).modifyPositionFromSide(getDirection()); + AxisAlignedBB searchBounds = AxisAlignedBB.getAABBPool().getAABB(searchVec.x, searchVec.y, searchVec.z, searchVec.x + 1, searchVec.y + 1, searchVec.z + 1); + + if (searchBounds != null) + { + for (EntityItem entityItem : (List) worldObj.getEntitiesWithinAABB(EntityItem.class, searchBounds)) + { + if (renderBeam) + { + ResonantInduction.proxy.renderElectricShock(worldObj, new Vector3(this).translate(0.5), new Vector3(entityItem), ResonantInduction.DYE_COLORS[dyeID], false); + } + + moveEntity(entityItem, getDirection(), new Vector3(this)); + } } } } - } + else if (!hasLink()) + { + for (EntityItem entityItem : (List) worldObj.getEntitiesWithinAABB(EntityItem.class, operationBounds)) + { + moveEntity(entityItem, getDirection(), new Vector3(this)); + } + } - this.lastCalcTime--; + if (linked != null && linked.isInvalid()) + { + linked = null; + } + + lastCalcTime--; + } } public static boolean canBePath(World world, Vector3 position) @@ -240,6 +249,11 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke return block == null || (block instanceof BlockSnow || block instanceof BlockVine || block instanceof BlockLadder || ((block instanceof BlockFluid || block instanceof IFluidBlock) && block.blockID != Block.lavaMoving.blockID && block.blockID != Block.lavaStill.blockID)); } + private boolean hasLink() + { + return linked != null && !linked.isInvalid() && linked.linked == this; + } + private void moveEntity(EntityItem entityItem, ForgeDirection direction, Vector3 lockVector) { switch (direction) @@ -348,6 +362,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke break; } + entityItem.ticksExisted = 1; entityItem.isAirBorne = true; entityItem.delayBeforeCanPickup = 1; entityItem.age = Math.max(entityItem.age - 1, 0); @@ -357,7 +372,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke { EntityItem item = null; - switch (this.getDirection()) + switch (getDirection()) { case DOWN: item = new EntityItem(worldObj, xCoord + 0.5, yCoord - 0.2, zCoord + 0.5, toSend); @@ -388,20 +403,9 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke return item; } - @Override - public void validate() - { - super.validate(); - - if (worldObj.isRemote) - { - PacketHandler.sendDataRequest(this); - } - } - public void updateBounds() { - switch (this.getDirection()) + switch (getDirection()) { case DOWN: operationBounds = AxisAlignedBB.getBoundingBox(xCoord, Math.max(yCoord - MAX_REACH, 1), zCoord, xCoord + 1, yCoord, zCoord + 1); @@ -439,7 +443,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke public TileEntity getLatched() { - ForgeDirection side = this.getDirection().getOpposite(); + ForgeDirection side = getDirection().getOpposite(); TileEntity tile = worldObj.getBlockTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ); @@ -453,78 +457,40 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke public void incrementFacing() { - int newOrdinal = this.getDirection().ordinal() < 5 ? this.getDirection().ordinal() + 1 : 0; - this.setFacing(ForgeDirection.getOrientation(newOrdinal)); + int newOrdinal = getDirection().ordinal() < 5 ? getDirection().ordinal() + 1 : 0; + setDirection(ForgeDirection.getOrientation(newOrdinal)); } public ForgeDirection getDirection() { - return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + return ForgeDirection.getOrientation(this.getBlockMetadata()); } - public void setFacing(ForgeDirection side) + public void setDirection(ForgeDirection side) { this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, side.ordinal(), 3); - - if (!worldObj.isRemote) - { - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); - } - - updateBounds(); - } - - public boolean canFunction() - { - return isLatched() && !this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + this.updateBounds(); } @Override - public void readFromNBT(NBTTagCompound nbt) + public ArrayList getPacketData(int type) { - super.readFromNBT(nbt); - this.suck = nbt.getBoolean("suck"); - this.dyeID = nbt.getInteger("dyeID"); - this.tempLinkVector = new Vector3(nbt.getCompoundTag("link")); - } + ArrayList data = new ArrayList(); + data.add(suck); + data.add(dyeID); - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setBoolean("suck", suck); - nbt.setInteger("dyeID", this.dyeID); - - if (this.linked != null) + if (linked != null) { - nbt.setCompoundTag("link", new Vector3(this.linked).writeToNBT(new NBTTagCompound())); - } - } + data.add(true); - @Override - public void handle(ByteArrayDataInput input) - { - try + data.add(linked.xCoord); + data.add(linked.yCoord); + data.add(linked.zCoord); + } + else { - suck = input.readBoolean(); - this.dyeID = input.readInt(); - - if (input.readBoolean()) - { - this.tempLinkVector = new Vector3(input.readInt(), input.readInt(), input.readInt()); - } - - this.worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); - updateBounds(); + data.add(false); } - catch (Exception e) - { - } - } - - @Override - public ArrayList getNetworkedData(ArrayList data) - { return data; } @@ -532,13 +498,54 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke @Override public Packet getDescriptionPacket() { - if (this.linked != null) + return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()); + } + + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player) + { + suck = data.readBoolean(); + dyeID = data.readInt(); + + if (data.readBoolean()) { - return PacketHandler.getTileEntityPacket(this, this.suck, this.dyeID, true, this.linked.xCoord, this.linked.yCoord, this.linked.zCoord); + tempLinkVector = new Vector3(data.readInt(), data.readInt(), data.readInt()); } - else + + worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); + updateBounds(); + } + + public boolean canFunction() + { + return isLatched() && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + + this.suck = nbt.getBoolean("suck"); + this.dyeID = nbt.getInteger("dyeID"); + + if (nbt.hasKey("link")) { - return PacketHandler.getTileEntityPacket(this, this.suck, this.dyeID, false); + tempLinkVector = new Vector3(nbt.getCompoundTag("link")); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + + nbt.setBoolean("suck", suck); + nbt.setInteger("dyeID", dyeID); + + if (linked != null) + { + nbt.setCompoundTag("link", new Vector3(linked).writeToNBT(new NBTTagCompound())); } } @@ -547,47 +554,46 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke */ public void setLink(TileEntityEMContractor tileEntity, boolean setOpponent) { - if (this.linked != null && setOpponent) + if (linked != null && setOpponent) { - this.linked.setLink(null, false); + linked.setLink(null, false); } - this.linked = tileEntity; + linked = tileEntity; if (setOpponent) { - this.linked.setLink(this, false); + linked.setLink(this, false); } - this.updatePath(); + updatePath(); } public void updatePath() { - if (this.thread == null && this.linked != null && this.lastCalcTime <= 0) + if (thread == null && linked != null && lastCalcTime <= 0) { - this.pathfinder = null; - Vector3 start = new Vector3(this).modifyPositionFromSide(this.getDirection()); - Vector3 target = new Vector3(this.linked).modifyPositionFromSide(this.linked.getDirection()); + pathfinder = null; + + Vector3 start = new Vector3(this).modifyPositionFromSide(getDirection()); + Vector3 target = new Vector3(linked).modifyPositionFromSide(linked.getDirection()); if (start.distance(target) < ResonantInduction.MAX_CONTRACTOR_DISTANCE) { - if (TileEntityEMContractor.canBePath(this.worldObj, start) && TileEntityEMContractor.canBePath(this.worldObj, target)) + if (TileEntityEMContractor.canBePath(worldObj, start) && TileEntityEMContractor.canBePath(worldObj, target)) { - this.thread = new ThreadEMPathfinding(new PathfinderEMContractor(this.worldObj, target), start); - this.thread.start(); - this.lastCalcTime = 40; + thread = new ThreadEMPathfinding(new PathfinderEMContractor(worldObj, target), start); + thread.start(); + lastCalcTime = 40; } } } } - /** - * @param itemDamage - */ - public void setDye(int dyeID) + public void setDye(int dye) { - this.dyeID = dyeID; - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + dyeID = dye; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } + } diff --git a/src/resonantinduction/BlockAdvancedFurnace.java b/src/resonantinduction/furnace/BlockAdvancedFurnace.java similarity index 97% rename from src/resonantinduction/BlockAdvancedFurnace.java rename to src/resonantinduction/furnace/BlockAdvancedFurnace.java index c3bbe0558..31c120ea0 100644 --- a/src/resonantinduction/BlockAdvancedFurnace.java +++ b/src/resonantinduction/furnace/BlockAdvancedFurnace.java @@ -1,4 +1,4 @@ -package resonantinduction; +package resonantinduction.furnace; import net.minecraft.block.Block; import net.minecraft.block.BlockFurnace; diff --git a/src/resonantinduction/TileEntityAdvancedFurnace.java b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java similarity index 98% rename from src/resonantinduction/TileEntityAdvancedFurnace.java rename to src/resonantinduction/furnace/TileEntityAdvancedFurnace.java index e4bc8502a..519f30e5b 100644 --- a/src/resonantinduction/TileEntityAdvancedFurnace.java +++ b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java @@ -1,6 +1,6 @@ -package resonantinduction; +package resonantinduction.furnace; -import net.minecraft.block.BlockFurnace; +import resonantinduction.ResonantInduction; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntity; diff --git a/src/resonantinduction/gui/GuiMultimeter.java b/src/resonantinduction/gui/GuiMultimeter.java index b6d143e71..e2adac991 100644 --- a/src/resonantinduction/gui/GuiMultimeter.java +++ b/src/resonantinduction/gui/GuiMultimeter.java @@ -11,10 +11,10 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; import resonantinduction.multimeter.ContainerMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; +import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -59,7 +59,7 @@ public class GuiMultimeter extends GuiContainer try { - PacketHandler.sendPacketToServer(this.tileEntity, (byte) 3, Float.parseFloat(this.textFieldLimit.getText())); + PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this.tileEntity, (byte) 3, Float.parseFloat(this.textFieldLimit.getText()))); } catch (Exception e) { @@ -104,7 +104,7 @@ public class GuiMultimeter extends GuiContainer @Override protected void actionPerformed(GuiButton button) { - PacketHandler.sendPacketToServer(this.tileEntity, (byte) 2); + PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this.tileEntity, (byte) 2)); } } diff --git a/src/resonantinduction/multimeter/TileEntityMultimeter.java b/src/resonantinduction/multimeter/TileEntityMultimeter.java index 0662f3055..9085d494e 100644 --- a/src/resonantinduction/multimeter/TileEntityMultimeter.java +++ b/src/resonantinduction/multimeter/TileEntityMultimeter.java @@ -14,17 +14,18 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; -import resonantinduction.base.IPacketReceiver; import universalelectricity.core.block.IConductor; import universalelectricity.core.block.IConnector; import universalelectricity.core.block.IElectricalStorage; import universalelectricity.core.grid.IElectricityNetwork; -import universalelectricity.prefab.tile.IRotatable; import universalelectricity.prefab.tile.TileEntityAdvanced; import universalelectricity.prefab.tile.TileEntityElectrical; import buildcraft.api.power.IPowerReceptor; +import calclavia.lib.IRotatable; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.network.IPacketSender; +import cofh.api.energy.TileEnergyHandler; import com.google.common.io.ByteArrayDataInput; @@ -37,7 +38,7 @@ import cpw.mods.fml.common.network.Player; * @author Calclavia * */ -public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketReceiver, IConnector, IRotatable +public class TileEntityMultimeter extends TileEntityAdvanced implements IConnector, IRotatable, IPacketReceiver, IPacketSender { public Set playersUsing = new HashSet(); @@ -48,9 +49,9 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR public String display; - private DetectMode(String display) + private DetectMode(String s) { - this.display = display; + display = s; } } @@ -66,12 +67,12 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR { super.updateEntity(); - if (!this.worldObj.isRemote) + if (!worldObj.isRemote) { - if (this.ticks % 20 == 0) + if (ticks % 20 == 0) { - float prevDetectedEnergy = this.detectedEnergy; - this.updateDetection(this.doGetDetectedEnergy()); + float prevDetectedEnergy = detectedEnergy; + updateDetection(doGetDetectedEnergy()); boolean outputRedstone = false; @@ -80,86 +81,84 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR default: break; case EQUAL: - outputRedstone = this.detectedEnergy == this.energyLimit; + outputRedstone = detectedEnergy == energyLimit; break; case GREATER_THAN: - outputRedstone = this.detectedEnergy > this.energyLimit; + outputRedstone = detectedEnergy > energyLimit; break; case GREATER_THAN_EQUAL: - outputRedstone = this.detectedEnergy >= this.energyLimit; + outputRedstone = detectedEnergy >= energyLimit; break; case LESS_THAN: - outputRedstone = this.detectedEnergy < this.energyLimit; + outputRedstone = detectedEnergy < energyLimit; break; case LESS_THAN_EQUAL: - outputRedstone = this.detectedEnergy <= this.energyLimit; + outputRedstone = detectedEnergy <= energyLimit; break; } - if (outputRedstone != this.redstoneOn) + if (outputRedstone != redstoneOn) { - this.redstoneOn = outputRedstone; - this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID); + redstoneOn = outputRedstone; + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, ResonantInduction.blockMultimeter.blockID); } - if (prevDetectedEnergy != this.detectedEnergy) + if (prevDetectedEnergy != detectedEnergy) { - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray())); } } } - if (!this.worldObj.isRemote) + if (!worldObj.isRemote) { - for (EntityPlayer player : this.playersUsing) + for (EntityPlayer player : playersUsing) { - PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player); + PacketDispatcher.sendPacketToPlayer(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()), (Player) player); } } } + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player) + { + switch (data.readByte()) + { + default: + detectMode = DetectMode.values()[data.readByte()]; + detectedEnergy = data.readFloat(); + energyLimit = data.readFloat(); + break; + case 2: + toggleMode(); + break; + case 3: + energyLimit = data.readFloat(); + break; + } + } + + @Override + public ArrayList getPacketData(int type) + { + ArrayList data = new ArrayList(); + data.add((byte) 1); + data.add((byte) detectMode.ordinal()); + data.add(detectedEnergy); + data.add(energyLimit); + return data; + } + @Override public Packet getDescriptionPacket() { - return PacketHandler.getTileEntityPacket(this, (byte) 1, (byte) this.detectMode.ordinal(), this.detectedEnergy, this.energyLimit); - } - - @Override - public void handle(ByteArrayDataInput input) - { - try - { - switch (input.readByte()) - { - default: - this.detectMode = DetectMode.values()[input.readByte()]; - this.detectedEnergy = input.readFloat(); - this.energyLimit = input.readFloat(); - break; - case 2: - this.toggleMode(); - break; - case 3: - this.energyLimit = input.readFloat(); - break; - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public ArrayList getNetworkedData(ArrayList data) - { - return null; + return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()); } public float doGetDetectedEnergy() { - ForgeDirection direction = this.getDirection(); - TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); + ForgeDirection direction = getDirection(); + TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); return getDetectedEnergy(direction.getOpposite(), tileEntity); } @@ -186,9 +185,9 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR { return ((IEnergyStorage) tileEntity).getStored(); } - else if (tileEntity instanceof IEnergyStorage) + else if (tileEntity instanceof TileEnergyHandler) { - return ((IEnergyStorage) tileEntity).getStored(); + return ((TileEnergyHandler) tileEntity).getEnergyStored(side.getOpposite()); } else if (tileEntity instanceof IPowerReceptor) { @@ -203,82 +202,72 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR public void updateDetection(float detected) { - this.detectedEnergy = detected; - this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2; - this.peakDetection = Math.max(peakDetection, this.detectedEnergy); + detectedEnergy = detected; + detectedAverageEnergy = (detectedAverageEnergy + detectedEnergy) / 2; + peakDetection = Math.max(peakDetection, detectedEnergy); } public float getDetectedEnergy() { - return this.detectedEnergy; + return detectedEnergy; } public float getAverageDetectedEnergy() { - return this.detectedAverageEnergy; + return detectedAverageEnergy; } public void toggleMode() { - this.detectMode = DetectMode.values()[(this.detectMode.ordinal() + 1) % DetectMode.values().length]; + detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length]; } - /** - * Reads a tile entity from NBT. - */ @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - this.detectMode = DetectMode.values()[nbt.getInteger("detectMode")]; - this.energyLimit = nbt.getFloat("energyLimit"); + detectMode = DetectMode.values()[nbt.getInteger("detectMode")]; + energyLimit = nbt.getFloat("energyLimit"); } - /** - * Writes a tile entity to NBT. - */ @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setInteger("detectMode", this.detectMode.ordinal()); - nbt.setFloat("energyLimit", this.energyLimit); + nbt.setInteger("detectMode", detectMode.ordinal()); + nbt.setFloat("energyLimit", energyLimit); } public DetectMode getMode() { - return this.detectMode; + return detectMode; } public float getLimit() { - return this.energyLimit; + return energyLimit; } - /** - * @return - */ public float getPeak() { - return this.peakDetection; + return peakDetection; } @Override public boolean canConnect(ForgeDirection direction) { - return direction == this.getDirection(); + return direction == getDirection(); } @Override public ForgeDirection getDirection() { - return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + return ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); } @Override public void setDirection(ForgeDirection direction) { - this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, direction.ordinal(), 3); + this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3); } - } diff --git a/src/resonantinduction/render/RenderPartWire.java b/src/resonantinduction/render/RenderPartWire.java index 6d0c0aca5..9c1de9c3d 100644 --- a/src/resonantinduction/render/RenderPartWire.java +++ b/src/resonantinduction/render/RenderPartWire.java @@ -12,8 +12,8 @@ import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; -import resonantinduction.wire.multipart.PartConductor; -import resonantinduction.wire.multipart.PartWire; +import resonantinduction.wire.PartConductor; +import resonantinduction.wire.PartWire; import universalelectricity.core.vector.Vector3; import codechicken.lib.colour.Colour; import codechicken.lib.colour.ColourRGBA; diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 3fb2e0320..8b14346f3 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Set; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; import net.minecraft.server.MinecraftServer; @@ -20,13 +21,13 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; -import resonantinduction.base.IPacketReceiver; import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.vector.Vector3; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.network.IPacketSender; import com.google.common.io.ByteArrayDataInput; @@ -40,7 +41,7 @@ import cpw.mods.fml.common.network.PacketDispatcher; * @author Calclavia * */ -public class TileEntityTesla extends TileEntityUniversalElectrical implements ITesla, IPacketReceiver +public class TileEntityTesla extends TileEntityUniversalElectrical implements ITesla, IPacketSender, IPacketReceiver { public final static int DEFAULT_COLOR = 12; public final float TRANSFER_CAP = 10; @@ -281,63 +282,64 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT return this.isController(); } + /** + * 1 - Description Packet + * 2 - Energy Update + * 3 - Tesla Beam + */ + @Override + public ArrayList getPacketData(int type) + { + ArrayList data = new ArrayList(); + data.add((byte) type); + + switch (type) + { + case 1: + { + data.add(this.getEnergyStored()); + data.add(this.dyeID); + data.add(this.canReceive); + data.add(this.attackEntities); + data.add(this.linked != null); + break; + } + case 2: + { + data.add(this.getEnergyStored()); + } + } + + return data; + } + + public void sendPacket(int type) + { + PacketDispatcher.sendPacketToAllInDimension(ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(type)), this.worldObj.provider.dimensionId); + } + @Override public Packet getDescriptionPacket() { - return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID, this.canReceive, this.attackEntities, this.linked != null); - } - - public Packet getDescriptionPacket2() - { - return PacketHandler.getTileEntityPacket(this, (byte) 2, this.getEnergyStored()); - } - - /** - * Do Tesla Beam. - */ - public Packet getDescriptionPacket3() - { - return PacketHandler.getTileEntityPacket(this, (byte) 3); - } - - public void sendPacket(int id) - { - switch (id) - { - case 1: - PacketDispatcher.sendPacketToAllInDimension(this.getDescriptionPacket(), this.worldObj.provider.dimensionId); - break; - case 2: - PacketDispatcher.sendPacketToAllInDimension(this.getDescriptionPacket2(), this.worldObj.provider.dimensionId); - break; - case 3: - PacketDispatcher.sendPacketToAllInDimension(this.getDescriptionPacket3(), this.worldObj.provider.dimensionId); - break; - } + return ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(1)); } @Override - public ArrayList getNetworkedData(ArrayList data) - { - return null; - } - - @Override - public void handle(ByteArrayDataInput input) + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player) { try { - switch (input.readByte()) + switch (data.readByte()) { case 1: - this.setEnergyStored(input.readFloat()); - this.dyeID = input.readInt(); - this.canReceive = input.readBoolean(); - this.attackEntities = input.readBoolean(); - this.isLinkedClient = input.readBoolean(); + this.setEnergyStored(data.readFloat()); + this.dyeID = data.readInt(); + this.canReceive = data.readBoolean(); + this.attackEntities = data.readBoolean(); + this.isLinkedClient = data.readBoolean(); break; case 2: - this.setEnergyStored(input.readFloat()); + this.setEnergyStored(data.readFloat()); break; case 3: this.doTransfer = true; diff --git a/src/resonantinduction/wire/BlockWire.java b/src/resonantinduction/wire/BlockWire.java index a8d714c85..539eabf99 100644 --- a/src/resonantinduction/wire/BlockWire.java +++ b/src/resonantinduction/wire/BlockWire.java @@ -9,12 +9,10 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.ResonantInduction; import resonantinduction.TabRI; -import universalelectricity.core.block.IConductor; import universalelectricity.prefab.block.BlockConductor; /** diff --git a/src/resonantinduction/wire/EnumWireMaterial.java b/src/resonantinduction/wire/EnumWireMaterial.java index c13d11fc2..345d1e7f8 100644 --- a/src/resonantinduction/wire/EnumWireMaterial.java +++ b/src/resonantinduction/wire/EnumWireMaterial.java @@ -16,54 +16,63 @@ import universalelectricity.core.vector.Vector3; public enum EnumWireMaterial { - COPPER(12.5f, 3, 2, new Vector3(184, 115, 51)), TIN(13, 2, 0.5f, new Vector3(132, 132, 130)), - IRON(0.1f, 2, 4, new Vector3(97, 102, 105)), - ALUMINUM(0.025f, 6, 0.15f, new Vector3(215, 205, 181)), - SILVER(0.005f, 1, 2, new Vector3(192, 192, 192)), - SUPERCONDUCTOR(0, 8, Float.MAX_VALUE, new Vector3(212, 175, 55)); + COPPER("Copper", 12.5F, 3, 2, new Vector3(184, 115, 51)), + TIN("Tin", 13, 2, 0.5F, new Vector3(132, 132, 130)), + IRON("Iron", 0.1F, 2, 4, new Vector3(97, 102, 105)), + ALUMINUM("Aluminum", 0.025F, 6, 0.15F, new Vector3(215, 205, 181)), + SILVER("Silver", 0.005F, 1, 2, new Vector3(192, 192, 192)), + SUPERCONDUCTOR("Superconductor", 0, 1, 2, new Vector3(192, 192, 192)); public final float resistance; public final float damage; public final float maxAmps; public final Vector3 color; private ItemStack wire; + private final String name; - EnumWireMaterial(float resistance, float electrocutionDamage, float maxAmps, Vector3 color) + private EnumWireMaterial(String s, float resist, float electrocution, float max, Vector3 vec) { - this.resistance = resistance; - this.damage = electrocutionDamage; - this.maxAmps = maxAmps; - this.color = color.scale(1D / 255D); + name = s; + resistance = resist; + damage = electrocution; + maxAmps = max; + color = vec.scale(1D / 255D); + } + + public String getName() + { + return name; } public ItemStack getWire() { - return this.getWire(1); + return getWire(1); } public ItemStack getWire(int amount) { - ItemStack returnStack = this.wire.copy(); + ItemStack returnStack = wire.copy(); returnStack.stackSize = amount; + return returnStack; } public void setWire(ItemStack item) { - if (this.wire == null) + if (wire == null) { - this.wire = item; - OreDictionary.registerOre(this.name().toLowerCase() + "Wire", this.wire); + wire = item; + OreDictionary.registerOre(getName().toLowerCase() + "Wire", wire); } } public void setWire(Item item) { - this.setWire(new ItemStack(item, 1, this.ordinal())); + setWire(new ItemStack(item, 1, ordinal())); } public void setWire(Block block) { - this.setWire(new ItemStack(block, 1, this.ordinal())); + setWire(new ItemStack(block, 1, ordinal())); } } \ No newline at end of file diff --git a/src/resonantinduction/wire/multipart/IBlockableConnection.java b/src/resonantinduction/wire/IBlockableConnection.java similarity index 77% rename from src/resonantinduction/wire/multipart/IBlockableConnection.java rename to src/resonantinduction/wire/IBlockableConnection.java index 9340d8cf3..450f1ba00 100644 --- a/src/resonantinduction/wire/multipart/IBlockableConnection.java +++ b/src/resonantinduction/wire/IBlockableConnection.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import net.minecraftforge.common.ForgeDirection; diff --git a/src/resonantinduction/wire/IInsulation.java b/src/resonantinduction/wire/IInsulation.java index 09481a191..d68b9e70d 100644 --- a/src/resonantinduction/wire/IInsulation.java +++ b/src/resonantinduction/wire/IInsulation.java @@ -8,5 +8,5 @@ public interface IInsulation public int getInsulationColor(); - public void setInsulationColor(int dyeID); + public void setInsulationColor(int dye); } diff --git a/src/resonantinduction/wire/multipart/ItemPartWire.java b/src/resonantinduction/wire/ItemPartWire.java similarity index 59% rename from src/resonantinduction/wire/multipart/ItemPartWire.java rename to src/resonantinduction/wire/ItemPartWire.java index c866f0398..b2e43a0a9 100644 --- a/src/resonantinduction/wire/multipart/ItemPartWire.java +++ b/src/resonantinduction/wire/ItemPartWire.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import java.util.List; @@ -12,7 +12,6 @@ import net.minecraftforge.common.Configuration; import resonantinduction.ResonantInduction; import resonantinduction.TabRI; import resonantinduction.render.RenderPartWire; -import resonantinduction.wire.EnumWireMaterial; import universalelectricity.core.electricity.ElectricityDisplay; import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; import codechicken.lib.vec.BlockCoord; @@ -29,22 +28,15 @@ public class ItemPartWire extends JItemMultiPart public ItemPartWire(int id) { super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "wireMultipart", id).getInt(id)); - this.setUnlocalizedName(ResonantInduction.PREFIX + "wire"); - this.setCreativeTab(TabRI.INSTANCE); - this.setHasSubtypes(true); - this.setMaxDamage(0); + setCreativeTab(TabRI.INSTANCE); + setHasSubtypes(true); + setMaxDamage(0); } @Override public TMultiPart newPart(ItemStack arg0, EntityPlayer arg1, World arg2, BlockCoord arg3, int arg4, Vector3 arg5) { - return new PartWire(this.getDamage(arg0)); - } - - @Override - public String getUnlocalizedName() - { - return super.getUnlocalizedName().replace("item", "tile"); + return new PartWire(getDamage(arg0)); } @Override @@ -56,39 +48,39 @@ public class ItemPartWire extends JItemMultiPart @Override public String getUnlocalizedName(ItemStack itemStack) { - return this.getUnlocalizedName() + "." + EnumWireMaterial.values()[itemStack.getItemDamage()].name().toLowerCase(); + return "tile.Wire." + EnumWireMaterial.values()[itemStack.getItemDamage()].getName() + "Wire"; } @Override - public void addInformation(ItemStack itemstack, EntityPlayer player, List par3List, boolean par4) + public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4) { - par3List.add("Resistance: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].resistance, ElectricUnit.RESISTANCE)); - par3List.add("Max Amperage: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, ElectricUnit.AMPERE)); + list.add("Resistance: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].resistance, ElectricUnit.RESISTANCE)); + list.add("Max Amperage: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, ElectricUnit.AMPERE)); } @Override @SideOnly(Side.CLIENT) - public void registerIcons(IconRegister iconRegister) - { - for (int i = 0; i < EnumWireMaterial.values().length; i++) + public void registerIcons(IconRegister register) + { + for(EnumWireMaterial material : EnumWireMaterial.values()) { - this.icons[i] = iconRegister.registerIcon(this.getUnlocalizedName(new ItemStack(this.itemID, 1, i)).replaceAll("tile.", "")); + icons[material.ordinal()] = register.registerIcon("mekanism:" + material.getName() + "Wire"); } - RenderPartWire.registerIcons(iconRegister); + RenderPartWire.registerIcons(register); } @Override @SideOnly(Side.CLIENT) public Icon getIconFromDamage(int meta) { - return this.icons[meta]; + return icons[meta]; } @Override public void getSubItems(int itemID, CreativeTabs tab, List listToAddTo) { - for (EnumWireMaterial mat : EnumWireMaterial.values()) + for(EnumWireMaterial mat : EnumWireMaterial.values()) { listToAddTo.add(new ItemStack(itemID, 1, mat.ordinal())); } @@ -100,5 +92,4 @@ public class ItemPartWire extends JItemMultiPart { return 0; } - } diff --git a/src/resonantinduction/wire/multipart/PartAdvanced.java b/src/resonantinduction/wire/PartAdvanced.java similarity index 56% rename from src/resonantinduction/wire/multipart/PartAdvanced.java rename to src/resonantinduction/wire/PartAdvanced.java index d61052ff9..bedf24a8b 100644 --- a/src/resonantinduction/wire/multipart/PartAdvanced.java +++ b/src/resonantinduction/wire/PartAdvanced.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import net.minecraft.block.Block; import codechicken.multipart.TMultiPart; @@ -11,29 +11,27 @@ public abstract class PartAdvanced extends TMultiPart @Override public void update() { - if (this.ticks == 0) + if(ticks == 0) { - this.initiate(); + initiate(); } - if (this.ticks >= Long.MAX_VALUE) + if(ticks >= Long.MAX_VALUE) { - this.ticks = 1; + ticks = 1; } - this.ticks++; + ticks++; } @Override public void onAdded() { - world().notifyBlocksOfNeighborChange(x(), y(), z(), ((Block) MultipartProxy.block()).blockID); + world().notifyBlocksOfNeighborChange(x(), y(), z(), ((Block)MultipartProxy.block()).blockID); } /** * Called on the TileEntity's first tick. */ - public void initiate() - { - } + public void initiate() {} } diff --git a/src/resonantinduction/wire/multipart/PartConductor.java b/src/resonantinduction/wire/PartConductor.java similarity index 57% rename from src/resonantinduction/wire/multipart/PartConductor.java rename to src/resonantinduction/wire/PartConductor.java index e47cff9c8..6885f5190 100644 --- a/src/resonantinduction/wire/multipart/PartConductor.java +++ b/src/resonantinduction/wire/PartConductor.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; @@ -33,14 +33,13 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public void bind(TileMultipart t) { - if (tile() != null && network != null) + if(tile() != null && network != null) { - this.getNetwork().getConductors().remove(tile()); + getNetwork().getConductors().remove(tile()); super.bind(t); - this.getNetwork().getConductors().add((IConductor) tile()); + getNetwork().getConductors().add((IConductor) tile()); } - else - { + else { super.bind(t); } } @@ -48,9 +47,9 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public void preRemove() { - if (!this.world().isRemote && this.tile() instanceof IConductor) + if(!world().isRemote && tile() instanceof IConductor) { - this.getNetwork().split((IConductor) this.tile()); + getNetwork().split((IConductor) tile()); } super.preRemove(); @@ -65,29 +64,30 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public IElectricityNetwork getNetwork() { - if (this.network == null && this.tile() instanceof IConductor) + if(network == null && tile() instanceof IConductor) { - this.setNetwork(NetworkLoader.getNewNetwork((IConductor) this.tile())); + setNetwork(NetworkLoader.getNewNetwork((IConductor)tile())); } - return this.network; + return network; } public boolean canConnectBothSides(TileEntity tile, ForgeDirection side) { - boolean notPrevented = !connectionPrevented(tile, side); + boolean notPrevented = !isConnectionPrevented(tile, side); - if (tile instanceof IConnector) + if(tile instanceof IConnector) { - notPrevented &= ((IConnector) tile).canConnect(side.getOpposite()); + notPrevented &= ((IConnector)tile).canConnect(side.getOpposite()); } + return notPrevented; } @Override - public void setNetwork(IElectricityNetwork network) + public void setNetwork(IElectricityNetwork net) { - this.network = network; + network = net; } /** @@ -97,7 +97,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor * @param side The side we're checking * @return Whether we're preventing connections on given side or to given tileEntity */ - public boolean connectionPrevented(TileEntity tile, ForgeDirection side) + public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) { return false; } @@ -106,12 +106,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor { byte connections = 0x00; - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side); - if (tileEntity instanceof INetworkProvider && this.canConnectBothSides(tileEntity, side)) + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + + if(tileEntity instanceof INetworkProvider && canConnectBothSides(tileEntity, side)) + { connections |= 1 << side.ordinal(); + } } + return connections; } @@ -119,12 +123,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor { byte connections = 0x00; - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side); - if (this.isValidAcceptor(tileEntity) && this.canConnectBothSides(tileEntity, side)) + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + + if(isValidAcceptor(tileEntity) && canConnectBothSides(tileEntity, side)) + { connections |= 1 << side.ordinal(); + } } + return connections; } @@ -139,44 +147,46 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public void refresh() { - if (!this.world().isRemote) + if(!world().isRemote) { - this.adjacentConnections = null; + adjacentConnections = null; + byte possibleWireConnections = getPossibleWireConnections(); byte possibleAcceptorConnections = getPossibleAcceptorConnections(); - if (possibleWireConnections != currentWireConnections) + if(possibleWireConnections != currentWireConnections) { byte or = (byte) (possibleWireConnections | currentWireConnections); - if (or != possibleWireConnections) // Connections have been removed + + if(or != possibleWireConnections) // Connections have been removed { - this.getNetwork().split((IConductor) tile()); - this.setNetwork(null); + getNetwork().split((IConductor) tile()); + setNetwork(null); } - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if (connectionMapContainsSide(possibleWireConnections, side)) + if(connectionMapContainsSide(possibleWireConnections, side)) { - TileEntity tileEntity = VectorHelper.getConnectorFromSide(this.world(), new Vector3(tile()), side); + TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side); - if (tileEntity instanceof INetworkProvider) + if(tileEntity instanceof INetworkProvider) { - this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork()); + getNetwork().merge(((INetworkProvider) tileEntity).getNetwork()); } } } - this.currentWireConnections = possibleWireConnections; + currentWireConnections = possibleWireConnections; } - this.currentAcceptorConnections = possibleAcceptorConnections; + currentAcceptorConnections = possibleAcceptorConnections; - this.getNetwork().refresh(); - this.sendDescUpdate(); + getNetwork().refresh(); + sendDescUpdate(); } - this.tile().markRender(); + tile().markRender(); } /** @@ -186,27 +196,27 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public TileEntity[] getAdjacentConnections() { - if (this.adjacentConnections == null) + if(adjacentConnections == null) { - this.adjacentConnections = new TileEntity[6]; + adjacentConnections = new TileEntity[6]; - for (byte i = 0; i < 6; i++) + for(byte i = 0; i < 6; i++) { ForgeDirection side = ForgeDirection.getOrientation(i); - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side); + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - if (isCurrentlyConnected(side)) + if(isCurrentlyConnected(side)) { adjacentConnections[i] = tileEntity; } } } - return this.adjacentConnections; + return adjacentConnections; } public boolean isCurrentlyConnected(ForgeDirection side) { - return connectionMapContainsSide(this.getAllCurrentConnections(), side); + return connectionMapContainsSide(getAllCurrentConnections(), side); } /** @@ -216,28 +226,28 @@ public abstract class PartConductor extends PartAdvanced implements IConductor public boolean canConnect(ForgeDirection direction) { Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction); - TileEntity connectTile = connectPos.getTileEntity(this.world()); - return !connectionPrevented(connectTile, direction); + TileEntity connectTile = connectPos.getTileEntity(world()); + return !isConnectionPrevented(connectTile, direction); } @Override public void onAdded() { super.onAdded(); - this.refresh(); + refresh(); } @Override public void onChunkLoad() { super.onChunkLoad(); - this.refresh(); + refresh(); } @Override public void onNeighborChanged() { super.onNeighborChanged(); - this.refresh(); + refresh(); } } diff --git a/src/resonantinduction/wire/multipart/PartUniversalConductor.java b/src/resonantinduction/wire/PartUniversalConductor.java similarity index 50% rename from src/resonantinduction/wire/multipart/PartUniversalConductor.java rename to src/resonantinduction/wire/PartUniversalConductor.java index 327d3e459..3794b515b 100644 --- a/src/resonantinduction/wire/multipart/PartUniversalConductor.java +++ b/src/resonantinduction/wire/PartUniversalConductor.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; @@ -20,44 +20,61 @@ import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.Type; +import cofh.api.energy.IEnergyHandler; -public abstract class PartUniversalConductor extends PartConductor implements IEnergySink, IPowerReceptor +public abstract class PartUniversalConductor extends PartConductor implements IEnergySink, IPowerReceptor, IEnergyHandler { - protected boolean isAddedToEnergyNet; public PowerHandler powerHandler; public float buildcraftBuffer = Compatibility.BC3_RATIO * 50; public PartUniversalConductor() { - this.powerHandler = new PowerHandler(this, Type.PIPE); - this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2); - this.powerHandler.configurePowerPerdition(0, 0); + powerHandler = new PowerHandler(this, Type.PIPE); + powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, buildcraftBuffer * 2); + powerHandler.configurePowerPerdition(0, 0); } @Override public boolean isValidAcceptor(TileEntity tile) { - if (Compatibility.isIndustrialCraft2Loaded() && tile instanceof IEnergyTile) + if(tile instanceof IEnergyTile) { return true; } - else if (Compatibility.isBuildcraftLoaded() && tile instanceof IPowerReceptor) + else if(tile instanceof IPowerReceptor) { return true; } + else if(tile instanceof IEnergyHandler) + { + return true; + } + return super.isValidAcceptor(tile); } + @Override + public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) + { + if(tile instanceof IEnergyHandler) + { + return !((IEnergyHandler)tile).canInterface(side); + } + + return super.isConnectionPrevented(tile, side); + } + @Override public void onWorldJoin() { super.onWorldJoin(); - if (!this.world().isRemote) + + if(!world().isRemote) { - if (!this.isAddedToEnergyNet) + if(!isAddedToEnergyNet) { - this.initIC(); + initIC(); } } } @@ -66,11 +83,12 @@ public abstract class PartUniversalConductor extends PartConductor implements IE public void onAdded() { super.onAdded(); - if (!this.world().isRemote) + + if(!world().isRemote) { - if (!this.isAddedToEnergyNet) + if(!isAddedToEnergyNet) { - this.initIC(); + initIC(); } } } @@ -79,11 +97,12 @@ public abstract class PartUniversalConductor extends PartConductor implements IE public void onChunkLoad() { super.onChunkLoad(); - if (!this.world().isRemote) + + if(!world().isRemote) { - if (!this.isAddedToEnergyNet) + if(!isAddedToEnergyNet) { - this.initIC(); + initIC(); } } } @@ -91,69 +110,67 @@ public abstract class PartUniversalConductor extends PartConductor implements IE @Override public void onWorldSeparate() { - this.unloadTileIC2(); + unloadTileIC2(); super.onWorldSeparate(); } @Override public void onChunkUnload() { - this.unloadTileIC2(); + unloadTileIC2(); super.onChunkUnload(); } @Override - public void onRemoved() - { - } + public void onRemoved() {} @Override public void preRemove() { - this.unloadTileIC2(); + unloadTileIC2(); super.preRemove(); } protected void initIC() { - if (Compatibility.isIndustrialCraft2Loaded()) + if(Compatibility.isIndustrialCraft2Loaded()) { MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); } - this.isAddedToEnergyNet = true; + isAddedToEnergyNet = true; } private void unloadTileIC2() { - if (this.isAddedToEnergyNet && this.world() != null) + if(isAddedToEnergyNet && world() != null) { - if (Compatibility.isIndustrialCraft2Loaded()) + if(Compatibility.isIndustrialCraft2Loaded()) { MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile())); } - this.isAddedToEnergyNet = false; + isAddedToEnergyNet = false; } } @Override public double demandedEnergyUnits() { - if (this.getNetwork() == null) + if(getNetwork() == null) { return 0.0; } - return this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO; + return getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO; } @Override public double injectEnergyUnits(ForgeDirection directionFrom, double amount) { - TileEntity tile = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), directionFrom); + TileEntity tile = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), directionFrom); ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120); - return this.getNetwork().produce(pack, tile(), tile) * Compatibility.TO_IC2_RATIO; + return getNetwork().produce(pack, tile(), tile) * Compatibility.TO_IC2_RATIO; } @Override @@ -174,7 +191,7 @@ public abstract class PartUniversalConductor extends PartConductor implements IE @Override public PowerReceiver getPowerReceiver(ForgeDirection side) { - return this.powerHandler.getPowerReceiver(); + return powerHandler.getPowerReceiver(); } @Override @@ -183,14 +200,14 @@ public abstract class PartUniversalConductor extends PartConductor implements IE Set ignoreTiles = new HashSet(); ignoreTiles.add(tile()); - for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tile = new Vector3(tile()).modifyPositionFromSide(direction).getTileEntity(this.world()); + TileEntity tile = new Vector3(tile()).modifyPositionFromSide(direction).getTileEntity(world()); ignoreTiles.add(tile); } - ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120); - this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0])); + ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120); + getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0])); } @Override @@ -198,4 +215,50 @@ public abstract class PartUniversalConductor extends PartConductor implements IE { return world(); } + + /** + * Thermal Expansion Functions + */ + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) + { + ElectricityPack pack = ElectricityPack.getFromWatts(maxReceive * Compatibility.TE_RATIO, 1); + float request = getMaxEnergyStored(from); + + if(!simulate) + { + if(request > 0) + { + return (int) (maxReceive - (getNetwork().produce(pack, new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(world())) * Compatibility.TO_TE_RATIO)); + } + + return 0; + } + + return (int)Math.min(maxReceive, request * Compatibility.TO_TE_RATIO); + } + + @Override + public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) + { + return 0; + } + + @Override + public boolean canInterface(ForgeDirection from) + { + return true; + } + + @Override + public int getEnergyStored(ForgeDirection from) + { + return 0; + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) + { + return (int)Math.round(getNetwork().getRequest(new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(world())).getWatts() * Compatibility.TO_TE_RATIO); + } } diff --git a/src/resonantinduction/wire/multipart/PartWire.java b/src/resonantinduction/wire/PartWire.java similarity index 72% rename from src/resonantinduction/wire/multipart/PartWire.java rename to src/resonantinduction/wire/PartWire.java index fdb08b1f6..d54da40a1 100644 --- a/src/resonantinduction/wire/multipart/PartWire.java +++ b/src/resonantinduction/wire/PartWire.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart; +package resonantinduction.wire; import java.util.ArrayList; import java.util.Collection; @@ -20,12 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.util.MovingObjectPosition; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.ResonantInduction; import resonantinduction.render.RenderPartWire; -import resonantinduction.wire.EnumWireMaterial; -import resonantinduction.wire.IInsulatedMaterial; -import resonantinduction.wire.IInsulation; -import resonantinduction.wire.IWireMaterial; import universalelectricity.compatibility.Compatibility; import buildcraft.api.power.PowerHandler; import codechicken.lib.data.MCDataInput; @@ -45,7 +40,6 @@ import codechicken.multipart.NormalOcclusionTest; import codechicken.multipart.PartMap; import codechicken.multipart.TMultiPart; import codechicken.multipart.TSlottedPart; -import codechicken.multipart.TileMultipart; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -88,7 +82,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN public PartWire(EnumWireMaterial type) { super(); - this.material = type; + material = type; } public PartWire() @@ -99,7 +93,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN @Override public boolean canConnect(ForgeDirection direction) { - if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) { return false; } @@ -108,44 +102,50 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN } @Override - public boolean connectionPrevented(TileEntity tile, ForgeDirection side) + public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) { if (tile instanceof IWireMaterial) { IWireMaterial wireTile = (IWireMaterial) tile; - if (wireTile.getMaterial() != this.getMaterial()) + if (wireTile.getMaterial() != getMaterial()) + { return true; + } } - if (this.isInsulated() && tile instanceof IInsulation) + if (isInsulated() && tile instanceof IInsulation) { IInsulation insulatedTile = (IInsulation) tile; - if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != this.getInsulationColor() && this.getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR)) + if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != getInsulationColor() && getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR)) + { return true; + } } - return (this.isBlockedOnSide(side) || tile instanceof IBlockableConnection && ((IBlockableConnection) tile).isBlockedOnSide(side.getOpposite())); + return (isBlockedOnSide(side) || tile instanceof IBlockableConnection && ((IBlockableConnection) tile).isBlockedOnSide(side.getOpposite())); } @Override public byte getPossibleWireConnections() { - if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) { return 0x00; } + return super.getPossibleWireConnections(); } @Override public byte getPossibleAcceptorConnections() { - if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) { return 0x00; } + return super.getPossibleAcceptorConnections(); } @@ -172,23 +172,25 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN return material.ordinal(); } - public void setDye(int dyeID) + public void setDye(int dye) { - this.dyeID = dyeID; - this.refresh(); - this.world().markBlockForUpdate(this.x(), this.y(), this.z()); + dyeID = dye; + refresh(); + world().markBlockForUpdate(x(), y(), z()); + tile().notifyPartChange(this); } public void setMaterialFromID(int id) { - this.material = EnumWireMaterial.values()[id]; + material = EnumWireMaterial.values()[id]; } @Override public void doWork(PowerHandler workProvider) { - this.buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(this.getMaterial().maxAmps, 100); - this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2); + buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(getMaterial().maxAmps, 100); + powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, buildcraftBuffer * 2); + super.doWork(workProvider); } @@ -208,16 +210,18 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN public Iterable getSubParts() { Set subParts = new HashSet(); - IndexedCuboid6[] currentSides = this.isInsulated() ? insulatedSides : sides; + IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides; + if (tile() != null) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { int ord = side.ordinal(); - if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == this.testingSide) + if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide) subParts.add(currentSides[ord]); } } + subParts.add(currentSides[6]); return subParts; } @@ -227,6 +231,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN { Set collisionBoxes = new HashSet(); collisionBoxes.addAll((Collection) getSubParts()); + return collisionBoxes; } @@ -235,8 +240,12 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN { List drops = new ArrayList(); drops.add(pickItem(null)); + if (isInsulated) + { drops.add(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))); + } + return drops; } @@ -251,15 +260,19 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass) { if (pass == 0) + { RenderPartWire.INSTANCE.renderStatic(this); + } } @Override @SideOnly(Side.CLIENT) public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) { - if (ResonantInduction.SHINY_SILVER && this.getMaterial() == EnumWireMaterial.SILVER) + if (getMaterial() == EnumWireMaterial.SILVER) + { RenderPartWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame); + } } @Override @@ -272,47 +285,50 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN @Override public void readDesc(MCDataInput packet) { - this.setMaterialFromID(packet.readInt()); - this.dyeID = packet.readInt(); - this.isInsulated = packet.readBoolean(); - this.currentWireConnections = packet.readByte(); - this.currentAcceptorConnections = packet.readByte(); + setMaterialFromID(packet.readInt()); + dyeID = packet.readInt(); + isInsulated = packet.readBoolean(); + currentWireConnections = packet.readByte(); + currentAcceptorConnections = packet.readByte(); + if (tile() != null) + { tile().markRender(); + } } @Override public void writeDesc(MCDataOutput packet) { - packet.writeInt(this.getTypeID()); - packet.writeInt(this.dyeID); - packet.writeBoolean(this.isInsulated); - packet.writeByte(this.currentWireConnections); - packet.writeByte(this.currentAcceptorConnections); + packet.writeInt(getTypeID()); + packet.writeInt(dyeID); + packet.writeBoolean(isInsulated); + packet.writeByte(currentWireConnections); + packet.writeByte(currentAcceptorConnections); } @Override public void save(NBTTagCompound nbt) { super.save(nbt); - nbt.setInteger("typeID", this.getTypeID()); - nbt.setInteger("dyeID", this.dyeID); - nbt.setBoolean("isInsulated", this.isInsulated); + nbt.setInteger("typeID", getTypeID()); + nbt.setInteger("dyeID", dyeID); + nbt.setBoolean("isInsulated", isInsulated); } @Override public void load(NBTTagCompound nbt) { super.load(nbt); - this.setMaterialFromID(nbt.getInteger("typeID")); - this.dyeID = nbt.getInteger("dyeID"); - this.isInsulated = nbt.getBoolean("isInsulated"); + setMaterialFromID(nbt.getInteger("typeID")); + dyeID = nbt.getInteger("dyeID"); + isInsulated = nbt.getBoolean("isInsulated"); } @Override public ItemStack pickItem(MovingObjectPosition hit) { - return EnumWireMaterial.values()[this.getTypeID()].getWire(); + return EnumWireMaterial.values()[getTypeID()].getWire(); } @Override @@ -329,20 +345,21 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN { if (isInsulated() && !world().isRemote) { - this.tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)))); + tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)))); } - this.setInsulated(BlockColored.getDyeFromBlock(item.getItemDamage())); + + setInsulated(BlockColored.getDyeFromBlock(item.getItemDamage())); player.inventory.decrStackSize(player.inventory.currentItem, 1); return true; } - else if ((item.itemID == Item.shears.itemID || item.getItem() instanceof ItemShears) && this.isInsulated()) + else if ((item.itemID == Item.shears.itemID || item.getItem() instanceof ItemShears) && isInsulated()) { - if (!this.world().isRemote) + if (!world().isRemote) { - this.tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)))); + tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)))); } - this.setInsulated(false); + setInsulated(false); return true; } } @@ -364,7 +381,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN @Override public int getHollowSize() { - return this.isInsulated ? 8 : 6; + return isInsulated ? 8 : 6; } @Override @@ -380,30 +397,34 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN } @Override - public void setInsulationColor(int dyeID) + public void setInsulationColor(int dye) { - this.dyeID = dyeID; - this.refresh(); - this.world().markBlockForUpdate(this.x(), this.y(), this.z()); + dyeID = dye; + + refresh(); + world().markBlockForUpdate(x(), y(), z()); + tile().notifyPartChange(this); } @Override public void setInsulated(boolean insulated) { - this.isInsulated = insulated; - this.dyeID = DEFAULT_COLOR; - this.refresh(); - this.world().markBlockForUpdate(this.x(), this.y(), this.z()); - this.tile().notifyPartChange(this); + isInsulated = insulated; + dyeID = DEFAULT_COLOR; + + refresh(); + world().markBlockForUpdate(x(), y(), z()); + tile().notifyPartChange(this); } public void setInsulated(int dyeColour) { - this.isInsulated = true; - this.dyeID = dyeColour; - this.refresh(); - this.world().markBlockForUpdate(this.x(), this.y(), this.z()); - this.tile().notifyPartChange(this); + isInsulated = true; + dyeID = dyeColour; + + refresh(); + world().markBlockForUpdate(x(), y(), z()); + tile().notifyPartChange(this); } public void setInsulated() @@ -445,16 +466,15 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN public boolean isBlockedOnSide(ForgeDirection side) { TMultiPart blocker = tile().partMap(side.ordinal()); - this.testingSide = side; + testingSide = side; boolean expandable = NormalOcclusionTest.apply(this, blocker); - this.testingSide = null; + testingSide = null; return !expandable; } @Override public void onPartChanged(TMultiPart part) { - this.refresh(); + refresh(); } - -} +} \ No newline at end of file diff --git a/src/resonantinduction/wire/multipart/javatraits/TEnergySink.java b/src/resonantinduction/wire/TEnergySink.java similarity index 77% rename from src/resonantinduction/wire/multipart/javatraits/TEnergySink.java rename to src/resonantinduction/wire/TEnergySink.java index af271b41f..39d9465b2 100644 --- a/src/resonantinduction/wire/multipart/javatraits/TEnergySink.java +++ b/src/resonantinduction/wire/TEnergySink.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.multipart.javatraits; +package resonantinduction.wire; import ic2.api.energy.tile.IEnergySink; @@ -18,41 +18,54 @@ public class TEnergySink extends TileMultipart implements IEnergySink public void copyFrom(TileMultipart that) { super.copyFrom(that); - if (that instanceof TEnergySink) - ic2Sinks = ((TEnergySink) that).ic2Sinks; + + if(that instanceof TEnergySink) + { + ic2Sinks = ((TEnergySink)that).ic2Sinks; + } } @Override public void bindPart(TMultiPart part) { super.bindPart(part); - if (part instanceof IEnergySink) + + if(part instanceof IEnergySink) + { ic2Sinks.add((IEnergySink) part); + } } @Override public void partRemoved(TMultiPart part, int p) { super.partRemoved(part, p); - if (part instanceof IEnergySink) + + if(part instanceof IEnergySink) + { ic2Sinks.remove(part); + } } @Override public void clearParts() { super.clearParts(); + ic2Sinks.clear(); } @Override public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) { - for (IEnergySink sink : this.ic2Sinks) + for(IEnergySink sink : ic2Sinks) { - if (sink.acceptsEnergyFrom(emitter, direction)) + if(sink.acceptsEnergyFrom(emitter, direction)) + { return true; + } } + return false; } @@ -61,20 +74,22 @@ public class TEnergySink extends TileMultipart implements IEnergySink { double demanded = 0; - for (IEnergySink sink : this.ic2Sinks) + for(IEnergySink sink : ic2Sinks) { demanded += sink.demandedEnergyUnits(); } + return demanded; } @Override public double injectEnergyUnits(ForgeDirection directionFrom, double amount) { - for (IEnergySink sink : this.ic2Sinks) + for(IEnergySink sink : ic2Sinks) { amount = sink.injectEnergyUnits(directionFrom, Math.min(amount, sink.demandedEnergyUnits())); } + return amount; } @@ -82,10 +97,12 @@ public class TEnergySink extends TileMultipart implements IEnergySink public int getMaxSafeInput() { int safe = 0; - for (IEnergySink sink : this.ic2Sinks) + + for(IEnergySink sink : ic2Sinks) { safe += sink.getMaxSafeInput(); } + return safe; } diff --git a/src/resonantinduction/wire/TileEntityWire.java b/src/resonantinduction/wire/TileEntityWire.java index e509cf397..91822d115 100644 --- a/src/resonantinduction/wire/TileEntityWire.java +++ b/src/resonantinduction/wire/TileEntityWire.java @@ -2,22 +2,25 @@ package resonantinduction.wire; import java.util.ArrayList; +import resonantinduction.ResonantInduction; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.PacketHandler; -import resonantinduction.base.IPacketReceiver; import universalelectricity.compatibility.Compatibility; import universalelectricity.compatibility.TileEntityUniversalConductor; import universalelectricity.core.block.INetworkProvider; import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.VectorHelper; import buildcraft.api.power.PowerHandler; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.network.IPacketSender; +import calclavia.lib.network.PacketHandler; import com.google.common.io.ByteArrayDataInput; -public class TileEntityWire extends TileEntityUniversalConductor implements IPacketReceiver, IInsulatedMaterial +public class TileEntityWire extends TileEntityUniversalConductor implements IPacketSender, IPacketReceiver, IInsulatedMaterial { public static final int DEFAULT_COLOR = 16; public int dyeID = DEFAULT_COLOR; @@ -124,18 +127,25 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac } @Override - public Packet getDescriptionPacket() + public ArrayList getPacketData(int type) { - return PacketHandler.getTileEntityPacket(this, this.isInsulated, this.dyeID); + ArrayList data = new ArrayList(); + return data; } @Override - public void handle(ByteArrayDataInput input) + public Packet getDescriptionPacket() + { + return ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(1)); + } + + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player) { try { - this.isInsulated = input.readBoolean(); - this.dyeID = input.readInt(); + this.isInsulated = data.readBoolean(); + this.dyeID = data.readInt(); } catch (Exception e) { @@ -165,12 +175,6 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac nbt.setBoolean("isInsulated", this.isInsulated); } - @Override - public ArrayList getNetworkedData(ArrayList data) - { - return null; - } - @Override public void doWork(PowerHandler workProvider) { @@ -204,4 +208,5 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac { setDye(dyeID); } + }