Fixed #358 and framed wire not connecting properly

This commit is contained in:
Calclavia 2014-03-08 19:47:27 -08:00
parent 9b6d67a02b
commit 74c00b802f
7 changed files with 99 additions and 144 deletions

View file

@ -2,6 +2,8 @@ package resonantinduction.electrical.multimeter;
import java.util.List; import java.util.List;
import org.lwjgl.input.Keyboard;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -10,6 +12,9 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import resonantinduction.core.prefab.part.IHighlight; import resonantinduction.core.prefab.part.IHighlight;
import resonantinduction.electrical.wire.EnumWireMaterial; import resonantinduction.electrical.wire.EnumWireMaterial;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import calclavia.lib.render.EnumColor;
import calclavia.lib.utility.LanguageUtility; import calclavia.lib.utility.LanguageUtility;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
@ -45,20 +50,15 @@ public class ItemMultimeter extends JItemMultiPart implements IHighlight
} }
@Override @Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4)
{ {
par3List.add(LanguageUtility.getLocal("tooltip.multimeter.line1")); if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
par3List.add(LanguageUtility.getLocal("tooltip.multimeter.line2"));
float detection = this.getDetection(itemStack);
if (detection != -1)
{ {
par3List.add(LanguageUtility.getLocal("tooltip.multimeter.lastSave").replace("%v", detection + "")); list.add(LanguageUtility.getLocal("tooltip.noShift").replace("%0", EnumColor.AQUA.toString()).replace("%1", EnumColor.GREY.toString()));
} }
else else
{ {
par3List.add(LanguageUtility.getLocal("tooltip.multimeter.noSave")); list.addAll(LanguageUtility.splitStringPerWord(LanguageUtility.getLocal("item.resonantinduction:multimeter.tooltip"), 5));
} }
} }

View file

@ -48,7 +48,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@UniversalClass @UniversalClass
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
{ {
public PartFramedWire() public PartFramedWire()
{ {
@ -101,6 +101,8 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
} }
} }
super.onWorldJoin();
} }
@Override @Override
@ -145,6 +147,9 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{ {
if (!world().isRemote)
System.out.println(getNetwork());
if (item != null) if (item != null)
{ {
if (item.getItem().itemID == Block.lever.blockID) if (item.getItem().itemID == Block.lever.blockID)
@ -186,7 +191,6 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
{ {
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;
} }
@ -241,41 +245,11 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
return isInsulated ? 8 : 6; 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 Icon getBreakingIcon(Object subPart, int side)
{
return RenderFramedWire.breakIcon;
}
@Override @Override
protected boolean canConnectTo(TileEntity tile, ForgeDirection side) protected boolean canConnectTo(TileEntity tile, ForgeDirection side)
{ {
Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile; Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
return canConnect(side, obj);
if (obj instanceof PartFramedWire)
{
PartFramedWire wire = (PartFramedWire) obj;
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;
}
return false;
}
return CompatibilityModule.canConnect(obj, side.getOpposite(), this);
} }
@Override @Override
@ -289,8 +263,11 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
/** Shouldn't need to be overridden. Override connectionPrevented instead */ /** Shouldn't need to be overridden. Override connectionPrevented instead */
@Override @Override
public boolean canConnect(ForgeDirection direction, Object obj) public boolean canConnect(ForgeDirection from, Object obj)
{ {
if (isBlockedOnSide(from))
return false;
if (obj instanceof PartFramedWire) if (obj instanceof PartFramedWire)
{ {
if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
@ -298,12 +275,22 @@ public class PartFramedWire extends PartFramedConnection<EnumWireMaterial, ICond
return false; return false;
} }
Vector3 connectPos = new Vector3(tile()).translate(direction); PartFramedWire wire = (PartFramedWire) obj;
TileEntity connectTile = connectPos.getTileEntity(world());
return !isConnectionPrevented(connectTile, direction); if (this.getMaterial() == wire.getMaterial())
{
if (isInsulated() && wire.isInsulated())
{
return getColor() == wire.getColor() || (getColor() == DEFAULT_COLOR || wire.getColor() == DEFAULT_COLOR);
}
return true;
}
return false;
} }
return false; return CompatibilityModule.canConnect(obj, from.getOpposite(), this);
} }
@Override @Override

View file

@ -176,7 +176,7 @@ public class Mechanical
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.CERAMIC.ordinal()), "BBB", " ", "BBB", 'B', Item.brick)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.CERAMIC.ordinal()), "BBB", " ", "BBB", 'B', Item.brick));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.BRONZE.ordinal()), "BBB", " ", "BBB", 'B', "ingotBronze")); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.BRONZE.ordinal()), "BBB", " ", "BBB", 'B', "ingotBronze"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.PLASTIC.ordinal()), "BBB", " ", "BBB", 'B', "rubber")); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.PLASTIC.ordinal()), "BBB", " ", "BBB", 'B', UniversalRecipe.RUBBER.get()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.IRON.ordinal()), "BBB", " ", "BBB", 'B', Item.ingotIron)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.IRON.ordinal()), "BBB", " ", "BBB", 'B', Item.ingotIron));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.STEEL.ordinal()), "BBB", " ", "BBB", 'B', "ingotSteel")); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.STEEL.ordinal()), "BBB", " ", "BBB", 'B', "ingotSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.FIBERGLASS.ordinal()), "BBB", " ", "BBB", 'B', Item.diamond)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 1, EnumPipeMaterial.FIBERGLASS.ordinal()), "BBB", " ", "BBB", 'B', Item.diamond));

View file

@ -17,7 +17,7 @@ import codechicken.multipart.TSlottedPart;
* @author Calclavia * @author Calclavia
* *
*/ */
public class PartRailing extends PartFramedConnection<EnumPipeMaterial, IRailing, INodeNetwork> implements IRailing, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects public class PartRailing extends PartFramedConnection<EnumPipeMaterial, IRailing, INodeNetwork> implements IRailing, TSlottedPart, JNormalOcclusion, IHollowConnect
{ {
RedstoneControl control; RedstoneControl control;

View file

@ -85,86 +85,90 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
public void distribute() public void distribute()
{ {
Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator(); synchronized (getConnections())
while (it.hasNext())
{ {
Entry<?, ForgeDirection> entry = it.next(); Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator();
Object obj = entry.getKey();
ForgeDirection dir = entry.getValue();
if (obj instanceof PressureNode) while (it.hasNext())
{ {
PressureNode otherPipe = (PressureNode) obj; Entry<?, ForgeDirection> entry = it.next();
Object obj = entry.getKey();
ForgeDirection dir = entry.getValue();
/** if (obj instanceof PressureNode)
* Move fluid from higher pressure to lower. In this case, move from tankA to tankB.
*/
int pressureA = getPressure(dir);
int pressureB = otherPipe.getPressure(dir.getOpposite());
if (pressureA >= pressureB)
{ {
FluidTank tankA = parent.getPressureTank(); PressureNode otherPipe = (PressureNode) obj;
if (tankA != null) /**
* Move fluid from higher pressure to lower. In this case, move from tankA to
* tankB.
*/
int pressureA = getPressure(dir);
int pressureB = otherPipe.getPressure(dir.getOpposite());
if (pressureA >= pressureB)
{ {
FluidStack fluidA = tankA.getFluid(); FluidTank tankA = parent.getPressureTank();
if (fluidA != null) if (tankA != null)
{ {
int amountA = fluidA.amount; FluidStack fluidA = tankA.getFluid();
if (amountA > 0) if (fluidA != null)
{ {
FluidTank tankB = otherPipe.parent.getPressureTank(); int amountA = fluidA.amount;
if (tankB != null) if (amountA > 0)
{ {
int amountB = tankB.getFluidAmount(); FluidTank tankB = otherPipe.parent.getPressureTank();
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate())); if (tankB != null)
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{ {
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false); int amountB = tankB.getFluidAmount();
if (drainStack != null && drainStack.amount > 0) int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate()));
parent.drain(dir.getOpposite(), otherPipe.parent.fill(dir, drainStack, true), true); quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false);
if (drainStack != null && drainStack.amount > 0)
parent.drain(dir.getOpposite(), otherPipe.parent.fill(dir, drainStack, true), true);
}
} }
} }
} }
} }
} }
} }
} else if (obj instanceof IFluidHandler)
else if (obj instanceof IFluidHandler)
{
IFluidHandler fluidHandler = (IFluidHandler) obj;
int pressure = getPressure(dir);
int tankPressure = fluidHandler instanceof IPressureNodeProvider ? ((IPressureNodeProvider) fluidHandler).getNode(PressureNode.class, dir.getOpposite()).getPressure(dir.getOpposite()) : 0;
FluidTank sourceTank = parent.getPressureTank();
int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate();
if (pressure > tankPressure)
{ {
if (sourceTank.getFluidAmount() > 0 && transferAmount > 0) IFluidHandler fluidHandler = (IFluidHandler) obj;
{ int pressure = getPressure(dir);
FluidStack drainStack = parent.drain(dir.getOpposite(), transferAmount, false); int tankPressure = fluidHandler instanceof IPressureNodeProvider ? ((IPressureNodeProvider) fluidHandler).getNode(PressureNode.class, dir.getOpposite()).getPressure(dir.getOpposite()) : 0;
parent.drain(dir.getOpposite(), fluidHandler.fill(dir.getOpposite(), drainStack, true), true); FluidTank sourceTank = parent.getPressureTank();
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
FluidStack drainStack = fluidHandler.drain(dir.getOpposite(), transferAmount, false);
if (drainStack != null) int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate();
if (pressure > tankPressure)
{
if (sourceTank.getFluidAmount() > 0 && transferAmount > 0)
{ {
fluidHandler.drain(dir.getOpposite(), parent.fill(dir.getOpposite(), drainStack, true), true); FluidStack drainStack = parent.drain(dir.getOpposite(), transferAmount, false);
parent.drain(dir.getOpposite(), fluidHandler.fill(dir.getOpposite(), drainStack, true), true);
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
FluidStack drainStack = fluidHandler.drain(dir.getOpposite(), transferAmount, false);
if (drainStack != null)
{
fluidHandler.drain(dir.getOpposite(), parent.fill(dir.getOpposite(), drainStack, true), true);
}
} }
} }
} }

View file

@ -35,7 +35,7 @@ import codechicken.multipart.TileMultipart;
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 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
{ {
public static IndexedCuboid6[] sides = new IndexedCuboid6[7]; public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
@ -134,24 +134,6 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
} }
} }
@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 breakIcon;
}
@Override
public Icon getBrokenIcon(int side)
{
return breakIcon;
}
@Override @Override
public Iterable<Cuboid6> getOcclusionBoxes() public Iterable<Cuboid6> getOcclusionBoxes()
{ {
@ -170,18 +152,6 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
return isInsulated ? 8 : 6; return isInsulated ? 8 : 6;
} }
@Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
{
IconHitEffects.addHitEffects(this, hit, effectRenderer);
}
@Override
public void addDestroyEffects(EffectRenderer effectRenderer)
{
IconHitEffects.addDestroyEffects(this, effectRenderer, false);
}
public boolean isBlockedOnSide(ForgeDirection side) public boolean isBlockedOnSide(ForgeDirection side)
{ {
TMultiPart blocker = tile().partMap(side.ordinal()); TMultiPart blocker = tile().partMap(side.ordinal());
@ -309,7 +279,7 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
if (getConnector(tileEntity) != null) if (getConnector(tileEntity) != null)
{ {
this.getNetwork().merge(getConnector(tileEntity).getNetwork()); getNetwork().merge(getConnector(tileEntity).getNetwork());
} }
} }
} }
@ -373,15 +343,8 @@ public abstract class PartFramedConnection<M extends Enum, C extends IConnector<
} }
@Override @Override
public void onMoved() public void onWorldJoin()
{ {
this.refresh();
}
@Override
public void onChunkLoad()
{
super.onChunkLoad();
refresh(); refresh();
} }

View file

@ -143,6 +143,7 @@ item.resonantinduction\:wire.silver.name=Silver Wire
item.resonantinduction\:wire.superconductor.name=Superconductor Wire item.resonantinduction\:wire.superconductor.name=Superconductor Wire
item.resonantinduction\:transformer.name=Transformer item.resonantinduction\:transformer.name=Transformer
item.resonantinduction\:multimeter.name=Multimeter item.resonantinduction\:multimeter.name=Multimeter
item.resonantinduction\:multimeter.tooltip=Multimeter is a panel that display the energy and fluid information of a block.
### Quantum Tier ### Quantum Tier
tile.resonantinduction\:quantumGate.name=Quantum Gate tile.resonantinduction\:quantumGate.name=Quantum Gate