Fixed motor wrench rotation and tweaked pipe render

This commit is contained in:
Calclavia 2014-03-17 21:35:32 +08:00
parent 3e8345485d
commit 7bea838a12
9 changed files with 209 additions and 222 deletions

View file

@ -62,49 +62,46 @@ public class TileGutter extends TilePressureNode
node = new FluidGravityNode(this)
{
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
byte previousConnections = renderSides;
renderSides = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
connections.clear();
byte previousConnections = renderSides;
renderSides = 0;
TileEntity tile = position().translate(dir).getTileEntity(world());
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
if (tile instanceof IFluidHandler)
{
TileEntity tile = position().translate(dir).getTileEntity(world());
if (tile instanceof IFluidHandler)
if (tile instanceof IPressureNodeProvider)
{
if (tile instanceof IPressureNodeProvider)
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
connections.put(check, dir);
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
connections.put(check, dir);
if (tile instanceof TileGutter)
renderSides = WorldUtility.setEnableSide(renderSides, dir, true);
}
}
else
{
connections.put(tile, dir);
if (tile instanceof TileGrate)
if (tile instanceof TileGutter)
renderSides = WorldUtility.setEnableSide(renderSides, dir, true);
}
}
}
else
{
connections.put(tile, dir);
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
sendRenderUpdate();
if (tile instanceof TileGrate)
renderSides = WorldUtility.setEnableSide(renderSides, dir, true);
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
sendRenderUpdate();
}
}
};
}

View file

@ -3,6 +3,7 @@ package resonantinduction.electrical.generator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.Reference;
import universalelectricity.api.UniversalElectricity;
import calclavia.lib.prefab.block.BlockRotatable;
@ -38,6 +39,12 @@ public class BlockMotor extends BlockRotatable
return false;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return doRotateBlock(world, x, y, z, ForgeDirection.getOrientation(side));
}
@Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{

View file

@ -42,68 +42,65 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
mechanicalNode = new PacketMechanicalNode(this)
{
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
boolean didRefresh = false;
for (int i = 2; i < 6; i++)
{
connections.clear();
ForgeDirection dir = ForgeDirection.getOrientation(i);
Vector3 pos = new Vector3(TileConveyorBelt.this).translate(dir);
TileEntity tile = pos.getTileEntity(TileConveyorBelt.this.worldObj);
boolean didRefresh = false;
for (int i = 2; i < 6; i++)
if (dir == TileConveyorBelt.this.getDirection() || dir == TileConveyorBelt.this.getDirection().getOpposite())
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
Vector3 pos = new Vector3(TileConveyorBelt.this).translate(dir);
TileEntity tile = pos.getTileEntity(TileConveyorBelt.this.worldObj);
if (dir == TileConveyorBelt.this.getDirection() || dir == TileConveyorBelt.this.getDirection().getOpposite())
if (dir == TileConveyorBelt.this.getDirection())
{
if (dir == TileConveyorBelt.this.getDirection())
if (TileConveyorBelt.this.slantType == SlantType.DOWN)
{
if (TileConveyorBelt.this.slantType == SlantType.DOWN)
{
pos.translate(new Vector3(0, -1, 0));
}
else if (TileConveyorBelt.this.slantType == SlantType.UP)
{
pos.translate(new Vector3(0, 1, 0));
}
pos.translate(new Vector3(0, -1, 0));
}
else if (dir == TileConveyorBelt.this.getDirection().getOpposite())
else if (TileConveyorBelt.this.slantType == SlantType.UP)
{
if (TileConveyorBelt.this.slantType == SlantType.DOWN)
{
pos.translate(new Vector3(0, 1, 0));
}
else if (TileConveyorBelt.this.slantType == SlantType.UP)
{
pos.translate(new Vector3(0, -1, 0));
}
}
tile = pos.getTileEntity(worldObj);
if (tile instanceof TileConveyorBelt)
{
connections.put(((TileConveyorBelt) tile).getNode(MechanicalNode.class, dir.getOpposite()), dir);
didRefresh = true;
pos.translate(new Vector3(0, 1, 0));
}
}
else if (tile instanceof INodeProvider)
else if (dir == TileConveyorBelt.this.getDirection().getOpposite())
{
MechanicalNode mechanical = ((INodeProvider) tile).getNode(MechanicalNode.class, dir.getOpposite());
if (mechanical != null)
if (TileConveyorBelt.this.slantType == SlantType.DOWN)
{
connections.put(mechanical, dir);
pos.translate(new Vector3(0, 1, 0));
}
else if (TileConveyorBelt.this.slantType == SlantType.UP)
{
pos.translate(new Vector3(0, -1, 0));
}
}
}
if (!worldObj.isRemote)
{
markRefresh = true;
tile = pos.getTileEntity(worldObj);
if (tile instanceof TileConveyorBelt)
{
connections.put(((TileConveyorBelt) tile).getNode(MechanicalNode.class, dir.getOpposite()), dir);
didRefresh = true;
}
}
else if (tile instanceof INodeProvider)
{
MechanicalNode mechanical = ((INodeProvider) tile).getNode(MechanicalNode.class, dir.getOpposite());
if (mechanical != null)
{
connections.put(mechanical, dir);
}
}
}
if (!worldObj.isRemote)
{
markRefresh = true;
}
}

View file

@ -104,88 +104,85 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
}
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
/**
* Only call refresh if this is the main block of a multiblock gear or a single
* gear
* block.
*/
if (!getMultiBlock().isPrimary() || world() == null)
{
connections.clear();
return;
}
/**
* Only call refresh if this is the main block of a multiblock gear or a single
* gear
* block.
*/
if (!getMultiBlock().isPrimary() || world() == null)
/** Look for gears that are back-to-back with this gear. Equate torque. */
TileEntity tileBehind = new universalelectricity.api.vector.Vector3(tile()).translate(placementSide).getTileEntity(world());
if (tileBehind instanceof INodeProvider)
{
MechanicalNode instance = ((INodeProvider) tileBehind).getNode(MechanicalNode.class, placementSide.getOpposite());
if (instance != null && instance != this && !(instance.parent instanceof PartGearShaft) && instance.canConnect(placementSide.getOpposite(), this))
{
return;
connections.put(instance, placementSide);
}
}
/**
* Look for gears that are internal and adjacent to this gear. (The 4 sides +
* the internal center)
*/
for (int i = 0; i < 6; i++)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
TileEntity tile = tile();
if (getMultiBlock().isConstructed() && checkDir != placementSide && checkDir != placementSide.getOpposite())
{
tile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir).getTileEntity(world());
}
/** Look for gears that are back-to-back with this gear. Equate torque. */
TileEntity tileBehind = new universalelectricity.api.vector.Vector3(tile()).translate(placementSide).getTileEntity(world());
if (tileBehind instanceof INodeProvider)
if (tile instanceof INodeProvider)
{
MechanicalNode instance = ((INodeProvider) tileBehind).getNode(MechanicalNode.class, placementSide.getOpposite());
/**
* If we're checking for the block that is opposite to the gear's
* placement
* side
* (the center), then we try to look for a gear shaft in the center.
*/
MechanicalNode instance = ((INodeProvider) tile).getNode(MechanicalNode.class, checkDir == placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
if (instance != null && instance != this && !(instance.parent instanceof PartGearShaft) && instance.canConnect(placementSide.getOpposite(), this))
if (!connections.containsValue(checkDir) && instance != this && checkDir != placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
{
connections.put(instance, placementSide);
connections.put(instance, checkDir);
}
}
}
/**
* Look for gears that are internal and adjacent to this gear. (The 4 sides +
* the internal center)
*/
for (int i = 0; i < 6; i++)
int displaceCheck = 1;
if (getMultiBlock().isPrimary() && getMultiBlock().isConstructed())
{
displaceCheck = 2;
}
/** Look for gears outside this block space, the relative UP, DOWN, LEFT, RIGHT */
for (int i = 0; i < 4; i++)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(PartGear.this.placementSide.ordinal(), i));
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir, displaceCheck).getTileEntity(world());
if (!connections.containsValue(checkDir) && checkTile instanceof INodeProvider)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
MechanicalNode instance = ((INodeProvider) checkTile).getNode(MechanicalNode.class, placementSide);
TileEntity tile = tile();
if (getMultiBlock().isConstructed() && checkDir != placementSide && checkDir != placementSide.getOpposite())
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.parent instanceof PartGearShaft))
{
tile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir).getTileEntity(world());
}
if (tile instanceof INodeProvider)
{
/**
* If we're checking for the block that is opposite to the gear's
* placement
* side
* (the center), then we try to look for a gear shaft in the center.
*/
MechanicalNode instance = ((INodeProvider) tile).getNode(MechanicalNode.class, checkDir == placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
if (!connections.containsValue(checkDir) && instance != this && checkDir != placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
{
connections.put(instance, checkDir);
}
}
}
int displaceCheck = 1;
if (getMultiBlock().isPrimary() && getMultiBlock().isConstructed())
{
displaceCheck = 2;
}
/** Look for gears outside this block space, the relative UP, DOWN, LEFT, RIGHT */
for (int i = 0; i < 4; i++)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(PartGear.this.placementSide.ordinal(), i));
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir, displaceCheck).getTileEntity(world());
if (!connections.containsValue(checkDir) && checkTile instanceof INodeProvider)
{
MechanicalNode instance = ((INodeProvider) checkTile).getNode(MechanicalNode.class, placementSide);
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.parent instanceof PartGearShaft))
{
connections.put(instance, checkDir);
}
connections.put(instance, checkDir);
}
}
}

View file

@ -86,46 +86,43 @@ public class PartGearShaft extends PartMechanical
}
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
/** Check for internal connections, the FRONT and BACK. */
for (int i = 0; i < 6; i++)
{
connections.clear();
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
/** Check for internal connections, the FRONT and BACK. */
for (int i = 0; i < 6; i++)
if (checkDir == placementSide || checkDir == placementSide.getOpposite())
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
MechanicalNode instance = ((INodeProvider) tile()).getNode(MechanicalNode.class, checkDir);
if (checkDir == placementSide || checkDir == placementSide.getOpposite())
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
{
MechanicalNode instance = ((INodeProvider) tile()).getNode(MechanicalNode.class, checkDir);
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
{
connections.put(instance, checkDir);
}
connections.put(instance, checkDir);
}
}
}
/** Look for connections outside this block space, the relative FRONT and BACK */
for (int i = 0; i < 6; i++)
/** Look for connections outside this block space, the relative FRONT and BACK */
for (int i = 0; i < 6; i++)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
if (!connections.containsValue(checkDir) && (checkDir == placementSide || checkDir == placementSide.getOpposite()))
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir).getTileEntity(world());
if (!connections.containsValue(checkDir) && (checkDir == placementSide || checkDir == placementSide.getOpposite()))
if (checkTile instanceof INodeProvider)
{
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir).getTileEntity(world());
MechanicalNode instance = ((INodeProvider) checkTile).getNode(MechanicalNode.class, checkDir.getOpposite());
if (checkTile instanceof INodeProvider)
// Only connect to shafts outside of this block space.
if (instance != null && instance != this && instance.parent instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
{
MechanicalNode instance = ((INodeProvider) checkTile).getNode(MechanicalNode.class, checkDir.getOpposite());
// Only connect to shafts outside of this block space.
if (instance != null && instance != this && instance.parent instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
{
connections.put(instance, checkDir);
}
connections.put(instance, checkDir);
}
}
}

View file

@ -199,24 +199,21 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
* Recache the connections. This is the default connection implementation.
*/
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
connections.clear();
TileEntity tile = position().translate(dir).getTileEntity(world());
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
if (tile instanceof INodeProvider)
{
TileEntity tile = position().translate(dir).getTileEntity(world());
MechanicalNode check = ((INodeProvider) tile).getNode(MechanicalNode.class, dir.getOpposite());
if (tile instanceof INodeProvider)
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
MechanicalNode check = ((INodeProvider) tile).getNode(MechanicalNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
connections.put(check, dir);
}
connections.put(check, dir);
}
}
}

View file

@ -47,47 +47,45 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
node = new FluidPressureNode(this)
{
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
if (world() != null)
{
connections.clear();
byte previousConnections = getAllCurrentConnections();
currentConnections = 0;
if (world() != null)
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
byte previousConnections = getAllCurrentConnections();
currentConnections = 0;
TileEntity tile = position().translate(dir).getTileEntity(world());
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
if (tile instanceof IFluidHandler)
{
TileEntity tile = position().translate(dir).getTileEntity(world());
if (tile instanceof IFluidHandler)
if (tile instanceof IPressureNodeProvider)
{
if (tile instanceof IPressureNodeProvider)
{
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(check, dir);
}
}
else if (canConnect(dir, tile))
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(tile, dir);
connections.put(check, dir);
}
}
else if (canConnect(dir, tile))
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(tile, dir);
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (!world().isRemote && previousConnections != currentConnections)
{
sendConnectionUpdate();
}
/** Only send packet updates if visuallyConnected changed. */
if (!world().isRemote && previousConnections != currentConnections)
{
sendConnectionUpdate();
}
}
}

View file

@ -59,7 +59,7 @@ public class RenderPipe implements ISimpleItemRenderer
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef((float) x + 0.35f, (float) y + 0.35f, (float) z + 0.35f);
GL11.glScalef(0.3f, 0.3f, 0.3f);
GL11.glScalef(0.33f, 0.33f, 0.33f);
GL11.glCallList(displayList[(int) (renderPercentage * (FluidRenderUtility.DISPLAY_STAGES - 1))]);
@ -99,7 +99,7 @@ public class RenderPipe implements ISimpleItemRenderer
break;
}
GL11.glScalef(0.3f, 0.3f, 0.3f);
GL11.glScalef(0.33f, 0.33f, 0.33f);
GL11.glCallList(displayList[(int) (renderPercentage * (FluidRenderUtility.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();

View file

@ -201,24 +201,21 @@ public class FluidPressureNode extends Node<IPressureNodeProvider, TickingGrid,
* Recache the connections. This is the default connection implementation.
*/
@Override
public void recache()
public void doRecache()
{
synchronized (connections)
connections.clear();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
connections.clear();
TileEntity tile = position().translate(dir).getTileEntity(world());
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
if (tile instanceof IPressureNodeProvider)
{
TileEntity tile = position().translate(dir).getTileEntity(world());
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
if (tile instanceof IPressureNodeProvider)
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
connections.put(check, dir);
}
connections.put(check, dir);
}
}
}