Changed how electrocution is handled for wires, damage is no longer in the millions and only works when wire has a current

This commit is contained in:
Robert S 2014-04-14 19:19:51 -04:00
parent 853c7bfdb0
commit bb1aaecc5b

View file

@ -16,6 +16,7 @@ import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.MultipartUtility;
import resonantinduction.electrical.Electrical;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.electricity.IElectricalNetwork;
import universalelectricity.api.energy.IConductor;
import calclavia.lib.prefab.CustomDamageSource;
import codechicken.lib.data.MCDataInput;
@ -23,337 +24,331 @@ import codechicken.lib.data.MCDataOutput;
import codechicken.multipart.IRedstonePart;
import codechicken.multipart.TMultiPart;
/**
* @author Calclavia
*
*/
/** @author Calclavia */
@Deprecated
public abstract class PartAdvancedWire extends PartConductor
{
public static final int DEFAULT_COLOR = 15;
public int color = DEFAULT_COLOR;
public static final int DEFAULT_COLOR = 15;
public int color = DEFAULT_COLOR;
public EnumWireMaterial material = EnumWireMaterial.COPPER;
public boolean isInsulated = false;
protected Item insulationType = Electrical.itemInsulation;
public EnumWireMaterial material = EnumWireMaterial.COPPER;
public boolean isInsulated = false;
protected Item insulationType = Electrical.itemInsulation;
/**
* INTERNAL USE.
* Can this conductor connect with an external object?
*/
@Override
public boolean canConnectTo(Object obj)
{
if (obj != null && (obj.getClass().isAssignableFrom(this.getClass()) || this.getClass().isAssignableFrom(obj.getClass())))
{
PartAdvancedWire wire = (PartAdvancedWire) obj;
/** INTERNAL USE. Can this conductor connect with an external object? */
@Override
public boolean canConnectTo(Object obj)
{
if (obj != null && (obj.getClass().isAssignableFrom(this.getClass()) || this.getClass().isAssignableFrom(obj.getClass())))
{
PartAdvancedWire wire = (PartAdvancedWire) obj;
if (this.getMaterial() == wire.getMaterial())
{
if (this.isInsulated() && wire.isInsulated())
{
return this.getColor() == wire.getColor() || (this.getColor() == DEFAULT_COLOR || wire.getColor() == DEFAULT_COLOR);
}
if (this.getMaterial() == wire.getMaterial())
{
if (this.isInsulated() && wire.isInsulated())
{
return this.getColor() == wire.getColor() || (this.getColor() == DEFAULT_COLOR || wire.getColor() == DEFAULT_COLOR);
}
return true;
}
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.isHandler(obj);
}
return true;
}
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.isHandler(obj);
}
return false;
}
return false;
}
protected boolean canConnectTo(Object obj, ForgeDirection dir)
{
if (obj != null && (obj.getClass().isAssignableFrom(this.getClass()) || this.getClass().isAssignableFrom(obj.getClass())))
{
PartAdvancedWire wire = (PartAdvancedWire) obj;
protected boolean canConnectTo(Object obj, ForgeDirection dir)
{
if (obj != null && (obj.getClass().isAssignableFrom(this.getClass()) || this.getClass().isAssignableFrom(obj.getClass())))
{
PartAdvancedWire wire = (PartAdvancedWire) obj;
if (this.getMaterial() == wire.getMaterial())
{
if (this.isInsulated() && wire.isInsulated())
{
return this.getColor() == wire.getColor() || (this.getColor() == DEFAULT_COLOR || wire.getColor() == DEFAULT_COLOR);
}
if (this.getMaterial() == wire.getMaterial())
{
if (this.isInsulated() && wire.isInsulated())
{
return this.getColor() == wire.getColor() || (this.getColor() == DEFAULT_COLOR || wire.getColor() == DEFAULT_COLOR);
}
return true;
}
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.canConnect(obj, dir.getOpposite(), this);
}
return true;
}
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.canConnect(obj, dir.getOpposite(), this);
}
return false;
}
return false;
}
@Override
public void onEntityCollision(Entity entity)
{
if (!this.isInsulated() && this.getNetwork().getLastBuffer() > 0)
{
entity.attackEntityFrom(CustomDamageSource.electrocution, this.getNetwork().getLastBuffer());
}
}
@Override
public void onEntityCollision(Entity entity)
{
if (!this.isInsulated())
{
float damage = 0;
@Override
public float getResistance()
{
return this.getMaterial().resistance;
}
if (this.getNetwork() instanceof IElectricalNetwork && this.getNetwork().getRequest() > 0)
{
damage = ((IElectricalNetwork) this.getNetwork()).getVoltage() / 60;
}
@Override
public long getCurrentCapacity()
{
return this.getMaterial().maxAmps;
}
if (damage > 0)
entity.attackEntityFrom(CustomDamageSource.electrocution, Math.max(damage, 10));
}
}
/**
* Material Methods
*/
public EnumWireMaterial getMaterial()
{
return this.material;
}
@Override
public float getResistance()
{
return this.getMaterial().resistance;
}
public void setMaterial(EnumWireMaterial material)
{
this.material = material;
}
@Override
public long getCurrentCapacity()
{
return this.getMaterial().maxAmps;
}
public void setMaterial(int id)
{
this.setMaterial(EnumWireMaterial.values()[id]);
}
/** Material Methods */
public EnumWireMaterial getMaterial()
{
return this.material;
}
public int getMaterialID()
{
return this.material.ordinal();
}
public void setMaterial(EnumWireMaterial material)
{
this.material = material;
}
/**
* Insulation Methods
*/
public void setInsulated(boolean insulated)
{
this.isInsulated = insulated;
this.color = DEFAULT_COLOR;
public void setMaterial(int id)
{
this.setMaterial(EnumWireMaterial.values()[id]);
}
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendInsulationUpdate();
}
}
public int getMaterialID()
{
return this.material.ordinal();
}
public void setInsulated(int dyeColour)
{
this.isInsulated = true;
this.color = dyeColour;
/** Insulation Methods */
public void setInsulated(boolean insulated)
{
this.isInsulated = insulated;
this.color = DEFAULT_COLOR;
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendInsulationUpdate();
this.sendColorUpdate();
}
}
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendInsulationUpdate();
}
}
public boolean isInsulated()
{
return this.isInsulated;
}
public void setInsulated(int dyeColour)
{
this.isInsulated = true;
this.color = dyeColour;
public void sendInsulationUpdate()
{
tile().getWriteStream(this).writeByte(1).writeBoolean(this.isInsulated);
}
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendInsulationUpdate();
this.sendColorUpdate();
}
}
/**
* Wire Coloring Methods
*/
public int getColor()
{
return this.isInsulated ? this.color : -1;
}
public boolean isInsulated()
{
return this.isInsulated;
}
public void setColor(int dye)
{
if (this.isInsulated)
{
this.color = dye;
public void sendInsulationUpdate()
{
tile().getWriteStream(this).writeByte(1).writeBoolean(this.isInsulated);
}
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendColorUpdate();
}
}
}
/** Wire Coloring Methods */
public int getColor()
{
return this.isInsulated ? this.color : -1;
}
public void sendColorUpdate()
{
tile().getWriteStream(this).writeByte(2).writeInt(this.color);
}
public void setColor(int dye)
{
if (this.isInsulated)
{
this.color = dye;
/**
* Changes the wire's color.
*/
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack itemStack)
{
if (itemStack != null)
{
int dyeColor = MultipartUtility.isDye(itemStack);
if (!this.world().isRemote)
{
tile().notifyPartChange(this);
this.sendColorUpdate();
}
}
}
if (dyeColor != -1 && this.isInsulated())
{
if (!player.capabilities.isCreativeMode)
{
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
public void sendColorUpdate()
{
tile().getWriteStream(this).writeByte(2).writeInt(this.color);
}
this.setColor(dyeColor);
return true;
}
else if (itemStack.getItem() == insulationType)
{
if (this.isInsulated())
{
if (!world().isRemote && player.capabilities.isCreativeMode)
{
tile().dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))));
}
/** Changes the wire's color. */
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack itemStack)
{
if (itemStack != null)
{
int dyeColor = MultipartUtility.isDye(itemStack);
this.setInsulated(false);
return true;
}
else
{
if (!player.capabilities.isCreativeMode)
{
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
if (dyeColor != -1 && this.isInsulated())
{
if (!player.capabilities.isCreativeMode)
{
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
this.setInsulated(BlockColored.getDyeFromBlock(itemStack.getItemDamage()));
return true;
}
}
else if (itemStack.getItem() instanceof ItemShears && isInsulated())
{
if (!world().isRemote && !player.capabilities.isCreativeMode)
{
tile().dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))));
}
this.setColor(dyeColor);
return true;
}
else if (itemStack.getItem() == insulationType)
{
if (this.isInsulated())
{
if (!world().isRemote && player.capabilities.isCreativeMode)
{
tile().dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))));
}
this.setInsulated(false);
return true;
}
}
this.setInsulated(false);
return true;
}
else
{
if (!player.capabilities.isCreativeMode)
{
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
return false;
}
this.setInsulated(BlockColored.getDyeFromBlock(itemStack.getItemDamage()));
return true;
}
}
else if (itemStack.getItem() instanceof ItemShears && isInsulated())
{
if (!world().isRemote && !player.capabilities.isCreativeMode)
{
tile().dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))));
}
@Override
protected ItemStack getItem()
{
return EnumWireMaterial.values()[getMaterialID()].getWire();
}
this.setInsulated(false);
return true;
}
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
return false;
}
if (this.isInsulated)
{
drops.add(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color)));
}
@Override
protected ItemStack getItem()
{
return EnumWireMaterial.values()[getMaterialID()].getWire();
}
return drops;
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return getItem();
}
if (this.isInsulated)
{
drops.add(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color)));
}
@Override
public void readDesc(MCDataInput packet)
{
this.setMaterial(packet.readByte());
this.color = packet.readByte();
this.isInsulated = packet.readBoolean();
}
return drops;
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte((byte) this.getMaterialID());
packet.writeByte((byte) this.color);
packet.writeBoolean(this.isInsulated);
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return getItem();
}
public void read(MCDataInput packet, int packetID)
{
switch (packetID)
{
case 1:
this.isInsulated = packet.readBoolean();
this.tile().markRender();
break;
case 2:
this.color = packet.readInt();
this.tile().markRender();
break;
}
}
@Override
public void readDesc(MCDataInput packet)
{
this.setMaterial(packet.readByte());
this.color = packet.readByte();
this.isInsulated = packet.readBoolean();
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setInteger("typeID", getMaterialID());
nbt.setBoolean("isInsulated", isInsulated);
nbt.setInteger("dyeID", color);
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte((byte) this.getMaterialID());
packet.writeByte((byte) this.color);
packet.writeBoolean(this.isInsulated);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
setMaterial(nbt.getInteger("typeID"));
this.isInsulated = nbt.getBoolean("isInsulated");
this.color = nbt.getInteger("dyeID");
}
public void read(MCDataInput packet, int packetID)
{
switch (packetID)
{
case 1:
this.isInsulated = packet.readBoolean();
this.tile().markRender();
break;
case 2:
this.color = packet.readInt();
this.tile().markRender();
break;
}
}
@Override
protected boolean checkRedstone(int side)
{
if (this.world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return true;
}
else
{
for (TMultiPart tp : tile().jPartList())
{
if (tp instanceof IRedstonePart)
{
IRedstonePart rp = (IRedstonePart) tp;
if ((Math.max(rp.strongPowerLevel(side), rp.weakPowerLevel(side)) << 4) > 0)
{
return true;
}
}
}
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setInteger("typeID", getMaterialID());
nbt.setBoolean("isInsulated", isInsulated);
nbt.setInteger("dyeID", color);
}
return false;
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
setMaterial(nbt.getInteger("typeID"));
this.isInsulated = nbt.getBoolean("isInsulated");
this.color = nbt.getInteger("dyeID");
}
@Override
protected boolean checkRedstone(int side)
{
if (this.world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return true;
}
else
{
for (TMultiPart tp : tile().jPartList())
{
if (tp instanceof IRedstonePart)
{
IRedstonePart rp = (IRedstonePart) tp;
if ((Math.max(rp.strongPowerLevel(side), rp.weakPowerLevel(side)) << 4) > 0)
{
return true;
}
}
}
}
return false;
}
}