use of com.simibubi.create.content.contraptions.base.IRotate in project Create_Aeronautics by Eriksonnaren.
the class RotationPropagatorMixin method getRotationSpeedModifier.
private static float getRotationSpeedModifier(KineticTileEntity from, KineticTileEntity to) {
BlockState stateFrom = from.getBlockState();
BlockState stateTo = to.getBlockState();
Block fromBlock = stateFrom.getBlock();
Block toBlock = stateTo.getBlock();
if (fromBlock instanceof IRotate && toBlock instanceof IRotate) {
IRotate definitionFrom = (IRotate) fromBlock;
IRotate definitionTo = (IRotate) toBlock;
BlockPos diff = to.getBlockPos().subtract(from.getBlockPos());
Direction direction = Direction.getNearest((float) diff.getX(), (float) diff.getY(), (float) diff.getZ());
World world = from.getLevel();
boolean alignedAxes = true;
Axis[] var12 = Axis.values();
int var13 = var12.length;
Axis sourceAxis;
for (int var14 = 0; var14 < var13; ++var14) {
sourceAxis = var12[var14];
if (sourceAxis != direction.getAxis() && sourceAxis.choose(diff.getX(), diff.getY(), diff.getZ()) != 0) {
alignedAxes = false;
}
}
boolean connectedByAxis = alignedAxes && definitionFrom.hasShaftTowards(world, from.getBlockPos(), stateFrom, direction) && definitionTo.hasShaftTowards(world, to.getBlockPos(), stateTo, direction.getOpposite());
boolean connectedByGears = ICogWheel.isSmallCog(stateFrom) && ICogWheel.isSmallCog(stateTo);
float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears);
if (custom != 0.0F) {
return custom;
} else if (connectedByAxis) {
float axisModifier = getAxisModifier(to, direction.getOpposite());
if (axisModifier != 0.0F) {
axisModifier = 1.0F / axisModifier;
}
return getAxisModifier(from, direction) * axisModifier;
} else if (fromBlock instanceof EncasedBeltBlock && toBlock instanceof EncasedBeltBlock) {
boolean connected = EncasedBeltBlock.areBlocksConnected(stateFrom, stateTo, direction);
return connected ? EncasedBeltBlock.getRotationSpeedModifier(from, to) : 0.0F;
} else if (isLargeToLargeGear(stateFrom, stateTo, diff)) {
sourceAxis = (Axis) stateFrom.getValue(BlockStateProperties.AXIS);
Axis targetAxis = (Axis) stateTo.getValue(BlockStateProperties.AXIS);
int sourceAxisDiff = sourceAxis.choose(diff.getX(), diff.getY(), diff.getZ());
int targetAxisDiff = targetAxis.choose(diff.getX(), diff.getY(), diff.getZ());
return sourceAxisDiff > 0 ^ targetAxisDiff > 0 ? -1.0F : 1.0F;
} else if (ICogWheel.isLargeCog(stateFrom) && ICogWheel.isSmallCog(stateTo) && isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff)) {
return -2.0F;
} else if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom) && isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff)) {
return -0.5F;
} else {
if (connectedByGears) {
if (diff.distManhattan(BlockPos.ZERO) != 1) {
return 0.0F;
}
if (ICogWheel.isLargeCog(stateTo)) {
return 0.0F;
}
if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom)) {
return 0.0F;
}
if (definitionFrom.getRotationAxis(stateFrom) == definitionTo.getRotationAxis(stateTo)) {
return -1.0F;
}
}
return 0.0F;
}
} else {
return 0.0F;
}
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create_Aeronautics by Eriksonnaren.
the class RotationPropagatorMixin method getPotentialNeighbourLocations.
private static List<BlockPos> getPotentialNeighbourLocations(KineticTileEntity te) {
List<BlockPos> neighbours = new LinkedList();
if (!te.getLevel().isAreaLoaded(te.getBlockPos(), 1)) {
return neighbours;
} else {
Direction[] var2 = Iterate.directions;
int var3 = var2.length;
for (int var4 = 0; var4 < var3; ++var4) {
Direction facing = var2[var4];
neighbours.add(te.getBlockPos().relative(facing));
}
BlockState blockState = te.getBlockState();
if (!(blockState.getBlock() instanceof IRotate)) {
return neighbours;
} else {
IRotate block = (IRotate) blockState.getBlock();
return te.addPropagationLocations(block, blockState, neighbours);
}
}
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class MechanicalPistonTileEntity method getMovementModeSlot.
@Override
protected ValueBoxTransform getMovementModeSlot() {
return new DirectionalExtenderScrollOptionSlot((state, d) -> {
Axis axis = d.getAxis();
Axis extensionAxis = state.getValue(MechanicalPistonBlock.FACING).getAxis();
Axis shaftAxis = ((IRotate) state.getBlock()).getRotationAxis(state);
return extensionAxis != axis && shaftAxis != axis;
});
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class GantryCarriageBlock method getValidGantryShaftAxis.
public static Axis getValidGantryShaftAxis(BlockState state) {
if (!(state.getBlock() instanceof GantryCarriageBlock))
return Axis.Y;
IRotate block = (IRotate) state.getBlock();
Axis rotationAxis = block.getRotationAxis(state);
Axis facingAxis = state.getValue(FACING).getAxis();
for (Axis axis : Iterate.axes) if (axis != rotationAxis && axis != facingAxis)
return axis;
return Axis.Y;
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class RotationPropagator method getRotationSpeedModifier.
/**
* Determines the change in rotation between two attached kinetic entities. For
* instance, an axis connection returns 1 while a 1-to-1 gear connection
* reverses the rotation and therefore returns -1.
*
* @param from
* @param to
* @return
*/
private static float getRotationSpeedModifier(KineticTileEntity from, KineticTileEntity to) {
final BlockState stateFrom = from.getBlockState();
final BlockState stateTo = to.getBlockState();
Block fromBlock = stateFrom.getBlock();
Block toBlock = stateTo.getBlock();
if (!(fromBlock instanceof IRotate && toBlock instanceof IRotate))
return 0;
final IRotate definitionFrom = (IRotate) fromBlock;
final IRotate definitionTo = (IRotate) toBlock;
final BlockPos diff = to.getBlockPos().subtract(from.getBlockPos());
final Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());
final Level world = from.getLevel();
boolean alignedAxes = true;
for (Axis axis : Axis.values()) if (axis != direction.getAxis())
if (axis.choose(diff.getX(), diff.getY(), diff.getZ()) != 0)
alignedAxes = false;
boolean connectedByAxis = alignedAxes && definitionFrom.hasShaftTowards(world, from.getBlockPos(), stateFrom, direction) && definitionTo.hasShaftTowards(world, to.getBlockPos(), stateTo, direction.getOpposite());
boolean connectedByGears = ICogWheel.isSmallCog(stateFrom) && ICogWheel.isSmallCog(stateTo);
float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears);
if (custom != 0)
return custom;
// Axis <-> Axis
if (connectedByAxis) {
float axisModifier = getAxisModifier(to, direction.getOpposite());
if (axisModifier != 0)
axisModifier = 1 / axisModifier;
return getAxisModifier(from, direction) * axisModifier;
}
// Attached Encased Belts
if (fromBlock instanceof EncasedBeltBlock && toBlock instanceof EncasedBeltBlock) {
boolean connected = EncasedBeltBlock.areBlocksConnected(stateFrom, stateTo, direction);
return connected ? EncasedBeltBlock.getRotationSpeedModifier(from, to) : 0;
}
// Large Gear <-> Large Gear
if (isLargeToLargeGear(stateFrom, stateTo, diff)) {
Axis sourceAxis = stateFrom.getValue(AXIS);
Axis targetAxis = stateTo.getValue(AXIS);
int sourceAxisDiff = sourceAxis.choose(diff.getX(), diff.getY(), diff.getZ());
int targetAxisDiff = targetAxis.choose(diff.getX(), diff.getY(), diff.getZ());
return sourceAxisDiff > 0 ^ targetAxisDiff > 0 ? -1 : 1;
}
// Gear <-> Large Gear
if (ICogWheel.isLargeCog(stateFrom) && ICogWheel.isSmallCog(stateTo))
if (isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff))
return -2f;
if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom))
if (isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff))
return -.5f;
// Gear <-> Gear
if (connectedByGears) {
if (diff.distManhattan(BlockPos.ZERO) != 1)
return 0;
if (ICogWheel.isLargeCog(stateTo))
return 0;
if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom))
return 0;
if (definitionFrom.getRotationAxis(stateFrom) == definitionTo.getRotationAxis(stateTo))
return -1;
}
return 0;
}
Aggregations