Converted gear to scala
This commit is contained in:
parent
99b5a3bd68
commit
89e494116d
13 changed files with 663 additions and 780 deletions
|
@ -1,42 +0,0 @@
|
|||
package resonantinduction.mechanical.mech.gear;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import resonant.lib.multiblock.reference.MultiBlockHandler;
|
||||
import universalelectricity.core.transform.vector.Vector3;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
|
||||
public class GearMultiBlockHandler extends MultiBlockHandler<PartGear>
|
||||
{
|
||||
public GearMultiBlockHandler(PartGear wrapper)
|
||||
{
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartGear getWrapperAt(Vector3 position)
|
||||
{
|
||||
TileEntity tile = position.getTileEntity(this.tile.getWorld());
|
||||
|
||||
if (tile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart part = ((TileMultipart) tile).partMap(getPlacementSide().ordinal());
|
||||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
if (((PartGear) part).tier == this.tile.tier)
|
||||
{
|
||||
return (PartGear) part;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ForgeDirection getPlacementSide()
|
||||
{
|
||||
return tile.placementSide;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package resonantinduction.mechanical.mech.gear
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.lib.multiblock.reference.MultiBlockHandler
|
||||
import universalelectricity.core.transform.vector.Vector3
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.TileMultipart
|
||||
|
||||
class GearMultiBlockHandler(wrapper: PartGear) extends MultiBlockHandler[PartGear](wrapper: PartGear)
|
||||
{
|
||||
|
||||
override def getWrapperAt(position: Vector3): PartGear =
|
||||
{
|
||||
val tile: TileEntity = position.getTileEntity(this.tile.getWorld)
|
||||
if (tile.isInstanceOf[TileMultipart])
|
||||
{
|
||||
val part: TMultiPart = (tile.asInstanceOf[TileMultipart]).partMap(getPlacementSide.ordinal)
|
||||
if (part.isInstanceOf[PartGear])
|
||||
{
|
||||
if ((part.asInstanceOf[PartGear]).tier == this.tile.tier)
|
||||
{
|
||||
return part.asInstanceOf[PartGear]
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
def getPlacementSide: ForgeDirection =
|
||||
{
|
||||
return tile.placementSide
|
||||
}
|
||||
}
|
|
@ -1,296 +0,0 @@
|
|||
package resonantinduction.mechanical.mech.gear;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.mech.MechanicalNode;
|
||||
import resonantinduction.mechanical.mech.gearshaft.PartGearShaft;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import universalelectricity.api.core.grid.INodeProvider;
|
||||
import universalelectricity.core.transform.vector.IVectorWorld;
|
||||
import universalelectricity.core.transform.vector.VectorWorld;
|
||||
|
||||
/**
|
||||
* Node for the gear
|
||||
*
|
||||
* @author Calclavia, Edited by: Darkguardsman
|
||||
*/
|
||||
public class GearNode extends MechanicalNode
|
||||
{
|
||||
public GearNode(PartGear parent)
|
||||
{
|
||||
super(parent);
|
||||
}
|
||||
|
||||
protected PartGear gear()
|
||||
{
|
||||
return (PartGear) this.getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
if (!gear().getMultiBlock().isPrimary())
|
||||
{
|
||||
torque = 0;
|
||||
angularVelocity = 0;
|
||||
}
|
||||
else
|
||||
if (gear().tier == 10)
|
||||
{
|
||||
torque = 100;
|
||||
angularVelocity = 100;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTorqueLoad()
|
||||
{
|
||||
// Decelerate the gear based on tier.
|
||||
switch (gear().tier)
|
||||
{
|
||||
default:
|
||||
return 0.3;
|
||||
case 1:
|
||||
return 0.2;
|
||||
case 2:
|
||||
return 0.1;
|
||||
case 10:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAngularVelocityLoad()
|
||||
{
|
||||
// Decelerate the gear based on tier.
|
||||
switch (gear().tier)
|
||||
{
|
||||
default:
|
||||
return 0.03;
|
||||
case 1:
|
||||
return 0.02;
|
||||
case 2:
|
||||
return 0.01;
|
||||
case 10:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConnections()
|
||||
{
|
||||
connections.clear();
|
||||
|
||||
/** Only call refresh if this is the main block of a multiblock gear or a single gear block. */
|
||||
if (!gear().getMultiBlock().isPrimary() || world() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/** Look for gears that are back-to-back with this gear. Equate torque. */
|
||||
TileEntity tileBehind = new universalelectricity.core.transform.vector.Vector3(gear().tile()).add(gear().placementSide).getTileEntity(world());
|
||||
|
||||
if (tileBehind instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) tileBehind).getNode(MechanicalNode.class, gear().placementSide.getOpposite());
|
||||
|
||||
if (instance != null && instance != this && !(instance.getParent() instanceof PartGearShaft) && instance.canConnect(gear().placementSide.getOpposite(), this))
|
||||
{
|
||||
addConnection(instance, gear().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 = gear().tile();
|
||||
|
||||
if (gear().getMultiBlock().isConstructed() && checkDir != gear().placementSide && checkDir != gear().placementSide.getOpposite())
|
||||
{
|
||||
tile = new universalelectricity.core.transform.vector.Vector3(gear().tile()).add(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 = (MechanicalNode) ((INodeProvider) tile).getNode(MechanicalNode.class, checkDir == gear().placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
|
||||
|
||||
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear().placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
|
||||
{
|
||||
addConnection(instance, checkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int displaceCheck = 1;
|
||||
|
||||
if (gear().getMultiBlock().isPrimary() && gear().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(gear().placementSide.ordinal(), i));
|
||||
TileEntity checkTile = new universalelectricity.core.transform.vector.Vector3(gear().tile()).add(checkDir).getTileEntity(world());
|
||||
|
||||
if (!connections.containsValue(checkDir) && checkTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) checkTile).getNode(MechanicalNode.class, gear().placementSide);
|
||||
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.getParent() instanceof PartGearShaft))
|
||||
{
|
||||
addConnection(instance, checkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can this gear be connected BY the source?
|
||||
*
|
||||
* @param from - Direction source is coming from.
|
||||
* @param with - The source of the connection.
|
||||
* @return True is so.
|
||||
*/
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object with)
|
||||
{
|
||||
if (!gear().getMultiBlock().isPrimary())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (with instanceof MechanicalNode)
|
||||
{
|
||||
INodeProvider parent = ((MechanicalNode) with).getParent();
|
||||
|
||||
/** Check for flat connections (gear face on gear face) to make sure it's actually on
|
||||
* this gear block. */
|
||||
if (from == gear().placementSide.getOpposite())
|
||||
{
|
||||
if (parent instanceof PartGear || parent instanceof PartGearShaft)
|
||||
{
|
||||
if (parent instanceof PartGearShaft)
|
||||
{
|
||||
PartGearShaft shaft = (PartGearShaft) parent;
|
||||
return shaft.tile().partMap(from.getOpposite().ordinal()) == gear() && Math.abs(shaft.placementSide.offsetX) == Math.abs(gear().placementSide.offsetX) && Math.abs(shaft.placementSide.offsetY) == Math.abs(gear().placementSide.offsetY) && Math.abs(shaft.placementSide.offsetZ) == Math.abs(gear().placementSide.offsetZ);
|
||||
}
|
||||
else if (parent instanceof PartGear)
|
||||
{
|
||||
if (((PartGear) parent).tile() == gear().tile() && !gear().getMultiBlock().isConstructed())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (((PartGear) parent).placementSide != gear().placementSide)
|
||||
{
|
||||
TMultiPart part = gear().tile().partMap(((PartGear) parent).placementSide.ordinal());
|
||||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
/** Case when we connect gears via edges internally. Large gear
|
||||
* attempt to connect to small gear. */
|
||||
PartGear sourceGear = (PartGear) part;
|
||||
|
||||
if (sourceGear.isCenterMultiBlock() && !sourceGear.getMultiBlock().isPrimary())
|
||||
{
|
||||
// For large gear to small gear on edge connection.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Small gear attempting to connect to large gear. */
|
||||
if (gear().getMultiBlock().isConstructed())
|
||||
{
|
||||
TMultiPart checkPart = ((PartGear) parent).tile().partMap(gear().placementSide.ordinal());
|
||||
|
||||
if (checkPart instanceof PartGear)
|
||||
{
|
||||
ForgeDirection requiredDirection = ((PartGear) checkPart).getPosition().subtract(position()).toForgeDirection();
|
||||
return ((PartGear) checkPart).isCenterMultiBlock() && ((PartGear) parent).placementSide == requiredDirection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Face to face stick connection. */
|
||||
TileEntity sourceTile = position().add(from.getOpposite()).getTileEntity(world());
|
||||
|
||||
if (sourceTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = (MechanicalNode) ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from);
|
||||
return sourceInstance == with;
|
||||
}
|
||||
}
|
||||
else if (from == gear().placementSide)
|
||||
{
|
||||
/** Face to face stick connection. */
|
||||
TileEntity sourceTile = position().add(from).getTileEntity(world());
|
||||
|
||||
if (sourceTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = (MechanicalNode) ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
|
||||
return sourceInstance == with;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity destinationTile = ((MechanicalNode) with).position().add(from.getOpposite()).getTileEntity(world());
|
||||
|
||||
if (destinationTile instanceof INodeProvider && destinationTile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart destinationPart = ((TileMultipart) destinationTile).partMap(gear().placementSide.ordinal());
|
||||
|
||||
if (destinationPart instanceof PartGear)
|
||||
{
|
||||
if (gear() != destinationPart)
|
||||
{
|
||||
return ((PartGear) destinationPart).isCenterMultiBlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRadius(ForgeDirection dir, IMechanicalNode with)
|
||||
{
|
||||
universalelectricity.core.transform.vector.Vector3 deltaPos = new VectorWorld((IVectorWorld)with).subtract(position());
|
||||
|
||||
boolean caseX = gear().placementSide.offsetX != 0 && deltaPos.y() == 0 && deltaPos.z() == 0;
|
||||
boolean caseY = gear().placementSide.offsetY != 0 && deltaPos.x() == 0 && deltaPos.z() == 0;
|
||||
boolean caseZ = gear().placementSide.offsetZ != 0 && deltaPos.x() == 0 && deltaPos.y() == 0;
|
||||
|
||||
if (caseX || caseY || caseZ)
|
||||
{
|
||||
return super.getRadius(dir, with);
|
||||
}
|
||||
|
||||
return gear().getMultiBlock().isConstructed() ? 1.5f : super.getRadius(dir, with);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
package resonantinduction.mechanical.mech.gear
|
||||
|
||||
import codechicken.lib.vec.Rotation
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.TileMultipart
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonantinduction.core.interfaces.IMechanicalNode
|
||||
import resonantinduction.mechanical.mech.MechanicalNode
|
||||
import resonantinduction.mechanical.mech.gearshaft.PartGearShaft
|
||||
import universalelectricity.api.core.grid.INodeProvider
|
||||
import universalelectricity.core.transform.vector.IVectorWorld
|
||||
import universalelectricity.core.transform.vector.VectorWorld
|
||||
import universalelectricity.core.transform.vector.Vector3
|
||||
|
||||
/**
|
||||
* Node for the gear
|
||||
*
|
||||
* @author Calclavia, Edited by: Darkguardsman
|
||||
*/
|
||||
class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
|
||||
{
|
||||
|
||||
protected def gear: PartGear =
|
||||
{
|
||||
return this.getParent.asInstanceOf[PartGear]
|
||||
}
|
||||
|
||||
override def onUpdate
|
||||
{
|
||||
super.onUpdate
|
||||
if (!gear.getMultiBlock.isPrimary)
|
||||
{
|
||||
torque = 0
|
||||
angularVelocity = 0
|
||||
}
|
||||
else if (gear.tier == 10)
|
||||
{
|
||||
torque = 100
|
||||
angularVelocity = 100
|
||||
}
|
||||
}
|
||||
|
||||
override def getTorqueLoad: Double =
|
||||
{
|
||||
if (gear.tier == 1) return 0.2
|
||||
if (gear.tier == 2) return 0.1
|
||||
if (gear.tier == 0) return 0
|
||||
return 0.3
|
||||
}
|
||||
|
||||
override def getAngularVelocityLoad: Double =
|
||||
{
|
||||
if (gear.tier == 1) return 0.2
|
||||
if (gear.tier == 2) return 0.1
|
||||
if (gear.tier == 0) return 0
|
||||
return 0.3
|
||||
}
|
||||
|
||||
override def buildConnections
|
||||
{
|
||||
connections.clear
|
||||
if (!gear.getMultiBlock.isPrimary || world == null)
|
||||
{
|
||||
return
|
||||
}
|
||||
val tileBehind: TileEntity = new Vector3(gear.tile).add(gear.placementSide).getTileEntity(world)
|
||||
if (tileBehind.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val instance: MechanicalNode = (tileBehind.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide.getOpposite).asInstanceOf[MechanicalNode]
|
||||
if (instance != null && instance != this && !(instance.getParent.isInstanceOf[PartGearShaft]) && instance.canConnect(gear.placementSide.getOpposite, this))
|
||||
{
|
||||
addConnection(instance, gear.placementSide)
|
||||
}
|
||||
}
|
||||
{
|
||||
var i: Int = 0
|
||||
while (i < 6)
|
||||
{
|
||||
{
|
||||
val checkDir: ForgeDirection = ForgeDirection.getOrientation(i)
|
||||
var tile: TileEntity = gear.tile
|
||||
if (gear.getMultiBlock.isConstructed && checkDir != gear.placementSide && checkDir != gear.placementSide.getOpposite)
|
||||
{
|
||||
tile = new Vector3(gear.tile).add(checkDir).getTileEntity(world)
|
||||
}
|
||||
if (tile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode]
|
||||
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(checkDir.getOpposite, this))
|
||||
{
|
||||
addConnection(instance, checkDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
({
|
||||
i += 1; i - 1
|
||||
})
|
||||
}
|
||||
}
|
||||
var displaceCheck: Int = 1
|
||||
if (gear.getMultiBlock.isPrimary && gear.getMultiBlock.isConstructed)
|
||||
{
|
||||
displaceCheck = 2
|
||||
}
|
||||
{
|
||||
var i: Int = 0
|
||||
while (i < 4)
|
||||
{
|
||||
{
|
||||
val checkDir: ForgeDirection = ForgeDirection.getOrientation(Rotation.rotateSide(gear.placementSide.ordinal, i))
|
||||
val checkTile: TileEntity = new Vector3(gear.tile).add(checkDir).getTileEntity(world)
|
||||
if (!connections.containsValue(checkDir) && checkTile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide).asInstanceOf[MechanicalNode]
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this) && !(instance.getParent.isInstanceOf[PartGearShaft]))
|
||||
{
|
||||
addConnection(instance, checkDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
({
|
||||
i += 1; i - 1
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can this gear be connected BY the source?
|
||||
*
|
||||
* @param from - Direction source is coming from.
|
||||
* @param with - The source of the connection.
|
||||
* @return True is so.
|
||||
*/
|
||||
override def canConnect(from: ForgeDirection, `with`: AnyRef): Boolean =
|
||||
{
|
||||
if (!gear.getMultiBlock.isPrimary)
|
||||
{
|
||||
return false
|
||||
}
|
||||
if (`with`.isInstanceOf[MechanicalNode])
|
||||
{
|
||||
val parent: INodeProvider = (`with`.asInstanceOf[MechanicalNode]).getParent
|
||||
if (from eq gear.placementSide.getOpposite)
|
||||
{
|
||||
if (parent.isInstanceOf[PartGear] || parent.isInstanceOf[PartGearShaft])
|
||||
{
|
||||
if (parent.isInstanceOf[PartGearShaft])
|
||||
{
|
||||
val shaft: PartGearShaft = parent.asInstanceOf[PartGearShaft]
|
||||
return shaft.tile.partMap(from.getOpposite.ordinal) != gear && Math.abs(shaft.placementSide.offsetX) == Math.abs(gear.placementSide.offsetX) && Math.abs(shaft.placementSide.offsetY) == Math.abs(gear.placementSide.offsetY) && Math.abs(shaft.placementSide.offsetZ) == Math.abs(gear.placementSide.offsetZ)
|
||||
}
|
||||
else if (parent.isInstanceOf[PartGear])
|
||||
{
|
||||
if ((parent.asInstanceOf[PartGear]).tile == gear.tile && !gear.getMultiBlock.isConstructed)
|
||||
{
|
||||
return true
|
||||
}
|
||||
if ((parent.asInstanceOf[PartGear]).placementSide ne gear.placementSide)
|
||||
{
|
||||
val part: TMultiPart = gear.tile.partMap((parent.asInstanceOf[PartGear]).placementSide.ordinal)
|
||||
if (part.isInstanceOf[PartGear])
|
||||
{
|
||||
val sourceGear: PartGear = part.asInstanceOf[PartGear]
|
||||
if (sourceGear.isCenterMultiBlock && !sourceGear.getMultiBlock.isPrimary)
|
||||
{
|
||||
return true
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gear.getMultiBlock.isConstructed)
|
||||
{
|
||||
val checkPart: TMultiPart = (parent.asInstanceOf[PartGear]).tile.partMap(gear.placementSide.ordinal)
|
||||
if (checkPart.isInstanceOf[PartGear])
|
||||
{
|
||||
val requiredDirection: ForgeDirection = (checkPart.asInstanceOf[PartGear]).getPosition.subtract(position).toForgeDirection
|
||||
return (checkPart.asInstanceOf[PartGear]).isCenterMultiBlock && (parent.asInstanceOf[PartGear]).placementSide == requiredDirection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val sourceTile: TileEntity = position.add(from.getOpposite).getTileEntity(world)
|
||||
if (sourceTile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from).asInstanceOf[MechanicalNode]
|
||||
return sourceInstance eq `with`
|
||||
}
|
||||
}
|
||||
else if (from eq gear.placementSide)
|
||||
{
|
||||
val sourceTile: TileEntity = position.add(from).getTileEntity(world)
|
||||
if (sourceTile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
|
||||
return sourceInstance eq `with`
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val destinationTile: TileEntity = (`with`.asInstanceOf[MechanicalNode]).position.add(from.getOpposite).getTileEntity(world)
|
||||
if (destinationTile.isInstanceOf[INodeProvider] && destinationTile.isInstanceOf[TileMultipart])
|
||||
{
|
||||
val destinationPart: TMultiPart = (destinationTile.asInstanceOf[TileMultipart]).partMap(gear.placementSide.ordinal)
|
||||
if (destinationPart.isInstanceOf[PartGear])
|
||||
{
|
||||
if (gear ne destinationPart)
|
||||
{
|
||||
return (destinationPart.asInstanceOf[PartGear]).isCenterMultiBlock
|
||||
}
|
||||
else
|
||||
{
|
||||
return true
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override def getRadius(dir: ForgeDirection, `with`: IMechanicalNode): Double =
|
||||
{
|
||||
val deltaPos: Vector3 = new VectorWorld(`with`.asInstanceOf[IVectorWorld]).subtract(position)
|
||||
val caseX: Boolean = gear.placementSide.offsetX != 0 && deltaPos.y == 0 && deltaPos.z == 0
|
||||
val caseY: Boolean = gear.placementSide.offsetY != 0 && deltaPos.x == 0 && deltaPos.z == 0
|
||||
val caseZ: Boolean = gear.placementSide.offsetZ != 0 && deltaPos.x == 0 && deltaPos.y == 0
|
||||
if (caseX || caseY || caseZ)
|
||||
{
|
||||
return super.getRadius(dir, `with`)
|
||||
}
|
||||
return if (gear.getMultiBlock.isConstructed) 1.5f else super.getRadius(dir, `with`)
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package resonantinduction.mechanical.mech.gear;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.prefab.part.IHighlight;
|
||||
import resonantinduction.mechanical.mech.gearshaft.PartGearShaft;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.FacePlacementGrid$;
|
||||
import codechicken.multipart.JItemMultiPart;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.PartMap;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
|
||||
public class ItemGear extends JItemMultiPart implements IHighlight
|
||||
{
|
||||
public ItemGear()
|
||||
{
|
||||
super();
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return super.getUnlocalizedName(itemStack) + "." + itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
|
||||
{
|
||||
PartGear part = (PartGear) MultiPartRegistry.createPart("resonant_induction_gear", false);
|
||||
side = FacePlacementGrid$.MODULE$.getHitSlot(hit, side);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos.x, pos.y, pos.z);
|
||||
|
||||
if (tile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side);
|
||||
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
|
||||
boolean clickedCenter = hit.mag() < 0.4;
|
||||
|
||||
if ((clickedCenter && centerPart instanceof PartGearShaft))
|
||||
{
|
||||
side ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
part.preparePlacement(side, itemStack.getItemDamage());
|
||||
return part;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item itemID, CreativeTabs tab, List listToAddTo)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
listToAddTo.add(new ItemStack(itemID, 1, i));
|
||||
}
|
||||
|
||||
listToAddTo.add(new ItemStack(itemID, 1, 10));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighlightType()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package resonantinduction.mechanical.mech.gear
|
||||
|
||||
import java.util.List
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.World
|
||||
import resonantinduction.core.prefab.part.IHighlight
|
||||
import resonantinduction.mechanical.mech.gearshaft.PartGearShaft
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.microblock.FacePlacementGrid
|
||||
import codechicken.multipart.JItemMultiPart
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import codechicken.multipart.PartMap
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.TileMultipart
|
||||
import resonant.lib.wrapper.WrapList._
|
||||
|
||||
class ItemGear extends JItemMultiPart with IHighlight
|
||||
{
|
||||
//Constructor
|
||||
setHasSubtypes(true)
|
||||
|
||||
override def getUnlocalizedName(itemStack: ItemStack): String =
|
||||
{
|
||||
return super.getUnlocalizedName(itemStack) + "." + itemStack.getItemDamage
|
||||
}
|
||||
|
||||
override def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, s: Int, hit: Vector3): TMultiPart =
|
||||
{
|
||||
val part: PartGear = MultiPartRegistry.createPart("resonant_induction_gear", false).asInstanceOf[PartGear]
|
||||
var side: Int = FacePlacementGrid.getHitSlot(hit, s)
|
||||
val tile: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
|
||||
if (tile.isInstanceOf[TileMultipart])
|
||||
{
|
||||
val occupyingPart: TMultiPart = (tile.asInstanceOf[TileMultipart]).partMap(side)
|
||||
val centerPart: TMultiPart = (tile.asInstanceOf[TileMultipart]).partMap(PartMap.CENTER.ordinal)
|
||||
val clickedCenter: Boolean = hit.mag < 0.4
|
||||
if ((clickedCenter && centerPart.isInstanceOf[PartGearShaft]))
|
||||
{
|
||||
side ^= 1
|
||||
}
|
||||
}
|
||||
part.preparePlacement(side, itemStack.getItemDamage)
|
||||
return part
|
||||
}
|
||||
|
||||
override def getSubItems(itemID: Item, tab: CreativeTabs, listToAddTo: List[_])
|
||||
{
|
||||
for(i <- 0 to 3)
|
||||
{
|
||||
listToAddTo.add(new ItemStack(itemID, 1, i))
|
||||
|
||||
}
|
||||
listToAddTo.add(new ItemStack(itemID, 1, 10))
|
||||
}
|
||||
|
||||
def getHighlightType: Int =
|
||||
{
|
||||
return 0
|
||||
}
|
||||
}
|
|
@ -1,258 +0,0 @@
|
|||
package resonantinduction.mechanical.mech.gear;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import resonant.lib.multiblock.reference.IMultiBlockStructure;
|
||||
import resonant.lib.utility.WrenchUtility;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.mech.PartMechanical;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.FaceMicroClass;
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import universalelectricity.api.core.grid.INode;
|
||||
|
||||
/** We assume all the force acting on the gear is 90 degrees.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class PartGear extends PartMechanical implements IMultiBlockStructure<PartGear>
|
||||
{
|
||||
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
|
||||
|
||||
static
|
||||
{
|
||||
oBoxes[0][0] = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1);
|
||||
oBoxes[0][1] = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D);
|
||||
for (int s = 1; s < 6; s++)
|
||||
{
|
||||
Transformation t = Rotation.sideRotations[s].at(Vector3.center);
|
||||
oBoxes[s][0] = oBoxes[0][0].copy().apply(t);
|
||||
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isClockwiseCrank = true;
|
||||
private int manualCrankTime = 0;
|
||||
private int multiBlockRadius = 1;
|
||||
|
||||
public PartGear()
|
||||
{
|
||||
super();
|
||||
node = new GearNode(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
node.apply(this, isClockwiseCrank ? 15 : -15, isClockwiseCrank ? 0.025f : -0.025f);
|
||||
manualCrankTime--;
|
||||
}
|
||||
}
|
||||
getMultiBlock().update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientUpdate()
|
||||
{
|
||||
if (getMultiBlock().isPrimary())
|
||||
super.checkClientUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null && itemStack.getItem() instanceof ItemHandCrank)
|
||||
{
|
||||
if (!world().isRemote && ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
getMultiBlock().get().node.torque = -getMultiBlock().get().node.torque;
|
||||
getMultiBlock().get().node.angularVelocity = -getMultiBlock().get().node.angularVelocity;
|
||||
return true;
|
||||
}
|
||||
|
||||
isClockwiseCrank = player.isSneaking();
|
||||
getMultiBlock().get().manualCrankTime = 20;
|
||||
world().playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, Reference.prefix() + "gearCrank", 0.5f, 0.9f + world().rand.nextFloat() * 0.2f);
|
||||
player.addExhaustion(0.01f);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WrenchUtility.isWrench(itemStack))
|
||||
{
|
||||
getMultiBlock().toggleConstruct();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.activate(player, hit, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRemove()
|
||||
{
|
||||
super.preRemove();
|
||||
getMultiBlock().deconstruct();
|
||||
}
|
||||
|
||||
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
|
||||
* gears?
|
||||
*
|
||||
* @return */
|
||||
public boolean isCenterMultiBlock()
|
||||
{
|
||||
if (!getMultiBlock().isConstructed())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
universalelectricity.core.transform.vector.Vector3 primaryPos = getMultiBlock().getPrimary().getPosition();
|
||||
|
||||
if (primaryPos.xi() == x() && placementSide.offsetX == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (primaryPos.yi() == y() && placementSide.offsetY == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (primaryPos.zi() == z() && placementSide.offsetZ == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItem()
|
||||
{
|
||||
return new ItemStack(Mechanical.itemGear, 1, tier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(Vector3 pos, float frame, int pass)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
RenderGear.INSTANCE.renderDynamic(this, pos.x, pos.y, pos.z, tier);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return "resonant_induction_gear";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
getMultiBlock().load(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
getMultiBlock().save(nbt);
|
||||
}
|
||||
|
||||
/** Multiblock */
|
||||
private GearMultiBlockHandler multiBlock;
|
||||
|
||||
@Override
|
||||
public universalelectricity.core.transform.vector.Vector3[] getMultiBlockVectors()
|
||||
{
|
||||
return new universalelectricity.core.transform.vector.Vector3(this.x(), this.y(), this.z()).getAround(this.world(), placementSide, 1).toArray(new universalelectricity.core.transform.vector.Vector3[9]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return world();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiBlockChanged()
|
||||
{
|
||||
if (world() != null)
|
||||
{
|
||||
tile().notifyPartChange(this);
|
||||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
sendDescUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GearMultiBlockHandler getMultiBlock()
|
||||
{
|
||||
if (multiBlock == null)
|
||||
multiBlock = new GearMultiBlockHandler(this);
|
||||
|
||||
return multiBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
|
||||
{
|
||||
if (nodeType.isAssignableFrom(node.getClass()))
|
||||
return getMultiBlock().get().node;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Multipart Bounds */
|
||||
@Override
|
||||
public Iterable<Cuboid6> getOcclusionBoxes()
|
||||
{
|
||||
return Arrays.asList(oBoxes[this.placementSide.ordinal()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotMask()
|
||||
{
|
||||
return 1 << this.placementSide.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Cuboid6 getRenderBounds()
|
||||
{
|
||||
return Cuboid6.full.copy().expand(multiBlockRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[PartGear]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s ";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
package resonantinduction.mechanical.mech.gear
|
||||
|
||||
import java.util
|
||||
|
||||
import codechicken.lib.vec.{Cuboid6, Rotation, Transformation, Vector3}
|
||||
import codechicken.microblock.FaceMicroClass
|
||||
import codechicken.multipart.ControlKeyModifer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.lib.multiblock.reference.IMultiBlockStructure
|
||||
import resonant.lib.utility.WrenchUtility
|
||||
import resonantinduction.core.Reference
|
||||
import resonantinduction.mechanical.Mechanical
|
||||
import resonantinduction.mechanical.mech.PartMechanical
|
||||
import universalelectricity.api.core.grid.INode
|
||||
import universalelectricity.core.transform.vector.VectorWorld
|
||||
|
||||
/** We assume all the force acting on the gear is 90 degrees.
|
||||
*
|
||||
* @author Calclavia */
|
||||
object PartGear
|
||||
{
|
||||
var oBoxes: Array[Array[Cuboid6]] = new Array[Array[Cuboid6]](6)
|
||||
|
||||
oBoxes(0)(0) = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1)
|
||||
oBoxes(0)(1) = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D)
|
||||
{
|
||||
var s: Int = 1
|
||||
while (s < 6)
|
||||
{
|
||||
{
|
||||
val t: Transformation = Rotation.sideRotations(s).at(Vector3.center)
|
||||
oBoxes(s)(0) = oBoxes(0)(0).copy.apply(t)
|
||||
oBoxes(s)(1) = oBoxes(0)(1).copy.apply(t)
|
||||
}
|
||||
({
|
||||
s += 1; s - 1
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||
{
|
||||
var isClockwiseCrank: Boolean = true
|
||||
var manualCrankTime: Int = 0
|
||||
var multiBlockRadius: Int = 1
|
||||
/** Multiblock */
|
||||
var multiBlock: GearMultiBlockHandler = null
|
||||
|
||||
//Constructor
|
||||
node = new GearNode(this)
|
||||
|
||||
override def update
|
||||
{
|
||||
super.update
|
||||
if (!this.world.isRemote)
|
||||
{
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
node.apply(this, if (isClockwiseCrank) 15 else -15, if (isClockwiseCrank) 0.025f else -0.025f)
|
||||
manualCrankTime -= 1
|
||||
}
|
||||
}
|
||||
getMultiBlock.update
|
||||
}
|
||||
|
||||
override def checkClientUpdate
|
||||
{
|
||||
if (getMultiBlock.isPrimary) super.checkClientUpdate
|
||||
}
|
||||
|
||||
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
|
||||
{
|
||||
if (itemStack != null && itemStack.getItem.isInstanceOf[ItemHandCrank])
|
||||
{
|
||||
if (!world.isRemote && ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
getMultiBlock.get.node.torque = -getMultiBlock.get.node.torque
|
||||
getMultiBlock.get.node.angularVelocity = -getMultiBlock.get.node.angularVelocity
|
||||
return true
|
||||
}
|
||||
isClockwiseCrank = player.isSneaking
|
||||
//TODO fix;
|
||||
// getMultiBlock.get.manualCrankTime = 20
|
||||
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f)
|
||||
player.addExhaustion(0.01f)
|
||||
return true
|
||||
}
|
||||
if (WrenchUtility.isWrench(itemStack))
|
||||
{
|
||||
getMultiBlock.toggleConstruct
|
||||
return true
|
||||
}
|
||||
return super.activate(player, hit, itemStack)
|
||||
}
|
||||
|
||||
override def preRemove
|
||||
{
|
||||
super.preRemove
|
||||
getMultiBlock.deconstruct
|
||||
}
|
||||
|
||||
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
|
||||
* gears?
|
||||
*
|
||||
* @return*/
|
||||
def isCenterMultiBlock: Boolean =
|
||||
{
|
||||
if (!getMultiBlock.isConstructed)
|
||||
{
|
||||
return true
|
||||
}
|
||||
val primaryPos: VectorWorld = getMultiBlock.getPrimary.getPosition
|
||||
if (primaryPos.xi == x && placementSide.offsetX == 0)
|
||||
{
|
||||
return true
|
||||
}
|
||||
if (primaryPos.yi == y && placementSide.offsetY == 0)
|
||||
{
|
||||
return true
|
||||
}
|
||||
if (primaryPos.zi == z && placementSide.offsetZ == 0)
|
||||
{
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
protected def getItem: ItemStack =
|
||||
{
|
||||
return new ItemStack(Mechanical.itemGear, 1, tier)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
RenderGear.INSTANCE.renderDynamic(this, pos.x, pos.y, pos.z, tier)
|
||||
}
|
||||
}
|
||||
|
||||
def getType: String =
|
||||
{
|
||||
return "resonant_induction_gear"
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
{
|
||||
super.load(nbt)
|
||||
getMultiBlock.load(nbt)
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound)
|
||||
{
|
||||
super.save(nbt)
|
||||
getMultiBlock.save(nbt)
|
||||
}
|
||||
|
||||
override def getMultiBlockVectors: java.util.List[universalelectricity.core.transform.vector.Vector3] =
|
||||
{
|
||||
val vec = new universalelectricity.core.transform.vector.Vector3(this.x, this.y, this.z)
|
||||
var array : java.util.List[universalelectricity.core.transform.vector.Vector3] = vec.getAround(this.world, placementSide, 1)
|
||||
return array
|
||||
}
|
||||
|
||||
def getWorld: World =
|
||||
{
|
||||
return world
|
||||
}
|
||||
|
||||
def onMultiBlockChanged
|
||||
{
|
||||
if (world != null)
|
||||
{
|
||||
tile.notifyPartChange(this)
|
||||
if (!world.isRemote)
|
||||
{
|
||||
sendDescUpdate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def getMultiBlock: GearMultiBlockHandler =
|
||||
{
|
||||
if (multiBlock == null) multiBlock = new GearMultiBlockHandler(this)
|
||||
return multiBlock
|
||||
}
|
||||
|
||||
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
|
||||
{
|
||||
if (nodeType.isAssignableFrom(node.getClass)) return getMultiBlock.get.node
|
||||
return null
|
||||
}
|
||||
|
||||
/** Multipart Bounds */
|
||||
def getOcclusionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
val list: java.util.List[Cuboid6] = new util.ArrayList[Cuboid6];
|
||||
for(v <- PartGear.oBoxes(this.placementSide.ordinal))
|
||||
{
|
||||
list.add(v)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
def getSlotMask: Int =
|
||||
{
|
||||
return 1 << this.placementSide.ordinal
|
||||
}
|
||||
|
||||
def getBounds: Cuboid6 =
|
||||
{
|
||||
return FaceMicroClass.aBounds(0x10 | this.placementSide.ordinal)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def getRenderBounds: Cuboid6 =
|
||||
{
|
||||
return Cuboid6.full.copy.expand(multiBlockRadius)
|
||||
}
|
||||
|
||||
override def toString: java.lang.String =
|
||||
{
|
||||
return "[PartGear]" + x + "x " + y + "y " + z + "z " + getSlotMask + "s "
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package resonantinduction.mechanical.mech.gear;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.client.model.AdvancedModelLoader;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonant.content.prefab.scala.render.ISimpleItemRenderer;
|
||||
import resonant.lib.render.RenderUtility;
|
||||
import resonantinduction.core.Reference;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderGear implements ISimpleItemRenderer
|
||||
{
|
||||
public static final RenderGear INSTANCE = new RenderGear();
|
||||
public final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "gears.obj"));
|
||||
|
||||
|
||||
public void renderGear(int side, int tier, boolean isLarge, double angle)
|
||||
{
|
||||
switch (tier)
|
||||
{
|
||||
default:
|
||||
RenderUtility.bind(Reference.blockTextureDirectory() + "planks_oak.png");
|
||||
break;
|
||||
case 1:
|
||||
RenderUtility.bind(Reference.blockTextureDirectory() + "cobblestone.png");
|
||||
break;
|
||||
case 2:
|
||||
RenderUtility.bind(Reference.blockTextureDirectory() + "iron_block.png");
|
||||
break;
|
||||
case 10:
|
||||
RenderUtility.bind(Reference.blockTextureDirectory() + "pumpkin_top.png");
|
||||
break;
|
||||
}
|
||||
|
||||
RenderUtility.rotateFaceBlockToSide(ForgeDirection.getOrientation(side));
|
||||
GL11.glRotated(angle, 0, 1, 0);
|
||||
|
||||
if (isLarge)
|
||||
{
|
||||
MODEL.renderOnly("LargeGear");
|
||||
}
|
||||
else
|
||||
{
|
||||
MODEL.renderOnly("SmallGear");
|
||||
}
|
||||
}
|
||||
|
||||
public void renderDynamic(PartGear part, double x, double y, double z, int tier)
|
||||
{
|
||||
if (part.getMultiBlock().isPrimary())
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
// Center the model first.
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||
GL11.glPushMatrix();
|
||||
renderGear(part.placementSide.ordinal(), part.tier, part.getMultiBlock().isConstructed(), Math.toDegrees(part.node.renderAngle));
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data)
|
||||
{
|
||||
GL11.glRotatef(90, 1, 0, 0);
|
||||
renderGear(-1, itemStack.getItemDamage(), false, 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package resonantinduction.mechanical.mech.gear
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraftforge.client.IItemRenderer
|
||||
import net.minecraftforge.client.model.AdvancedModelLoader
|
||||
import net.minecraftforge.client.model.IModelCustom
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.opengl.GL11
|
||||
import resonant.content.prefab.scala.render.ISimpleItemRenderer
|
||||
import resonant.lib.render.RenderUtility
|
||||
import resonantinduction.core.Reference
|
||||
|
||||
@SideOnly(Side.CLIENT) object RenderGear
|
||||
{
|
||||
final val INSTANCE: RenderGear = new RenderGear
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
class RenderGear extends ISimpleItemRenderer
|
||||
{
|
||||
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "gears.obj"))
|
||||
|
||||
def renderGear(side: Int, tier: Int, isLarge: Boolean, angle: Double)
|
||||
{
|
||||
if (tier == 1)
|
||||
{
|
||||
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
|
||||
}
|
||||
else if (tier == 2)
|
||||
{
|
||||
RenderUtility.bind(Reference.blockTextureDirectory + "iron_block.png")
|
||||
}
|
||||
else if (tier == 10)
|
||||
{
|
||||
RenderUtility.bind(Reference.blockTextureDirectory + "pumpkin_top.png")
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
|
||||
}
|
||||
RenderUtility.rotateFaceBlockToSide(ForgeDirection.getOrientation(side))
|
||||
GL11.glRotated(angle, 0, 1, 0)
|
||||
if (isLarge)
|
||||
{
|
||||
MODEL.renderOnly("LargeGear")
|
||||
}
|
||||
else
|
||||
{
|
||||
MODEL.renderOnly("SmallGear")
|
||||
}
|
||||
}
|
||||
|
||||
def renderDynamic(part: PartGear, x: Double, y: Double, z: Double, tier: Int)
|
||||
{
|
||||
if (part.getMultiBlock.isPrimary)
|
||||
{
|
||||
GL11.glPushMatrix
|
||||
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5f, y.asInstanceOf[Float] + 0.5f, z.asInstanceOf[Float] + 0.5f)
|
||||
GL11.glPushMatrix
|
||||
renderGear(part.placementSide.ordinal, part.tier, part.getMultiBlock.isConstructed, Math.toDegrees(part.node.renderAngle))
|
||||
GL11.glPopMatrix
|
||||
GL11.glPopMatrix
|
||||
}
|
||||
}
|
||||
|
||||
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
|
||||
{
|
||||
GL11.glRotatef(90, 1, 0, 0)
|
||||
renderGear(-1, itemStack.getItemDamage, false, 0)
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package resonantinduction.mechanical.mech.gearshaft
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Iterator
|
||||
import java.util.List
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonantinduction.mechanical.mech.MechanicalNode
|
||||
|
@ -34,13 +31,10 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
|
|||
override def buildConnections
|
||||
{
|
||||
connections.clear
|
||||
val dirs: List[ForgeDirection] = new ArrayList[ForgeDirection]
|
||||
dirs.add(shaft.placementSide)
|
||||
dirs.add(shaft.placementSide.getOpposite)
|
||||
val it: Iterator[ForgeDirection] = dirs.iterator
|
||||
while (it.hasNext)
|
||||
|
||||
for(ch <- List(shaft.placementSide, shaft.placementSide.getOpposite))
|
||||
{
|
||||
val checkDir: ForgeDirection = it.next
|
||||
val checkDir: ForgeDirection = ch
|
||||
if (checkDir == shaft.placementSide || checkDir == shaft.placementSide.getOpposite)
|
||||
{
|
||||
if (shaft.tile.isInstanceOf[INodeProvider])
|
||||
|
@ -49,16 +43,8 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
|
|||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this))
|
||||
{
|
||||
addConnection(instance, checkDir)
|
||||
it.remove
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dirs.isEmpty)
|
||||
{
|
||||
for (checkDir : ForgeDirection <- dirs)
|
||||
{
|
||||
if (!connections.containsValue(checkDir) && (checkDir == shaft.placementSide || checkDir == shaft.placementSide.getOpposite))
|
||||
}else
|
||||
{
|
||||
val checkTile: TileEntity = new Vector3(shaft.tile).add(checkDir).getTileEntity(world)
|
||||
if (checkTile.isInstanceOf[INodeProvider])
|
||||
|
|
|
@ -19,6 +19,6 @@ class NodeMechanicalPiston(parent: TileMechanicalPiston) extends MechanicalNode(
|
|||
|
||||
protected override def revolve
|
||||
{
|
||||
(getParent.asInstanceOf[TileMechanicalPiston]).markRevolve = true
|
||||
getParent.asInstanceOf[TileMechanicalPiston].markRevolve = true
|
||||
}
|
||||
}
|
|
@ -1,25 +1,23 @@
|
|||
package resonantinduction.mechanical.mech.process.crusher
|
||||
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper
|
||||
import resonant.content.factory.resources.RecipeType
|
||||
import resonantinduction.mechanical.mech.TileMechanical
|
||||
import java.lang.reflect.Method
|
||||
import java.util.List
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.World
|
||||
import resonant.api.recipe.MachineRecipes
|
||||
import resonant.api.recipe.RecipeResource
|
||||
import resonant.api.recipe.{MachineRecipes, RecipeResource}
|
||||
import resonant.content.factory.resources.RecipeType
|
||||
import resonant.lib.config.Config
|
||||
import resonant.lib.utility.MovementUtility
|
||||
import resonant.lib.utility.inventory.InventoryUtility
|
||||
import resonantinduction.core.ResonantInduction
|
||||
import resonantinduction.mechanical.mech.TileMechanical
|
||||
import universalelectricity.api.core.grid.INode
|
||||
import universalelectricity.core.transform.vector.Vector3
|
||||
import java.lang.reflect.Method
|
||||
import java.util.List
|
||||
|
||||
/**
|
||||
* Mechanical driven piston that can be used to move basic blocks and crush ores
|
||||
|
@ -32,6 +30,8 @@ object TileMechanicalPiston
|
|||
|
||||
class TileMechanicalPiston extends TileMechanical(Material.piston)
|
||||
{
|
||||
var markRevolve: Boolean = false
|
||||
|
||||
//Constructor
|
||||
mechanicalNode = new NodeMechanicalPiston(this)
|
||||
isOpaqueCube(false)
|
||||
|
@ -176,14 +176,14 @@ class TileMechanicalPiston extends TileMechanical(Material.piston)
|
|||
def notifyChanges(pos: Vector3)
|
||||
{
|
||||
worldObj.notifyBlocksOfNeighborChange(pos.xi, pos.yi, pos.zi, pos.getBlock(worldObj))
|
||||
val newTile: TileEntity = pos.getTileEntity(worldObj)
|
||||
/* val newTile: TileEntity = pos.getTileEntity(worldObj)
|
||||
if (newTile != null)
|
||||
{
|
||||
if (Loader.isModLoaded("BuildCraft|Factory"))
|
||||
{
|
||||
try
|
||||
{
|
||||
val clazz: Class[_] = Class.forName("buildcraft.factory.TileQuarry")
|
||||
val clazz: Class[_ <: Any] = Class.forName("buildcraft.factory.TileQuarry")
|
||||
if (newTile == clazz)
|
||||
{
|
||||
ReflectionHelper.setPrivateValue(clazz, newTile, true, "isAlive")
|
||||
|
@ -197,8 +197,6 @@ class TileMechanicalPiston extends TileMechanical(Material.piston)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
protected var markRevolve: Boolean = false
|
||||
}
|
Loading…
Reference in a new issue