use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class KineticEffectHandler method spawnRotationIndicators.
public void spawnRotationIndicators() {
float speed = kte.getSpeed();
if (speed == 0)
return;
BlockState state = kte.getBlockState();
Block block = state.getBlock();
if (!(block instanceof KineticBlock))
return;
KineticBlock kb = (KineticBlock) block;
float radius1 = kb.getParticleInitialRadius();
float radius2 = kb.getParticleTargetRadius();
Axis axis = kb.getRotationAxis(state);
BlockPos pos = kte.getBlockPos();
Level world = kte.getLevel();
if (axis == null)
return;
if (world == null)
return;
char axisChar = axis.name().charAt(0);
Vec3 vec = VecHelper.getCenterOf(pos);
SpeedLevel speedLevel = SpeedLevel.of(speed);
int color = speedLevel.getColor();
int particleSpeed = speedLevel.getParticleSpeed();
particleSpeed *= Math.signum(speed);
if (world instanceof ServerLevel) {
AllTriggers.triggerForNearbyPlayers(AllTriggers.ROTATION, world, pos, 5);
RotationIndicatorParticleData particleData = new RotationIndicatorParticleData(color, particleSpeed, radius1, radius2, 10, axisChar);
((ServerLevel) world).sendParticles(particleData, vec.x, vec.y, vec.z, 20, 0, 0, 0, 1);
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class KineticTileEntity method addPropagationLocations.
/**
* Specify additional locations the rotation propagator should look for
* potentially connected components. Neighbour list contains offset positions in
* all 6 directions by default.
*
* @param block
* @param state
* @param neighbours
* @return
*/
public List<BlockPos> addPropagationLocations(IRotate block, BlockState state, List<BlockPos> neighbours) {
if (!canPropagateDiagonally(block, state))
return neighbours;
Axis axis = block.getRotationAxis(state);
BlockPos.betweenClosedStream(new BlockPos(-1, -1, -1), new BlockPos(1, 1, 1)).forEach(offset -> {
if (axis.choose(offset.getX(), offset.getY(), offset.getZ()) != 0)
return;
if (offset.distSqr(0, 0, 0, false) != BlockPos.ZERO.distSqr(1, 1, 0, false))
return;
neighbours.add(worldPosition.offset(offset));
});
return neighbours;
}
use of net.minecraft.core.Direction.Axis 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;
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class RotationPropagator method isLargeToLargeGear.
private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
if (!ICogWheel.isLargeCog(from) || !ICogWheel.isLargeCog(to))
return false;
Axis fromAxis = from.getValue(AXIS);
Axis toAxis = to.getValue(AXIS);
if (fromAxis == toAxis)
return false;
for (Axis axis : Axis.values()) {
int axisDiff = axis.choose(diff.getX(), diff.getY(), diff.getZ());
if (axis == fromAxis || axis == toAxis) {
if (axisDiff == 0)
return false;
} else if (axisDiff != 0)
return false;
}
return true;
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BrassTunnelTileEntity method getAdjacent.
@Nullable
protected BrassTunnelTileEntity getAdjacent(boolean leftSide) {
if (!hasLevel())
return null;
BlockState blockState = getBlockState();
if (!AllBlocks.BRASS_TUNNEL.has(blockState))
return null;
Axis axis = blockState.getValue(BrassTunnelBlock.HORIZONTAL_AXIS);
Direction baseDirection = Direction.get(AxisDirection.POSITIVE, axis);
Direction direction = leftSide ? baseDirection.getCounterClockWise() : baseDirection.getClockWise();
BlockPos adjacentPos = worldPosition.relative(direction);
BlockState adjacentBlockState = level.getBlockState(adjacentPos);
if (!AllBlocks.BRASS_TUNNEL.has(adjacentBlockState))
return null;
if (adjacentBlockState.getValue(BrassTunnelBlock.HORIZONTAL_AXIS) != axis)
return null;
BlockEntity adjacentTE = level.getBlockEntity(adjacentPos);
if (adjacentTE.isRemoved())
return null;
if (!(adjacentTE instanceof BrassTunnelTileEntity))
return null;
return (BrassTunnelTileEntity) adjacentTE;
}
Aggregations