This commit is contained in:
Calclavia 2014-02-20 10:30:36 +08:00
commit 5adbe0d757
2 changed files with 371 additions and 376 deletions

View file

@ -36,263 +36,262 @@ import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.PartMap; import codechicken.multipart.PartMap;
import codechicken.multipart.TSlottedPart; import codechicken.multipart.TSlottedPart;
import codechicken.multipart.TileMultipart; import codechicken.multipart.TileMultipart;
import cpw.mods.fml.common.FMLCommonHandler;
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 PartFramedWire extends PartFramedConnection<EnumWireMaterial, IConductor, IEnergyNetwork> implements IConductor, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, IConductor, IEnergyNetwork> implements IConductor, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{ {
public PartFramedWire() public PartFramedWire()
{ {
super(); super();
breakIcon = RenderFramedWire.breakIcon; if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
} breakIcon = RenderFramedWire.breakIcon;
}
public PartFramedWire(EnumWireMaterial type) public PartFramedWire(EnumWireMaterial type)
{ {
super(); this();
breakIcon = RenderFramedWire.breakIcon; material = type;
material = type; }
}
public PartFramedWire(int typeID) public PartFramedWire(int typeID)
{ {
this(EnumWireMaterial.values()[typeID]); this(EnumWireMaterial.values()[typeID]);
} }
@Override @Override
public String getType() public String getType()
{ {
return "resonant_induction_wire"; return "resonant_induction_wire";
} }
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{ {
if (item != null) if (item != null)
{ {
if (item.getItem().itemID == Block.lever.blockID) if (item.getItem().itemID == Block.lever.blockID)
{ {
TileMultipart tile = tile(); TileMultipart tile = tile();
World w = world(); World w = world();
if (!w.isRemote) if (!w.isRemote)
{ {
PartFramedSwitchWire wire = (PartFramedSwitchWire) MultiPartRegistry.createPart("resonant_induction_switch_wire", false); PartFramedSwitchWire wire = (PartFramedSwitchWire) MultiPartRegistry.createPart("resonant_induction_switch_wire", false);
wire.copyFrom(this); wire.copyFrom(this);
if (tile.canReplacePart(this, wire)) if (tile.canReplacePart(this, wire))
{ {
tile.remPart(this); tile.remPart(this);
TileMultipart.addPart(w, new BlockCoord(tile), wire); TileMultipart.addPart(w, new BlockCoord(tile), wire);
if (!player.capabilities.isCreativeMode) if (!player.capabilities.isCreativeMode)
{ {
player.inventory.decrStackSize(player.inventory.currentItem, 1); player.inventory.decrStackSize(player.inventory.currentItem, 1);
} }
} }
} }
return true; return true;
} }
} }
return super.activate(player, part, item); return super.activate(player, part, item);
} }
@Override @Override
public void preparePlacement(int meta) public void preparePlacement(int meta)
{ {
this.setMaterial(meta); this.setMaterial(meta);
} }
@Override @Override
public Iterable<Cuboid6> getCollisionBoxes() public Iterable<Cuboid6> getCollisionBoxes()
{ {
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;
} }
@Override @Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player) public float getStrength(MovingObjectPosition hit, EntityPlayer player)
{ {
return 10F; return 10F;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
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)
{ {
RenderFramedWire.INSTANCE.renderStatic(this); RenderFramedWire.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 (getMaterial() == EnumWireMaterial.SILVER) if (getMaterial() == EnumWireMaterial.SILVER)
{ {
RenderFramedWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame); RenderFramedWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame);
} }
} }
@Override @Override
public void drawBreaking(RenderBlocks renderBlocks) public void drawBreaking(RenderBlocks renderBlocks)
{ {
CCRenderState.reset(); CCRenderState.reset();
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(renderBlocks.overrideBlockTexture), null); RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(renderBlocks.overrideBlockTexture), null);
} }
@Override @Override
public Iterable<Cuboid6> getOcclusionBoxes() public Iterable<Cuboid6> getOcclusionBoxes()
{ {
return getCollisionBoxes(); return getCollisionBoxes();
} }
@Override @Override
public int getSlotMask() public int getSlotMask()
{ {
return PartMap.CENTER.mask; return PartMap.CENTER.mask;
} }
@Override @Override
public int getHollowSize() public int getHollowSize()
{ {
return isInsulated ? 8 : 6; return isInsulated ? 8 : 6;
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds()
{ {
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625); return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625);
} }
@Override @Override
public Icon getBreakingIcon(Object subPart, int side) public Icon getBreakingIcon(Object subPart, int side)
{ {
return RenderFramedWire.breakIcon; return RenderFramedWire.breakIcon;
} }
@Override @Override
protected boolean canConnectTo(TileEntity tile) protected boolean canConnectTo(TileEntity tile)
{ {
return tile instanceof IConductor || this.canConnectToObj(tile); return tile instanceof IConductor || this.canConnectToObj(tile);
} }
public boolean canConnectToObj(Object obj) public boolean canConnectToObj(Object obj)
{ {
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.isHandler(obj); return CompatibilityModule.isHandler(obj);
} }
return false; return false;
} }
@Override @Override
public IConductor getConnector(TileEntity tile) public IConductor getConnector(TileEntity tile)
{ {
if (tile instanceof IConductor) if (tile instanceof IConductor)
return (IConductor) ((IConductor) tile).getInstance(ForgeDirection.UNKNOWN); return (IConductor) ((IConductor) tile).getInstance(ForgeDirection.UNKNOWN);
return null; return null;
} }
/** /** Shouldn't need to be overridden. Override connectionPrevented instead */
* Shouldn't need to be overridden. Override connectionPrevented instead @Override
*/ public boolean canConnect(ForgeDirection direction, Object obj)
@Override {
public boolean canConnect(ForgeDirection direction, Object obj) if (obj instanceof PartFramedWire)
{ {
if (obj instanceof PartFramedWire) if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{ {
if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) return false;
{ }
return false;
}
Vector3 connectPos = new Vector3(tile()).translate(direction); Vector3 connectPos = new Vector3(tile()).translate(direction);
TileEntity connectTile = connectPos.getTileEntity(world()); TileEntity connectTile = connectPos.getTileEntity(world());
return !isConnectionPrevented(connectTile, direction); return !isConnectionPrevented(connectTile, direction);
} }
return false; return false;
} }
@Override @Override
public float getResistance() public float getResistance()
{ {
return this.getMaterial().resistance; return this.getMaterial().resistance;
} }
public void copyFrom(PartFramedWire otherCable) public void copyFrom(PartFramedWire otherCable)
{ {
this.isInsulated = otherCable.isInsulated; this.isInsulated = otherCable.isInsulated;
this.color = otherCable.color; this.color = otherCable.color;
this.connections = otherCable.connections; this.connections = otherCable.connections;
this.material = otherCable.material; this.material = otherCable.material;
this.currentWireConnections = otherCable.currentWireConnections; this.currentWireConnections = otherCable.currentWireConnections;
this.currentAcceptorConnections = otherCable.currentAcceptorConnections; this.currentAcceptorConnections = otherCable.currentAcceptorConnections;
this.setNetwork(otherCable.getNetwork()); this.setNetwork(otherCable.getNetwork());
this.getNetwork().setBufferFor(this, otherCable.getInstance(ForgeDirection.UNKNOWN).getNetwork().getBufferOf(otherCable)); this.getNetwork().setBufferFor(this, otherCable.getInstance(ForgeDirection.UNKNOWN).getNetwork().getBufferOf(otherCable));
} }
@Override @Override
public IEnergyNetwork getNetwork() public IEnergyNetwork getNetwork()
{ {
if (network == null) if (network == null)
{ {
setNetwork(EnergyNetworkLoader.getNewNetwork(this)); setNetwork(EnergyNetworkLoader.getNewNetwork(this));
} }
return network; return network;
} }
@Override @Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{ {
return this.getNetwork().produce(this, from.getOpposite(), receive, doReceive); return this.getNetwork().produce(this, from.getOpposite(), receive, doReceive);
} }
@Override @Override
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract) public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
{ {
return 0; return 0;
} }
@Override @Override
public long getCurrentCapacity() public long getCurrentCapacity()
{ {
return this.getMaterial().maxAmps; return this.getMaterial().maxAmps;
} }
@Override @Override
public void setMaterial(int i) public void setMaterial(int i)
{ {
setMaterial(EnumWireMaterial.values()[i]); setMaterial(EnumWireMaterial.values()[i]);
} }
@Override @Override
protected ItemStack getItem() protected ItemStack getItem()
{ {
return new ItemStack(Electrical.itemWire); return new ItemStack(Electrical.itemWire);
} }
} }

View file

@ -32,6 +32,8 @@ 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 codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class PartFramedConnection<M extends Enum, C extends IConnector<N>, N extends INodeNetwork> extends PartColorableMaterial<M> implements IConnector<N>, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects public abstract class PartFramedConnection<M extends Enum, C extends IConnector<N>, N extends INodeNetwork> extends PartColorableMaterial<M> implements IConnector<N>, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{ {
@ -69,6 +71,8 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
/** Client Side */ /** Client Side */
private ForgeDirection testingSide; private ForgeDirection testingSide;
@SideOnly(Side.CLIENT)
protected Icon breakIcon; protected Icon breakIcon;
public void preparePlacement(int meta) public void preparePlacement(int meta)
@ -275,193 +279,185 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
return connections; return connections;
} }
public void refresh() public void refresh()
{ {
if (!world().isRemote) if (!world().isRemote)
{ {
byte possibleWireConnections = getPossibleWireConnections(); byte possibleWireConnections = getPossibleWireConnections();
byte possibleAcceptorConnections = getPossibleAcceptorConnections(); byte possibleAcceptorConnections = getPossibleAcceptorConnections();
if (possibleWireConnections != this.currentWireConnections) if (possibleWireConnections != this.currentWireConnections)
{ {
byte or = (byte) (possibleWireConnections | this.currentWireConnections); byte or = (byte) (possibleWireConnections | this.currentWireConnections);
// Connections have been removed // Connections have been removed
if (or != possibleWireConnections) if (or != possibleWireConnections)
{ {
this.getNetwork().removeConnector(this); this.getNetwork().removeConnector(this);
this.getNetwork().split(this); this.getNetwork().split(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(world(), new Vector3(tile()), side, this); TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side, this);
if (getConnector(tileEntity) != null) if (getConnector(tileEntity) != null)
{ {
this.getNetwork().merge(getConnector(tileEntity).getNetwork()); this.getNetwork().merge(getConnector(tileEntity).getNetwork());
} }
} }
} }
this.currentWireConnections = possibleWireConnections; this.currentWireConnections = possibleWireConnections;
} }
this.currentAcceptorConnections = possibleAcceptorConnections; this.currentAcceptorConnections = possibleAcceptorConnections;
this.getNetwork().reconstruct(); this.getNetwork().reconstruct();
this.sendConnectionUpdate(); this.sendConnectionUpdate();
} }
tile().markRender(); tile().markRender();
} }
/** /** Should include connections that are in the current connection maps even if those connections
* Should include connections that are in the current connection maps even if those connections * aren't allowed any more. This is so that networks split correctly. */
* aren't allowed any more. This is so that networks split correctly. @Override
*/ public TileEntity[] getConnections()
@Override {
public TileEntity[] getConnections() TileEntity[] connections = new TileEntity[6];
{
TileEntity[] connections = new TileEntity[6];
if (world() != null) if (world() != null)
{ {
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(world(), new Vector3(tile()), side); TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (isCurrentlyConnected(side)) if (isCurrentlyConnected(side))
{ {
connections[i] = tileEntity; connections[i] = tileEntity;
} }
} }
} }
return connections; return connections;
} }
public boolean isCurrentlyConnected(ForgeDirection side) public boolean isCurrentlyConnected(ForgeDirection side)
{ {
return connectionMapContainsSide(getAllCurrentConnections(), side); return connectionMapContainsSide(getAllCurrentConnections(), side);
} }
/** /** Shouldn't need to be overridden. Override connectionPrevented instead */
* Shouldn't need to be overridden. Override connectionPrevented instead @Override
*/ public boolean canConnect(ForgeDirection direction, Object source)
@Override {
public boolean canConnect(ForgeDirection direction, Object source) Vector3 connectPos = new Vector3(tile()).translate(direction);
{ TileEntity connectTile = connectPos.getTileEntity(world());
Vector3 connectPos = new Vector3(tile()).translate(direction); return !isConnectionPrevented(connectTile, direction);
TileEntity connectTile = connectPos.getTileEntity(world()); }
return !isConnectionPrevented(connectTile, direction);
}
@Override @Override
public void onAdded() public void onAdded()
{ {
super.onAdded(); super.onAdded();
refresh(); refresh();
} }
@Override @Override
public void onMoved() public void onMoved()
{ {
this.refresh(); this.refresh();
} }
@Override @Override
public void onChunkLoad() public void onChunkLoad()
{ {
super.onChunkLoad(); super.onChunkLoad();
refresh(); refresh();
} }
@Override @Override
public void onNeighborChanged() public void onNeighborChanged()
{ {
super.onNeighborChanged(); super.onNeighborChanged();
refresh(); refresh();
} }
@Override @Override
public void onPartChanged(TMultiPart part) public void onPartChanged(TMultiPart part)
{ {
refresh(); refresh();
} }
public void copyFrom(PartFramedConnection<M, C, N> other) public void copyFrom(PartFramedConnection<M, C, N> other)
{ {
this.isInsulated = other.isInsulated; this.isInsulated = other.isInsulated;
this.color = other.color; this.color = other.color;
this.connections = other.connections; this.connections = other.connections;
this.material = other.material; this.material = other.material;
this.currentWireConnections = other.currentWireConnections; this.currentWireConnections = other.currentWireConnections;
this.currentAcceptorConnections = other.currentAcceptorConnections; this.currentAcceptorConnections = other.currentAcceptorConnections;
this.setNetwork(other.getNetwork()); this.setNetwork(other.getNetwork());
} }
/** /** Packet Methods */
* Packet Methods public void sendConnectionUpdate()
*/ {
public void sendConnectionUpdate() tile().getWriteStream(this).writeByte(0).writeByte(this.currentWireConnections).writeByte(this.currentAcceptorConnections);
{ }
tile().getWriteStream(this).writeByte(0).writeByte(this.currentWireConnections).writeByte(this.currentAcceptorConnections);
}
@Override @Override
public void readDesc(MCDataInput packet) public void readDesc(MCDataInput packet)
{ {
super.readDesc(packet); super.readDesc(packet);
this.currentWireConnections = packet.readByte(); this.currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte(); this.currentAcceptorConnections = packet.readByte();
} }
@Override @Override
public void writeDesc(MCDataOutput packet) public void writeDesc(MCDataOutput packet)
{ {
super.writeDesc(packet); super.writeDesc(packet);
packet.writeByte(this.currentWireConnections); packet.writeByte(this.currentWireConnections);
packet.writeByte(this.currentAcceptorConnections); packet.writeByte(this.currentAcceptorConnections);
} }
@Override @Override
public void read(MCDataInput packet) public void read(MCDataInput packet)
{ {
read(packet, packet.readUByte()); read(packet, packet.readUByte());
} }
@Override @Override
public void read(MCDataInput packet, int packetID) public void read(MCDataInput packet, int packetID)
{ {
if (packetID == 0) if (packetID == 0)
{ {
this.currentWireConnections = packet.readByte(); this.currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte(); this.currentAcceptorConnections = packet.readByte();
tile().markRender(); tile().markRender();
} }
else else
{ {
super.read(packet, packetID); super.read(packet, packetID);
} }
} }
/** /** Network Methods */
* Network Methods @Override
*/ public void setNetwork(N network)
@Override {
public void setNetwork(N network) this.network = network;
{ }
this.network = network;
}
@Override @Override
public IConnector<N> getInstance(ForgeDirection dir) public IConnector<N> getInstance(ForgeDirection dir)
{ {
return this; return this;
} }
} }