Fixed framed wire not checking canConnect

This commit is contained in:
Calclavia 2014-02-22 11:42:51 +08:00
parent 8a4509feac
commit 31c44b5c57
4 changed files with 381 additions and 372 deletions

View file

@ -42,256 +42,256 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, IConductor, IEnergyNetwork> implements IConductor, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{
public PartFramedWire()
{
super();
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
breakIcon = RenderFramedWire.breakIcon;
}
public PartFramedWire()
{
super();
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
breakIcon = RenderFramedWire.breakIcon;
}
public PartFramedWire(EnumWireMaterial type)
{
this();
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, ForgeDirection side)
{
return tile instanceof IConductor || canConnectToObj(tile, side);
}
public boolean canConnectToObj(Object obj)
{
if (obj != null && (obj.getClass().isAssignableFrom(this.getClass()) || this.getClass().isAssignableFrom(obj.getClass())))
{
PartAdvancedWire wire = (PartAdvancedWire) obj;
protected boolean canConnectToObj(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.isHandler(obj);
}
return true;
}
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.canConnect(obj, dir.getOpposite(), this);
}
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

@ -180,7 +180,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe,
}
@Override
protected boolean canConnectTo(TileEntity tile)
protected boolean canConnectTo(TileEntity tile, ForgeDirection dir)
{
return tile instanceof IFluidHandler;
}

View file

@ -2,6 +2,7 @@ package resonantinduction.mechanical.logistic.rail;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.prefab.part.PartFramedConnection;
import resonantinduction.mechanical.fluid.pipe.EnumPipeMaterial;
import universalelectricity.api.net.INodeNetwork;
@ -10,12 +11,18 @@ import codechicken.multipart.JIconHitEffects;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.TSlottedPart;
/**
* NO-OP
*
* @author Calclavia
*
*/
public class PartRailing extends PartFramedConnection<EnumPipeMaterial, IRailing, INodeNetwork> implements IRailing, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{
RedstoneControl control;
@Override
protected boolean canConnectTo(TileEntity tile)
protected boolean canConnectTo(TileEntity tile, ForgeDirection dir)
{
// TODO Auto-generated method stub
return false;

View file

@ -71,7 +71,7 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
/** Client Side */
private ForgeDirection testingSide;
@SideOnly(Side.CLIENT)
protected Icon breakIcon;
@ -217,7 +217,7 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
/**
* CONNECTION LOGIC CODE
*/
protected abstract boolean canConnectTo(TileEntity tile);
protected abstract boolean canConnectTo(TileEntity tile, ForgeDirection to);
protected abstract C getConnector(TileEntity tile);
@ -242,7 +242,7 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
*/
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
return (!this.canConnectTo(tile)) || (isBlockedOnSide(side));
return (!this.canConnectTo(tile, side)) || (isBlockedOnSide(side));
}
public byte getPossibleWireConnections()
@ -270,7 +270,7 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (canConnectTo(tileEntity) && canConnectBothSides(tileEntity, side))
if (canConnectTo(tileEntity, side) && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
@ -279,185 +279,187 @@ 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;
}
}