Started revive on Resonant Induction

This commit is contained in:
Calclavia 2013-12-19 21:12:46 +08:00
parent 8151b81eb8
commit 49427ab5a6
25 changed files with 686 additions and 784 deletions

View file

@ -1,7 +1,7 @@
package resonantinduction; package resonantinduction;
import resonantinduction.wire.EnumWireMaterial; import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.multipart.PartWire; import resonantinduction.wire.PartWire;
import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator; import codechicken.multipart.MultipartGenerator;

View file

@ -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
}
}

View file

@ -29,6 +29,8 @@ import resonantinduction.contractor.ItemBlockContractor;
import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemLinker; import resonantinduction.entangler.ItemLinker;
import resonantinduction.entangler.ItemQuantumEntangler; import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.furnace.BlockAdvancedFurnace;
import resonantinduction.furnace.TileEntityAdvancedFurnace;
import resonantinduction.multimeter.BlockMultimeter; import resonantinduction.multimeter.BlockMultimeter;
import resonantinduction.multimeter.ItemBlockMultimeter; import resonantinduction.multimeter.ItemBlockMultimeter;
import resonantinduction.multimeter.MultimeterEventHandler; import resonantinduction.multimeter.MultimeterEventHandler;
@ -44,7 +46,9 @@ import universalelectricity.core.item.IItemElectric;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper; import universalelectricity.prefab.TranslationHelper;
import basiccomponents.api.BasicRegistry; 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.FMLLog;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
@ -155,6 +159,11 @@ public class ResonantInduction
private static Block blockWire; private static Block blockWire;
public static Block blockAdvancedFurnaceIdle, blockAdvancedFurnaceBurning; 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) }; 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 @EventHandler
@ -317,25 +326,25 @@ public class ResonantInduction
final ItemStack defaultWire = EnumWireMaterial.IRON.getWire(); final ItemStack defaultWire = EnumWireMaterial.IRON.getWire();
/** Capacitor **/ /** 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 **/ /** 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 **/ /** 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 */ /** 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 */ /** 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 */ /** 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 */ /** 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 **/ /** Wires **/
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.COPPER.getWire(3), "MMM", 'M', "ingotCopper")); GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.COPPER.getWire(3), "MMM", 'M', "ingotCopper"));

View file

@ -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);
}

View file

@ -19,14 +19,15 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction;
import resonantinduction.api.ICapacitor; import resonantinduction.api.ICapacitor;
import resonantinduction.base.IPacketReceiver;
import resonantinduction.base.ListUtil; import resonantinduction.base.ListUtil;
import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.compatibility.TileEntityUniversalElectrical;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.item.IItemElectric; import universalelectricity.core.item.IItemElectric;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.IPacketSender;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
@ -38,7 +39,7 @@ import cpw.mods.fml.common.network.Player;
* *
* @author AidanBrady * @author AidanBrady
*/ */
public class TileEntityBattery extends TileEntityUniversalElectrical implements IPacketReceiver, IInventory public class TileEntityBattery extends TileEntityUniversalElectrical implements IPacketSender, IPacketReceiver, IInventory
{ {
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>(); public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
@ -178,7 +179,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
for (EntityPlayer player : this.playersUsing) 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(); this.produce();
@ -192,7 +193,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
public void updateClient() public void updateClient()
{ {
PacketHandler.sendPacketToAllPlayers(this, getNetworkedData(new ArrayList()).toArray()); PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
} }
public void updateAllClients() public void updateAllClients()
@ -200,18 +201,7 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
for (Vector3 vec : structure.locations) for (Vector3 vec : structure.locations)
{ {
TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj); TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj);
PacketHandler.sendPacketToAllPlayers(battery, battery.getNetworkedData(new ArrayList()).toArray()); PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(battery, battery.getPacketData(0).toArray()));
}
}
@Override
public void validate()
{
super.validate();
if (worldObj.isRemote)
{
PacketHandler.sendDataRequest(this);
} }
} }
@ -479,28 +469,23 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
} }
@Override @Override
public void handle(ByteArrayDataInput input) public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
{ {
try structure.isMultiblock = data.readBoolean();
{
structure.isMultiblock = input.readBoolean();
clientEnergy = input.readFloat(); clientEnergy = data.readFloat();
clientCells = input.readInt(); clientCells = data.readInt();
clientMaxEnergy = input.readFloat(); clientMaxEnergy = data.readFloat();
structure.height = input.readInt(); structure.height = data.readInt();
structure.length = input.readInt(); structure.length = data.readInt();
structure.width = input.readInt(); structure.width = data.readInt();
}
catch (Exception e)
{
}
} }
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getPacketData(int type)
{ {
ArrayList data = new ArrayList();
data.add(structure.isMultiblock); data.add(structure.isMultiblock);
data.add(getEnergyStored()); data.add(getEnergyStored());

View file

@ -99,7 +99,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
if (tileEntity instanceof IInventory) if (tileEntity instanceof IInventory)
{ {
tileContractor.setFacing(side.getOpposite()); tileContractor.setDirection(side.getOpposite());
return; return;
} }
} }

View file

@ -23,7 +23,7 @@ public class ItemBlockContractor extends ItemBlock
if (place) if (place)
{ {
TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z); TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z);
tileContractor.setFacing(ForgeDirection.getOrientation(side)); tileContractor.setDirection(ForgeDirection.getOrientation(side));
if (!tileContractor.isLatched()) if (!tileContractor.isLatched())
{ {
@ -33,7 +33,7 @@ public class ItemBlockContractor extends ItemBlock
if (tileEntity instanceof IInventory) if (tileEntity instanceof IInventory)
{ {
tileContractor.setFacing(side1.getOpposite()); tileContractor.setDirection(side1.getOpposite());
break; break;
} }
} }

View file

@ -11,6 +11,7 @@ import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockSnow; import net.minecraft.block.BlockSnow;
import net.minecraft.block.BlockVine; import net.minecraft.block.BlockVine;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -20,13 +21,13 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidBlock;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.base.IPacketReceiver;
import resonantinduction.base.InventoryUtil;
import resonantinduction.tesla.TileEntityTesla; import resonantinduction.tesla.TileEntityTesla;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityAdvanced; 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; import com.google.common.io.ByteArrayDataInput;
@ -35,7 +36,7 @@ import com.google.common.io.ByteArrayDataInput;
* @author AidanBrady * @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 MAX_REACH = 40;
public static int PUSH_DELAY = 5; public static int PUSH_DELAY = 5;
@ -69,7 +70,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
public void initiate() public void initiate()
{ {
super.initiate(); super.initiate();
this.updateBounds(); updateBounds();
} }
@Override @Override
@ -77,16 +78,16 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
{ {
super.updateEntity(); 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()) if (canFunction())
@ -96,7 +97,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
if (!suck && pushDelay == 0) if (!suck && pushDelay == 0)
{ {
ItemStack retrieved = InventoryUtil.takeTopItemFromInventory(inventory, this.getDirection().ordinal()); ItemStack retrieved = InventoryHelper.takeTopItemFromInventory(inventory, getDirection().getOpposite().ordinal());
if (retrieved != null) if (retrieved != null)
{ {
@ -104,7 +105,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
this.worldObj.spawnEntityInWorld(item); worldObj.spawnEntityInWorld(item);
} }
pushDelay = PUSH_DELAY; pushDelay = PUSH_DELAY;
@ -113,10 +114,12 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
else if (suck) else if (suck)
{ {
if (suckBounds != null) if (suckBounds != null)
{
if (!worldObj.isRemote)
{ {
for (EntityItem item : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds)) for (EntityItem item : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds))
{ {
ItemStack remains = InventoryUtil.putStackInInventory(inventory, item.getEntityItem(), this.getDirection().ordinal()); ItemStack remains = InventoryHelper.putStackInInventory(inventory, item.getEntityItem(), getDirection().getOpposite().ordinal(), false);
if (remains == null) if (remains == null)
{ {
@ -129,92 +132,85 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
} }
} }
} }
}
if (this.thread != null) if (thread != null)
{ {
PathfinderEMContractor newPath = this.thread.getPath(); PathfinderEMContractor newPath = thread.getPath();
if (newPath != null) if (newPath != null)
{ {
this.pathfinder = newPath; pathfinder = newPath;
this.thread = null; thread = null;
} }
} }
final int renderFrequency = ResonantInduction.proxy.isFancy() ? 1 + this.worldObj.rand.nextInt(2) : 10 + this.worldObj.rand.nextInt(2); final int renderFrequency = ResonantInduction.proxy.isFancy() ? 1 + worldObj.rand.nextInt(2) : 10 + worldObj.rand.nextInt(2);
final boolean renderBeam = this.ticks % renderFrequency == 0 && this.linked != null && !this.linked.isInvalid() && this.linked.suck != this.suck; 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) 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.
* Push entity along path. if (pathfinder != null)
*/
if (this.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) 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); Vector3 difference = prevResult.clone().difference(result);
final ForgeDirection direction = difference.toForgeDirection(); final ForgeDirection direction = difference.toForgeDirection();
if (renderBeam) 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); AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1);
List<EntityItem> entities = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); List<EntityItem> entities = worldObj.getEntitiesWithinAABB(EntityItem.class, bounds);
for (EntityItem entityItem : entities) for (EntityItem entityItem : entities)
{ {
this.moveEntity(entityItem, direction, result); moveEntity(entityItem, direction, result);
} }
} }
} }
else else
{ {
this.updatePath(); updatePath();
break; break;
} }
} }
} }
else else
{ {
this.updatePath(); updatePath();
}
} }
} }
else else
{ {
if (renderBeam && this.linked != null && this.linked.pathfinder != null) 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);
} }
this.pathfinder = null; pathfinder = null;
AxisAlignedBB searchBounds = this.operationBounds; 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 (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) if (searchBounds != null)
{ {
@ -222,16 +218,29 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
{ {
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(entityItem), ResonantInduction.DYE_COLORS[dyeID], false);
} }
this.moveEntity(entityItem, this.getDirection(), new Vector3(this)); moveEntity(entityItem, getDirection(), new Vector3(this));
} }
} }
} }
} }
else if (!hasLink())
{
for (EntityItem entityItem : (List<EntityItem>) 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) 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)); 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) private void moveEntity(EntityItem entityItem, ForgeDirection direction, Vector3 lockVector)
{ {
switch (direction) switch (direction)
@ -348,6 +362,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
break; break;
} }
entityItem.ticksExisted = 1;
entityItem.isAirBorne = true; entityItem.isAirBorne = true;
entityItem.delayBeforeCanPickup = 1; entityItem.delayBeforeCanPickup = 1;
entityItem.age = Math.max(entityItem.age - 1, 0); entityItem.age = Math.max(entityItem.age - 1, 0);
@ -357,7 +372,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
{ {
EntityItem item = null; EntityItem item = null;
switch (this.getDirection()) switch (getDirection())
{ {
case DOWN: case DOWN:
item = new EntityItem(worldObj, xCoord + 0.5, yCoord - 0.2, zCoord + 0.5, toSend); 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; return item;
} }
@Override
public void validate()
{
super.validate();
if (worldObj.isRemote)
{
PacketHandler.sendDataRequest(this);
}
}
public void updateBounds() public void updateBounds()
{ {
switch (this.getDirection()) switch (getDirection())
{ {
case DOWN: case DOWN:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, Math.max(yCoord - MAX_REACH, 1), zCoord, xCoord + 1, yCoord, zCoord + 1); 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() 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); TileEntity tile = worldObj.getBlockTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
@ -453,92 +457,95 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
public void incrementFacing() public void incrementFacing()
{ {
int newOrdinal = this.getDirection().ordinal() < 5 ? this.getDirection().ordinal() + 1 : 0; int newOrdinal = getDirection().ordinal() < 5 ? getDirection().ordinal() + 1 : 0;
this.setFacing(ForgeDirection.getOrientation(newOrdinal)); setDirection(ForgeDirection.getOrientation(newOrdinal));
} }
public ForgeDirection getDirection() 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); this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, side.ordinal(), 3);
this.updateBounds();
if (!worldObj.isRemote)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
updateBounds();
}
public boolean canFunction()
{
return isLatched() && !this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public ArrayList getPacketData(int type)
{ {
super.readFromNBT(nbt); ArrayList data = new ArrayList();
this.suck = nbt.getBoolean("suck"); data.add(suck);
this.dyeID = nbt.getInteger("dyeID"); data.add(dyeID);
this.tempLinkVector = new Vector3(nbt.getCompoundTag("link"));
}
@Override if (linked != null)
public void writeToNBT(NBTTagCompound nbt)
{ {
super.writeToNBT(nbt); data.add(true);
nbt.setBoolean("suck", suck);
nbt.setInteger("dyeID", this.dyeID);
if (this.linked != null) data.add(linked.xCoord);
{ data.add(linked.yCoord);
nbt.setCompoundTag("link", new Vector3(this.linked).writeToNBT(new NBTTagCompound())); data.add(linked.zCoord);
} }
} else
@Override
public void handle(ByteArrayDataInput input)
{ {
try data.add(false);
{
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();
}
catch (Exception e)
{
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return data; return data;
} }
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
if (this.linked != null) return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray());
{
return PacketHandler.getTileEntityPacket(this, this.suck, this.dyeID, true, this.linked.xCoord, this.linked.yCoord, this.linked.zCoord);
} }
else
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
{ {
return PacketHandler.getTileEntityPacket(this, this.suck, this.dyeID, false); suck = data.readBoolean();
dyeID = data.readInt();
if (data.readBoolean())
{
tempLinkVector = new Vector3(data.readInt(), data.readInt(), data.readInt());
}
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"))
{
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) 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) if (setOpponent)
{ {
this.linked.setLink(this, false); linked.setLink(this, false);
} }
this.updatePath(); updatePath();
} }
public void updatePath() public void updatePath()
{ {
if (this.thread == null && this.linked != null && this.lastCalcTime <= 0) if (thread == null && linked != null && lastCalcTime <= 0)
{ {
this.pathfinder = null; pathfinder = null;
Vector3 start = new Vector3(this).modifyPositionFromSide(this.getDirection());
Vector3 target = new Vector3(this.linked).modifyPositionFromSide(this.linked.getDirection()); Vector3 start = new Vector3(this).modifyPositionFromSide(getDirection());
Vector3 target = new Vector3(linked).modifyPositionFromSide(linked.getDirection());
if (start.distance(target) < ResonantInduction.MAX_CONTRACTOR_DISTANCE) 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); thread = new ThreadEMPathfinding(new PathfinderEMContractor(worldObj, target), start);
this.thread.start(); thread.start();
this.lastCalcTime = 40; lastCalcTime = 40;
} }
} }
} }
} }
/** public void setDye(int dye)
* @param itemDamage
*/
public void setDye(int dyeID)
{ {
this.dyeID = dyeID; dyeID = dye;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
} }

View file

@ -1,4 +1,4 @@
package resonantinduction; package resonantinduction.furnace;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace; import net.minecraft.block.BlockFurnace;

View file

@ -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.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;

View file

@ -11,10 +11,10 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.multimeter.ContainerMultimeter; import resonantinduction.multimeter.ContainerMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter; import resonantinduction.multimeter.TileEntityMultimeter;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -59,7 +59,7 @@ public class GuiMultimeter extends GuiContainer
try 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) catch (Exception e)
{ {
@ -104,7 +104,7 @@ public class GuiMultimeter extends GuiContainer
@Override @Override
protected void actionPerformed(GuiButton button) protected void actionPerformed(GuiButton button)
{ {
PacketHandler.sendPacketToServer(this.tileEntity, (byte) 2); PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this.tileEntity, (byte) 2));
} }
} }

View file

@ -14,17 +14,18 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.base.IPacketReceiver;
import universalelectricity.core.block.IConductor; import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IConnector; import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.IElectricalStorage; import universalelectricity.core.block.IElectricalStorage;
import universalelectricity.core.grid.IElectricityNetwork; import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.prefab.tile.IRotatable;
import universalelectricity.prefab.tile.TileEntityAdvanced; import universalelectricity.prefab.tile.TileEntityAdvanced;
import universalelectricity.prefab.tile.TileEntityElectrical; import universalelectricity.prefab.tile.TileEntityElectrical;
import buildcraft.api.power.IPowerReceptor; 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; import com.google.common.io.ByteArrayDataInput;
@ -37,7 +38,7 @@ import cpw.mods.fml.common.network.Player;
* @author Calclavia * @author Calclavia
* *
*/ */
public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketReceiver, IConnector, IRotatable public class TileEntityMultimeter extends TileEntityAdvanced implements IConnector, IRotatable, IPacketReceiver, IPacketSender
{ {
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>(); public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
@ -48,9 +49,9 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR
public String display; 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(); super.updateEntity();
if (!this.worldObj.isRemote) if (!worldObj.isRemote)
{ {
if (this.ticks % 20 == 0) if (ticks % 20 == 0)
{ {
float prevDetectedEnergy = this.detectedEnergy; float prevDetectedEnergy = detectedEnergy;
this.updateDetection(this.doGetDetectedEnergy()); updateDetection(doGetDetectedEnergy());
boolean outputRedstone = false; boolean outputRedstone = false;
@ -80,86 +81,84 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR
default: default:
break; break;
case EQUAL: case EQUAL:
outputRedstone = this.detectedEnergy == this.energyLimit; outputRedstone = detectedEnergy == energyLimit;
break; break;
case GREATER_THAN: case GREATER_THAN:
outputRedstone = this.detectedEnergy > this.energyLimit; outputRedstone = detectedEnergy > energyLimit;
break; break;
case GREATER_THAN_EQUAL: case GREATER_THAN_EQUAL:
outputRedstone = this.detectedEnergy >= this.energyLimit; outputRedstone = detectedEnergy >= energyLimit;
break; break;
case LESS_THAN: case LESS_THAN:
outputRedstone = this.detectedEnergy < this.energyLimit; outputRedstone = detectedEnergy < energyLimit;
break; break;
case LESS_THAN_EQUAL: case LESS_THAN_EQUAL:
outputRedstone = this.detectedEnergy <= this.energyLimit; outputRedstone = detectedEnergy <= energyLimit;
break; break;
} }
if (outputRedstone != this.redstoneOn) if (outputRedstone != redstoneOn)
{ {
this.redstoneOn = outputRedstone; redstoneOn = outputRedstone;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID); 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 @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.getTileEntityPacket(this, (byte) 1, (byte) this.detectMode.ordinal(), this.detectedEnergy, this.energyLimit); return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray());
}
@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;
} }
public float doGetDetectedEnergy() public float doGetDetectedEnergy()
{ {
ForgeDirection direction = this.getDirection(); ForgeDirection direction = getDirection();
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
return getDetectedEnergy(direction.getOpposite(), tileEntity); return getDetectedEnergy(direction.getOpposite(), tileEntity);
} }
@ -186,9 +185,9 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR
{ {
return ((IEnergyStorage) tileEntity).getStored(); 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) else if (tileEntity instanceof IPowerReceptor)
{ {
@ -203,82 +202,72 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR
public void updateDetection(float detected) public void updateDetection(float detected)
{ {
this.detectedEnergy = detected; detectedEnergy = detected;
this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2; detectedAverageEnergy = (detectedAverageEnergy + detectedEnergy) / 2;
this.peakDetection = Math.max(peakDetection, this.detectedEnergy); peakDetection = Math.max(peakDetection, detectedEnergy);
} }
public float getDetectedEnergy() public float getDetectedEnergy()
{ {
return this.detectedEnergy; return detectedEnergy;
} }
public float getAverageDetectedEnergy() public float getAverageDetectedEnergy()
{ {
return this.detectedAverageEnergy; return detectedAverageEnergy;
} }
public void toggleMode() 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 @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.detectMode = DetectMode.values()[nbt.getInteger("detectMode")]; detectMode = DetectMode.values()[nbt.getInteger("detectMode")];
this.energyLimit = nbt.getFloat("energyLimit"); energyLimit = nbt.getFloat("energyLimit");
} }
/**
* Writes a tile entity to NBT.
*/
@Override @Override
public void writeToNBT(NBTTagCompound nbt) public void writeToNBT(NBTTagCompound nbt)
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setInteger("detectMode", this.detectMode.ordinal()); nbt.setInteger("detectMode", detectMode.ordinal());
nbt.setFloat("energyLimit", this.energyLimit); nbt.setFloat("energyLimit", energyLimit);
} }
public DetectMode getMode() public DetectMode getMode()
{ {
return this.detectMode; return detectMode;
} }
public float getLimit() public float getLimit()
{ {
return this.energyLimit; return energyLimit;
} }
/**
* @return
*/
public float getPeak() public float getPeak()
{ {
return this.peakDetection; return peakDetection;
} }
@Override @Override
public boolean canConnect(ForgeDirection direction) public boolean canConnect(ForgeDirection direction)
{ {
return direction == this.getDirection(); return direction == getDirection();
} }
@Override @Override
public ForgeDirection getDirection() public ForgeDirection getDirection()
{ {
return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); return ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
} }
@Override @Override
public void setDirection(ForgeDirection direction) 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);
} }
} }

View file

@ -12,8 +12,8 @@ import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.wire.multipart.PartConductor; import resonantinduction.wire.PartConductor;
import resonantinduction.wire.multipart.PartWire; import resonantinduction.wire.PartWire;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import codechicken.lib.colour.Colour; import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA; import codechicken.lib.colour.ColourRGBA;

View file

@ -12,6 +12,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -20,13 +21,13 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.api.ITesla; import resonantinduction.api.ITesla;
import resonantinduction.base.IPacketReceiver;
import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.compatibility.TileEntityUniversalElectrical;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.IPacketSender;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
@ -40,7 +41,7 @@ import cpw.mods.fml.common.network.PacketDispatcher;
* @author Calclavia * @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 static int DEFAULT_COLOR = 12;
public final float TRANSFER_CAP = 10; public final float TRANSFER_CAP = 10;
@ -281,63 +282,64 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
return this.isController(); 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 @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID, this.canReceive, this.attackEntities, this.linked != null); return ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(1));
}
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;
}
} }
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
{
return null;
}
@Override
public void handle(ByteArrayDataInput input)
{ {
try try
{ {
switch (input.readByte()) switch (data.readByte())
{ {
case 1: case 1:
this.setEnergyStored(input.readFloat()); this.setEnergyStored(data.readFloat());
this.dyeID = input.readInt(); this.dyeID = data.readInt();
this.canReceive = input.readBoolean(); this.canReceive = data.readBoolean();
this.attackEntities = input.readBoolean(); this.attackEntities = data.readBoolean();
this.isLinkedClient = input.readBoolean(); this.isLinkedClient = data.readBoolean();
break; break;
case 2: case 2:
this.setEnergyStored(input.readFloat()); this.setEnergyStored(data.readFloat());
break; break;
case 3: case 3:
this.doTransfer = true; this.doTransfer = true;

View file

@ -9,12 +9,10 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.TabRI; import resonantinduction.TabRI;
import universalelectricity.core.block.IConductor;
import universalelectricity.prefab.block.BlockConductor; import universalelectricity.prefab.block.BlockConductor;
/** /**

View file

@ -16,54 +16,63 @@ import universalelectricity.core.vector.Vector3;
public enum EnumWireMaterial public enum EnumWireMaterial
{ {
COPPER(12.5f, 3, 2, new Vector3(184, 115, 51)), TIN(13, 2, 0.5f, new Vector3(132, 132, 130)), COPPER("Copper", 12.5F, 3, 2, new Vector3(184, 115, 51)),
IRON(0.1f, 2, 4, new Vector3(97, 102, 105)), TIN("Tin", 13, 2, 0.5F, new Vector3(132, 132, 130)),
ALUMINUM(0.025f, 6, 0.15f, new Vector3(215, 205, 181)), IRON("Iron", 0.1F, 2, 4, new Vector3(97, 102, 105)),
SILVER(0.005f, 1, 2, new Vector3(192, 192, 192)), ALUMINUM("Aluminum", 0.025F, 6, 0.15F, new Vector3(215, 205, 181)),
SUPERCONDUCTOR(0, 8, Float.MAX_VALUE, new Vector3(212, 175, 55)); 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 resistance;
public final float damage; public final float damage;
public final float maxAmps; public final float maxAmps;
public final Vector3 color; public final Vector3 color;
private ItemStack wire; 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; name = s;
this.damage = electrocutionDamage; resistance = resist;
this.maxAmps = maxAmps; damage = electrocution;
this.color = color.scale(1D / 255D); maxAmps = max;
color = vec.scale(1D / 255D);
}
public String getName()
{
return name;
} }
public ItemStack getWire() public ItemStack getWire()
{ {
return this.getWire(1); return getWire(1);
} }
public ItemStack getWire(int amount) public ItemStack getWire(int amount)
{ {
ItemStack returnStack = this.wire.copy(); ItemStack returnStack = wire.copy();
returnStack.stackSize = amount; returnStack.stackSize = amount;
return returnStack; return returnStack;
} }
public void setWire(ItemStack item) public void setWire(ItemStack item)
{ {
if (this.wire == null) if (wire == null)
{ {
this.wire = item; wire = item;
OreDictionary.registerOre(this.name().toLowerCase() + "Wire", this.wire); OreDictionary.registerOre(getName().toLowerCase() + "Wire", wire);
} }
} }
public void setWire(Item item) public void setWire(Item item)
{ {
this.setWire(new ItemStack(item, 1, this.ordinal())); setWire(new ItemStack(item, 1, ordinal()));
} }
public void setWire(Block block) public void setWire(Block block)
{ {
this.setWire(new ItemStack(block, 1, this.ordinal())); setWire(new ItemStack(block, 1, ordinal()));
} }
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;

View file

@ -8,5 +8,5 @@ public interface IInsulation
public int getInsulationColor(); public int getInsulationColor();
public void setInsulationColor(int dyeID); public void setInsulationColor(int dye);
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import java.util.List; import java.util.List;
@ -12,7 +12,6 @@ import net.minecraftforge.common.Configuration;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.TabRI; import resonantinduction.TabRI;
import resonantinduction.render.RenderPartWire; import resonantinduction.render.RenderPartWire;
import resonantinduction.wire.EnumWireMaterial;
import universalelectricity.core.electricity.ElectricityDisplay; import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
@ -29,22 +28,15 @@ public class ItemPartWire extends JItemMultiPart
public ItemPartWire(int id) public ItemPartWire(int id)
{ {
super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "wireMultipart", id).getInt(id)); super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "wireMultipart", id).getInt(id));
this.setUnlocalizedName(ResonantInduction.PREFIX + "wire"); setCreativeTab(TabRI.INSTANCE);
this.setCreativeTab(TabRI.INSTANCE); setHasSubtypes(true);
this.setHasSubtypes(true); setMaxDamage(0);
this.setMaxDamage(0);
} }
@Override @Override
public TMultiPart newPart(ItemStack arg0, EntityPlayer arg1, World arg2, BlockCoord arg3, int arg4, Vector3 arg5) public TMultiPart newPart(ItemStack arg0, EntityPlayer arg1, World arg2, BlockCoord arg3, int arg4, Vector3 arg5)
{ {
return new PartWire(this.getDamage(arg0)); return new PartWire(getDamage(arg0));
}
@Override
public String getUnlocalizedName()
{
return super.getUnlocalizedName().replace("item", "tile");
} }
@Override @Override
@ -56,39 +48,39 @@ public class ItemPartWire extends JItemMultiPart
@Override @Override
public String getUnlocalizedName(ItemStack itemStack) public String getUnlocalizedName(ItemStack itemStack)
{ {
return this.getUnlocalizedName() + "." + EnumWireMaterial.values()[itemStack.getItemDamage()].name().toLowerCase(); return "tile.Wire." + EnumWireMaterial.values()[itemStack.getItemDamage()].getName() + "Wire";
} }
@Override @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)); list.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("Max Amperage: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, ElectricUnit.AMPERE));
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) public void registerIcons(IconRegister register)
{ {
for (int i = 0; i < EnumWireMaterial.values().length; i++) 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 @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int meta) public Icon getIconFromDamage(int meta)
{ {
return this.icons[meta]; return icons[meta];
} }
@Override @Override
public void getSubItems(int itemID, CreativeTabs tab, List listToAddTo) 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())); listToAddTo.add(new ItemStack(itemID, 1, mat.ordinal()));
} }
@ -100,5 +92,4 @@ public class ItemPartWire extends JItemMultiPart
{ {
return 0; return 0;
} }
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
@ -11,29 +11,27 @@ public abstract class PartAdvanced extends TMultiPart
@Override @Override
public void update() 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 @Override
public void onAdded() 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. * Called on the TileEntity's first tick.
*/ */
public void initiate() public void initiate() {}
{
}
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -33,14 +33,13 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public void bind(TileMultipart t) 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); super.bind(t);
this.getNetwork().getConductors().add((IConductor) tile()); getNetwork().getConductors().add((IConductor) tile());
} }
else else {
{
super.bind(t); super.bind(t);
} }
} }
@ -48,9 +47,9 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public void preRemove() 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(); super.preRemove();
@ -65,29 +64,30 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public IElectricityNetwork getNetwork() 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) 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; return notPrevented;
} }
@Override @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 * @param side The side we're checking
* @return Whether we're preventing connections on given side or to given tileEntity * @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; return false;
} }
@ -106,12 +106,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
{ {
byte connections = 0x00; byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if(tileEntity instanceof INetworkProvider && canConnectBothSides(tileEntity, side))
{ {
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side);
if (tileEntity instanceof INetworkProvider && this.canConnectBothSides(tileEntity, side))
connections |= 1 << side.ordinal(); connections |= 1 << side.ordinal();
} }
}
return connections; return connections;
} }
@ -119,12 +123,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
{ {
byte connections = 0x00; byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if(isValidAcceptor(tileEntity) && canConnectBothSides(tileEntity, side))
{ {
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side);
if (this.isValidAcceptor(tileEntity) && this.canConnectBothSides(tileEntity, side))
connections |= 1 << side.ordinal(); connections |= 1 << side.ordinal();
} }
}
return connections; return connections;
} }
@ -139,44 +147,46 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public void refresh() public void refresh()
{ {
if (!this.world().isRemote) if(!world().isRemote)
{ {
this.adjacentConnections = null; adjacentConnections = null;
byte possibleWireConnections = getPossibleWireConnections(); byte possibleWireConnections = getPossibleWireConnections();
byte possibleAcceptorConnections = getPossibleAcceptorConnections(); byte possibleAcceptorConnections = getPossibleAcceptorConnections();
if (possibleWireConnections != currentWireConnections) if(possibleWireConnections != currentWireConnections)
{ {
byte or = (byte) (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()); getNetwork().split((IConductor) tile());
this.setNetwork(null); 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(); getNetwork().refresh();
this.sendDescUpdate(); sendDescUpdate();
} }
this.tile().markRender(); tile().markRender();
} }
/** /**
@ -186,27 +196,27 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public TileEntity[] getAdjacentConnections() 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); 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; adjacentConnections[i] = tileEntity;
} }
} }
} }
return this.adjacentConnections; return adjacentConnections;
} }
public boolean isCurrentlyConnected(ForgeDirection side) 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) public boolean canConnect(ForgeDirection direction)
{ {
Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction); Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(this.world()); TileEntity connectTile = connectPos.getTileEntity(world());
return !connectionPrevented(connectTile, direction); return !isConnectionPrevented(connectTile, direction);
} }
@Override @Override
public void onAdded() public void onAdded()
{ {
super.onAdded(); super.onAdded();
this.refresh(); refresh();
} }
@Override @Override
public void onChunkLoad() public void onChunkLoad()
{ {
super.onChunkLoad(); super.onChunkLoad();
this.refresh(); refresh();
} }
@Override @Override
public void onNeighborChanged() public void onNeighborChanged()
{ {
super.onNeighborChanged(); super.onNeighborChanged();
this.refresh(); refresh();
} }
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent; 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;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type; 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; protected boolean isAddedToEnergyNet;
public PowerHandler powerHandler; public PowerHandler powerHandler;
public float buildcraftBuffer = Compatibility.BC3_RATIO * 50; public float buildcraftBuffer = Compatibility.BC3_RATIO * 50;
public PartUniversalConductor() public PartUniversalConductor()
{ {
this.powerHandler = new PowerHandler(this, Type.PIPE); powerHandler = new PowerHandler(this, Type.PIPE);
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2); powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, buildcraftBuffer * 2);
this.powerHandler.configurePowerPerdition(0, 0); powerHandler.configurePowerPerdition(0, 0);
} }
@Override @Override
public boolean isValidAcceptor(TileEntity tile) public boolean isValidAcceptor(TileEntity tile)
{ {
if (Compatibility.isIndustrialCraft2Loaded() && tile instanceof IEnergyTile) if(tile instanceof IEnergyTile)
{ {
return true; return true;
} }
else if (Compatibility.isBuildcraftLoaded() && tile instanceof IPowerReceptor) else if(tile instanceof IPowerReceptor)
{ {
return true; return true;
} }
else if(tile instanceof IEnergyHandler)
{
return true;
}
return super.isValidAcceptor(tile); 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 @Override
public void onWorldJoin() public void onWorldJoin()
{ {
super.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() public void onAdded()
{ {
super.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() public void onChunkLoad()
{ {
super.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 @Override
public void onWorldSeparate() public void onWorldSeparate()
{ {
this.unloadTileIC2(); unloadTileIC2();
super.onWorldSeparate(); super.onWorldSeparate();
} }
@Override @Override
public void onChunkUnload() public void onChunkUnload()
{ {
this.unloadTileIC2(); unloadTileIC2();
super.onChunkUnload(); super.onChunkUnload();
} }
@Override @Override
public void onRemoved() public void onRemoved() {}
{
}
@Override @Override
public void preRemove() public void preRemove()
{ {
this.unloadTileIC2(); unloadTileIC2();
super.preRemove(); super.preRemove();
} }
protected void initIC() protected void initIC()
{ {
if (Compatibility.isIndustrialCraft2Loaded()) if(Compatibility.isIndustrialCraft2Loaded())
{ {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
} }
this.isAddedToEnergyNet = true; isAddedToEnergyNet = true;
} }
private void unloadTileIC2() 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())); MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
} }
this.isAddedToEnergyNet = false; isAddedToEnergyNet = false;
} }
} }
@Override @Override
public double demandedEnergyUnits() public double demandedEnergyUnits()
{ {
if (this.getNetwork() == null) if(getNetwork() == null)
{ {
return 0.0; return 0.0;
} }
return this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO; return getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO;
} }
@Override @Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) 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); 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 @Override
@ -174,7 +191,7 @@ public abstract class PartUniversalConductor extends PartConductor implements IE
@Override @Override
public PowerReceiver getPowerReceiver(ForgeDirection side) public PowerReceiver getPowerReceiver(ForgeDirection side)
{ {
return this.powerHandler.getPowerReceiver(); return powerHandler.getPowerReceiver();
} }
@Override @Override
@ -183,14 +200,14 @@ public abstract class PartUniversalConductor extends PartConductor implements IE
Set<TileEntity> ignoreTiles = new HashSet<TileEntity>(); Set<TileEntity> ignoreTiles = new HashSet<TileEntity>();
ignoreTiles.add(tile()); 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); ignoreTiles.add(tile);
} }
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120); ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120);
this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0])); getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0]));
} }
@Override @Override
@ -198,4 +215,50 @@ public abstract class PartUniversalConductor extends PartConductor implements IE
{ {
return world(); 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);
}
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart; package resonantinduction.wire;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -20,12 +20,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.render.RenderPartWire; 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 universalelectricity.compatibility.Compatibility;
import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler;
import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataInput;
@ -45,7 +40,6 @@ import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.PartMap; import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart; import codechicken.multipart.TSlottedPart;
import codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -88,7 +82,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
public PartWire(EnumWireMaterial type) public PartWire(EnumWireMaterial type)
{ {
super(); super();
this.material = type; material = type;
} }
public PartWire() public PartWire()
@ -99,7 +93,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
@Override @Override
public boolean canConnect(ForgeDirection direction) public boolean canConnect(ForgeDirection direction)
{ {
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{ {
return false; return false;
} }
@ -108,44 +102,50 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
} }
@Override @Override
public boolean connectionPrevented(TileEntity tile, ForgeDirection side) public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{ {
if (tile instanceof IWireMaterial) if (tile instanceof IWireMaterial)
{ {
IWireMaterial wireTile = (IWireMaterial) tile; IWireMaterial wireTile = (IWireMaterial) tile;
if (wireTile.getMaterial() != this.getMaterial()) if (wireTile.getMaterial() != getMaterial())
{
return true; return true;
} }
}
if (this.isInsulated() && tile instanceof IInsulation) if (isInsulated() && tile instanceof IInsulation)
{ {
IInsulation insulatedTile = (IInsulation) tile; 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 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 @Override
public byte getPossibleWireConnections() public byte getPossibleWireConnections()
{ {
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{ {
return 0x00; return 0x00;
} }
return super.getPossibleWireConnections(); return super.getPossibleWireConnections();
} }
@Override @Override
public byte getPossibleAcceptorConnections() public byte getPossibleAcceptorConnections()
{ {
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z())) if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{ {
return 0x00; return 0x00;
} }
return super.getPossibleAcceptorConnections(); return super.getPossibleAcceptorConnections();
} }
@ -172,23 +172,25 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
return material.ordinal(); return material.ordinal();
} }
public void setDye(int dyeID) public void setDye(int dye)
{ {
this.dyeID = dyeID; dyeID = dye;
this.refresh(); refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z()); world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
} }
public void setMaterialFromID(int id) public void setMaterialFromID(int id)
{ {
this.material = EnumWireMaterial.values()[id]; material = EnumWireMaterial.values()[id];
} }
@Override @Override
public void doWork(PowerHandler workProvider) public void doWork(PowerHandler workProvider)
{ {
this.buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(this.getMaterial().maxAmps, 100); buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(getMaterial().maxAmps, 100);
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2); powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, buildcraftBuffer * 2);
super.doWork(workProvider); super.doWork(workProvider);
} }
@ -208,16 +210,18 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
public Iterable<IndexedCuboid6> getSubParts() public Iterable<IndexedCuboid6> getSubParts()
{ {
Set<IndexedCuboid6> subParts = new HashSet<IndexedCuboid6>(); Set<IndexedCuboid6> subParts = new HashSet<IndexedCuboid6>();
IndexedCuboid6[] currentSides = this.isInsulated() ? insulatedSides : sides; IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides;
if (tile() != null) if (tile() != null)
{ {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{ {
int ord = side.ordinal(); int ord = side.ordinal();
if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == this.testingSide) if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide)
subParts.add(currentSides[ord]); subParts.add(currentSides[ord]);
} }
} }
subParts.add(currentSides[6]); subParts.add(currentSides[6]);
return subParts; return subParts;
} }
@ -227,6 +231,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
{ {
Set<Cuboid6> collisionBoxes = new HashSet<Cuboid6>(); Set<Cuboid6> collisionBoxes = new HashSet<Cuboid6>();
collisionBoxes.addAll((Collection<? extends Cuboid6>) getSubParts()); collisionBoxes.addAll((Collection<? extends Cuboid6>) getSubParts());
return collisionBoxes; return collisionBoxes;
} }
@ -235,8 +240,12 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
{ {
List<ItemStack> drops = new ArrayList<ItemStack>(); List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(pickItem(null)); drops.add(pickItem(null));
if (isInsulated) if (isInsulated)
{
drops.add(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))); drops.add(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)));
}
return drops; return drops;
} }
@ -251,16 +260,20 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass) public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass)
{ {
if (pass == 0) if (pass == 0)
{
RenderPartWire.INSTANCE.renderStatic(this); RenderPartWire.INSTANCE.renderStatic(this);
} }
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) 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); RenderPartWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame);
} }
}
@Override @Override
public void drawBreaking(RenderBlocks renderBlocks) public void drawBreaking(RenderBlocks renderBlocks)
@ -272,47 +285,50 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
@Override @Override
public void readDesc(MCDataInput packet) public void readDesc(MCDataInput packet)
{ {
this.setMaterialFromID(packet.readInt()); setMaterialFromID(packet.readInt());
this.dyeID = packet.readInt(); dyeID = packet.readInt();
this.isInsulated = packet.readBoolean(); isInsulated = packet.readBoolean();
this.currentWireConnections = packet.readByte(); currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte(); currentAcceptorConnections = packet.readByte();
if (tile() != null) if (tile() != null)
{
tile().markRender(); tile().markRender();
} }
}
@Override @Override
public void writeDesc(MCDataOutput packet) public void writeDesc(MCDataOutput packet)
{ {
packet.writeInt(this.getTypeID()); packet.writeInt(getTypeID());
packet.writeInt(this.dyeID); packet.writeInt(dyeID);
packet.writeBoolean(this.isInsulated); packet.writeBoolean(isInsulated);
packet.writeByte(this.currentWireConnections); packet.writeByte(currentWireConnections);
packet.writeByte(this.currentAcceptorConnections); packet.writeByte(currentAcceptorConnections);
} }
@Override @Override
public void save(NBTTagCompound nbt) public void save(NBTTagCompound nbt)
{ {
super.save(nbt); super.save(nbt);
nbt.setInteger("typeID", this.getTypeID()); nbt.setInteger("typeID", getTypeID());
nbt.setInteger("dyeID", this.dyeID); nbt.setInteger("dyeID", dyeID);
nbt.setBoolean("isInsulated", this.isInsulated); nbt.setBoolean("isInsulated", isInsulated);
} }
@Override @Override
public void load(NBTTagCompound nbt) public void load(NBTTagCompound nbt)
{ {
super.load(nbt); super.load(nbt);
this.setMaterialFromID(nbt.getInteger("typeID")); setMaterialFromID(nbt.getInteger("typeID"));
this.dyeID = nbt.getInteger("dyeID"); dyeID = nbt.getInteger("dyeID");
this.isInsulated = nbt.getBoolean("isInsulated"); isInsulated = nbt.getBoolean("isInsulated");
} }
@Override @Override
public ItemStack pickItem(MovingObjectPosition hit) public ItemStack pickItem(MovingObjectPosition hit)
{ {
return EnumWireMaterial.values()[this.getTypeID()].getWire(); return EnumWireMaterial.values()[getTypeID()].getWire();
} }
@Override @Override
@ -329,20 +345,21 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
{ {
if (isInsulated() && !world().isRemote) 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); player.inventory.decrStackSize(player.inventory.currentItem, 1);
return true; 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; return true;
} }
} }
@ -364,7 +381,7 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
@Override @Override
public int getHollowSize() public int getHollowSize()
{ {
return this.isInsulated ? 8 : 6; return isInsulated ? 8 : 6;
} }
@Override @Override
@ -380,30 +397,34 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
} }
@Override @Override
public void setInsulationColor(int dyeID) public void setInsulationColor(int dye)
{ {
this.dyeID = dyeID; dyeID = dye;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z()); refresh();
world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
} }
@Override @Override
public void setInsulated(boolean insulated) public void setInsulated(boolean insulated)
{ {
this.isInsulated = insulated; isInsulated = insulated;
this.dyeID = DEFAULT_COLOR; dyeID = DEFAULT_COLOR;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z()); refresh();
this.tile().notifyPartChange(this); world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
} }
public void setInsulated(int dyeColour) public void setInsulated(int dyeColour)
{ {
this.isInsulated = true; isInsulated = true;
this.dyeID = dyeColour; dyeID = dyeColour;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z()); refresh();
this.tile().notifyPartChange(this); world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
} }
public void setInsulated() public void setInsulated()
@ -445,16 +466,15 @@ public class PartWire extends PartUniversalConductor implements TSlottedPart, JN
public boolean isBlockedOnSide(ForgeDirection side) public boolean isBlockedOnSide(ForgeDirection side)
{ {
TMultiPart blocker = tile().partMap(side.ordinal()); TMultiPart blocker = tile().partMap(side.ordinal());
this.testingSide = side; testingSide = side;
boolean expandable = NormalOcclusionTest.apply(this, blocker); boolean expandable = NormalOcclusionTest.apply(this, blocker);
this.testingSide = null; testingSide = null;
return !expandable; return !expandable;
} }
@Override @Override
public void onPartChanged(TMultiPart part) public void onPartChanged(TMultiPart part)
{ {
this.refresh(); refresh();
} }
} }

View file

@ -1,4 +1,4 @@
package resonantinduction.wire.multipart.javatraits; package resonantinduction.wire;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
@ -18,41 +18,54 @@ public class TEnergySink extends TileMultipart implements IEnergySink
public void copyFrom(TileMultipart that) public void copyFrom(TileMultipart that)
{ {
super.copyFrom(that); super.copyFrom(that);
if (that instanceof TEnergySink)
ic2Sinks = ((TEnergySink) that).ic2Sinks; if(that instanceof TEnergySink)
{
ic2Sinks = ((TEnergySink)that).ic2Sinks;
}
} }
@Override @Override
public void bindPart(TMultiPart part) public void bindPart(TMultiPart part)
{ {
super.bindPart(part); super.bindPart(part);
if (part instanceof IEnergySink)
if(part instanceof IEnergySink)
{
ic2Sinks.add((IEnergySink) part); ic2Sinks.add((IEnergySink) part);
} }
}
@Override @Override
public void partRemoved(TMultiPart part, int p) public void partRemoved(TMultiPart part, int p)
{ {
super.partRemoved(part, p); super.partRemoved(part, p);
if (part instanceof IEnergySink)
if(part instanceof IEnergySink)
{
ic2Sinks.remove(part); ic2Sinks.remove(part);
} }
}
@Override @Override
public void clearParts() public void clearParts()
{ {
super.clearParts(); super.clearParts();
ic2Sinks.clear(); ic2Sinks.clear();
} }
@Override @Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) 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 true;
} }
}
return false; return false;
} }
@ -61,20 +74,22 @@ public class TEnergySink extends TileMultipart implements IEnergySink
{ {
double demanded = 0; double demanded = 0;
for (IEnergySink sink : this.ic2Sinks) for(IEnergySink sink : ic2Sinks)
{ {
demanded += sink.demandedEnergyUnits(); demanded += sink.demandedEnergyUnits();
} }
return demanded; return demanded;
} }
@Override @Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) 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())); amount = sink.injectEnergyUnits(directionFrom, Math.min(amount, sink.demandedEnergyUnits()));
} }
return amount; return amount;
} }
@ -82,10 +97,12 @@ public class TEnergySink extends TileMultipart implements IEnergySink
public int getMaxSafeInput() public int getMaxSafeInput()
{ {
int safe = 0; int safe = 0;
for (IEnergySink sink : this.ic2Sinks)
for(IEnergySink sink : ic2Sinks)
{ {
safe += sink.getMaxSafeInput(); safe += sink.getMaxSafeInput();
} }
return safe; return safe;
} }

View file

@ -2,22 +2,25 @@ package resonantinduction.wire;
import java.util.ArrayList; import java.util.ArrayList;
import resonantinduction.ResonantInduction;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.PacketHandler;
import resonantinduction.base.IPacketReceiver;
import universalelectricity.compatibility.Compatibility; import universalelectricity.compatibility.Compatibility;
import universalelectricity.compatibility.TileEntityUniversalConductor; import universalelectricity.compatibility.TileEntityUniversalConductor;
import universalelectricity.core.block.INetworkProvider; import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper; import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.PowerHandler; 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; 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 static final int DEFAULT_COLOR = 16;
public int dyeID = DEFAULT_COLOR; public int dyeID = DEFAULT_COLOR;
@ -124,18 +127,25 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac
} }
@Override @Override
public Packet getDescriptionPacket() public ArrayList getPacketData(int type)
{ {
return PacketHandler.getTileEntityPacket(this, this.isInsulated, this.dyeID); ArrayList data = new ArrayList();
return data;
} }
@Override @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 try
{ {
this.isInsulated = input.readBoolean(); this.isInsulated = data.readBoolean();
this.dyeID = input.readInt(); this.dyeID = data.readInt();
} }
catch (Exception e) catch (Exception e)
{ {
@ -165,12 +175,6 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac
nbt.setBoolean("isInsulated", this.isInsulated); nbt.setBoolean("isInsulated", this.isInsulated);
} }
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return null;
}
@Override @Override
public void doWork(PowerHandler workProvider) public void doWork(PowerHandler workProvider)
{ {
@ -204,4 +208,5 @@ public class TileEntityWire extends TileEntityUniversalConductor implements IPac
{ {
setDye(dyeID); setDye(dyeID);
} }
} }