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