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

View file

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