Use EnumWireMaterial more in PartWire, apply material interface.

This commit is contained in:
Ben Spiers 2013-09-19 21:01:37 +01:00
parent 1017308d47
commit 50b3414788

View file

@ -13,7 +13,9 @@ import resonantinduction.ResonantInduction;
import resonantinduction.base.IPacketReceiver; import resonantinduction.base.IPacketReceiver;
import resonantinduction.render.RenderWirePart; import resonantinduction.render.RenderWirePart;
import resonantinduction.wire.EnumWireMaterial; import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.IInsulatedMaterial;
import resonantinduction.wire.IInsulation; import resonantinduction.wire.IInsulation;
import resonantinduction.wire.IWireMaterial;
import resonantinduction.wire.TileEntityWire; import resonantinduction.wire.TileEntityWire;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockColored; import net.minecraft.block.BlockColored;
@ -55,14 +57,14 @@ import codechicken.multipart.handler.MultipartProxy;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
public class PartWire extends PartUniversalConductor implements IPacketReceiver, TSlottedPart, JNormalOcclusion, IHollowConnect, IInsulation public class PartWire extends PartUniversalConductor implements IPacketReceiver, TSlottedPart, JNormalOcclusion, IHollowConnect, 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;
public boolean isInsulated = false; public boolean isInsulated = false;
public static RenderWirePart renderer = new RenderWirePart(); public static RenderWirePart renderer = new RenderWirePart();
public static IndexedCuboid6[] sides = new IndexedCuboid6[7]; public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
public int typeID = 0; public EnumWireMaterial material = EnumWireMaterial.COPPER;
/** Client Side Connection Check */ /** Client Side Connection Check */
public boolean isTick = false; public boolean isTick = false;
@ -78,9 +80,14 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
} }
public PartWire(int typeID) public PartWire(int typeID)
{
this(EnumWireMaterial.values()[typeID]);
}
public PartWire(EnumWireMaterial type)
{ {
super(); super();
this.typeID = typeID; this.material = type;
} }
@Override @Override
@ -92,12 +99,22 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
} }
Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction); Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(this.world());
if (this.isInsulated() && connectPos.getTileEntity(this.world()) instanceof IInsulation) if (connectTile instanceof IWireMaterial)
{ {
IInsulation insulatedTile = (IInsulation) connectPos.getTileEntity(this.world()); IWireMaterial wireTile = (IWireMaterial) connectTile;
if (wireTile.getMaterial() != this.getMaterial())
{
return false;
}
}
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != this.getInsulationColor() && this.getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR) )//|| connectPos.getBlockMetadata(this.world()) != this.getTypeID()) if (this.isInsulated() && connectTile instanceof IInsulation)
{
IInsulation insulatedTile = (IInsulation) connectTile;
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != this.getInsulationColor() && this.getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{ {
return false; return false;
} }
@ -147,23 +164,25 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
public EnumWireMaterial getMaterial() public EnumWireMaterial getMaterial()
{ {
return EnumWireMaterial.values()[this.getTypeID()]; return material;
} }
public int getTypeID() public int getTypeID()
{ {
return this.typeID; return material.ordinal();
} }
/**
* @param dyeID
*/
public void setDye(int dyeID) public void setDye(int dyeID)
{ {
this.dyeID = dyeID; this.dyeID = dyeID;
this.refresh(); this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z()); this.world().markBlockForUpdate(this.x(), this.y(), this.z());
} }
public void setMaterialFromID(int id)
{
this.material = EnumWireMaterial.values()[id];
}
@Override @Override
public void handle(ByteArrayDataInput input) public void handle(ByteArrayDataInput input)
@ -288,27 +307,27 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
@Override @Override
public void readDesc(MCDataInput packet) public void readDesc(MCDataInput packet)
{ {
typeID =packet.readInt(); this.setMaterialFromID(packet.readInt());
dyeID = packet.readInt(); this.dyeID = packet.readInt();
isInsulated = packet.readBoolean(); this.isInsulated = packet.readBoolean();
isTick = packet.readBoolean(); this.isTick = packet.readBoolean();
} }
@Override @Override
public void writeDesc(MCDataOutput packet) public void writeDesc(MCDataOutput packet)
{ {
packet.writeInt(typeID); packet.writeInt(this.getTypeID());
packet.writeInt(dyeID); packet.writeInt(this.dyeID);
packet.writeBoolean(isInsulated); packet.writeBoolean(this.isInsulated);
packet.writeBoolean(isTick); packet.writeBoolean(this.isTick);
} }
@Override @Override
public void save(NBTTagCompound nbt) public void save(NBTTagCompound nbt)
{ {
super.save(nbt); super.save(nbt);
nbt.setInteger("typeID", this.typeID); nbt.setInteger("typeID", this.getTypeID());
nbt.setInteger("dyeID", this.dyeID); nbt.setInteger("dyeID", this.dyeID);
nbt.setBoolean("isInsulated", this.isInsulated); nbt.setBoolean("isInsulated", this.isInsulated);
} }
@ -317,7 +336,7 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
public void load(NBTTagCompound nbt) public void load(NBTTagCompound nbt)
{ {
super.load(nbt); super.load(nbt);
this.typeID = nbt.getInteger("typeID"); this.setMaterialFromID(nbt.getInteger("typeID"));
this.dyeID = nbt.getInteger("dyeID"); this.dyeID = nbt.getInteger("dyeID");
this.isInsulated = nbt.getBoolean("isInsulated"); this.isInsulated = nbt.getBoolean("isInsulated");
} }
@ -331,13 +350,13 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
@Override @Override
public boolean doesTick() public boolean doesTick()
{ {
return isTick; return this.isTick;
} }
@Override @Override
public ItemStack pickItem(MovingObjectPosition hit) public ItemStack pickItem(MovingObjectPosition hit)
{ {
return new ItemStack(ResonantInduction.itemPartWire, 1, getTypeID()); return new ItemStack(ResonantInduction.itemPartWire, 1, this.getTypeID());
} }
@Override @Override
@ -358,8 +377,6 @@ public class PartWire extends PartUniversalConductor implements IPacketReceiver,
return true; return true;
} }
} }
player.sendChatToPlayer(ChatMessageComponent.createFromText("updating block"));
this.world().markBlockForUpdate(this.x(), this.y(), this.z());
return false; return false;
} }