use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BlueprintEntity method recalculateBoundingBox.
@Override
protected void recalculateBoundingBox() {
if (this.direction == null)
return;
if (this.verticalOrientation == null)
return;
Vec3 pos = Vec3.atLowerCornerOf(getPos()).add(.5, .5, .5).subtract(Vec3.atLowerCornerOf(direction.getNormal()).scale(0.46875));
double d1 = pos.x;
double d2 = pos.y;
double d3 = pos.z;
this.setPosRaw(d1, d2, d3);
Axis axis = direction.getAxis();
if (size == 2)
pos = pos.add(Vec3.atLowerCornerOf(axis.isHorizontal() ? direction.getCounterClockWise().getNormal() : verticalOrientation.getClockWise().getNormal()).scale(0.5)).add(Vec3.atLowerCornerOf(axis.isHorizontal() ? Direction.UP.getNormal() : direction == Direction.UP ? verticalOrientation.getNormal() : verticalOrientation.getOpposite().getNormal()).scale(0.5));
d1 = pos.x;
d2 = pos.y;
d3 = pos.z;
double d4 = (double) this.getWidth();
double d5 = (double) this.getHeight();
double d6 = (double) this.getWidth();
Direction.Axis direction$axis = this.direction.getAxis();
switch(direction$axis) {
case X:
d4 = 1.0D;
break;
case Y:
d5 = 1.0D;
break;
case Z:
d6 = 1.0D;
}
d4 = d4 / 32.0D;
d5 = d5 / 32.0D;
d6 = d6 / 32.0D;
this.setBoundingBox(new AABB(d1 - d4, d2 - d5, d3 - d6, d1 + d4, d2 + d5, d3 + d6));
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class Outline method renderAACuboidLine.
public void renderAACuboidLine(PoseStack ms, SuperRenderTypeBuffer buffer, Vec3 start, Vec3 end) {
float lineWidth = params.getLineWidth();
if (lineWidth == 0)
return;
VertexConsumer builder = buffer.getBuffer(RenderTypes.getOutlineSolid());
Vec3 diff = end.subtract(start);
if (diff.x + diff.y + diff.z < 0) {
Vec3 temp = start;
start = end;
end = temp;
diff = diff.scale(-1);
}
Vec3 extension = diff.normalize().scale(lineWidth / 2);
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
Direction face = Direction.getNearest(diff.x, diff.y, diff.z);
Axis axis = face.getAxis();
start = start.subtract(extension);
end = end.add(extension);
plane = plane.scale(lineWidth / 2);
Vec3 a1 = plane.add(start);
Vec3 b1 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a2 = plane.add(start);
Vec3 b2 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a3 = plane.add(start);
Vec3 b3 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a4 = plane.add(start);
Vec3 b4 = plane.add(end);
if (params.disableNormals) {
face = Direction.UP;
putQuad(ms, builder, b4, b3, b2, b1, face);
putQuad(ms, builder, a1, a2, a3, a4, face);
putQuad(ms, builder, a1, b1, b2, a2, face);
putQuad(ms, builder, a2, b2, b3, a3, face);
putQuad(ms, builder, a3, b3, b4, a4, face);
putQuad(ms, builder, a4, b4, b1, a1, face);
return;
}
putQuad(ms, builder, b4, b3, b2, b1, face);
putQuad(ms, builder, a1, a2, a3, a4, face.getOpposite());
Vec3 vec = a1.subtract(a4);
face = Direction.getNearest(vec.x, vec.y, vec.z);
putQuad(ms, builder, a1, b1, b2, a2, face);
vec = VecHelper.rotate(vec, -90, axis);
face = Direction.getNearest(vec.x, vec.y, vec.z);
putQuad(ms, builder, a2, b2, b3, a3, face);
vec = VecHelper.rotate(vec, -90, axis);
face = Direction.getNearest(vec.x, vec.y, vec.z);
putQuad(ms, builder, a3, b3, b4, a4, face);
vec = VecHelper.rotate(vec, -90, axis);
face = Direction.getNearest(vec.x, vec.y, vec.z);
putQuad(ms, builder, a4, b4, b1, a1, face);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BeltMovementHandler method transportEntity.
public static void transportEntity(BeltTileEntity beltTe, Entity entityIn, TransportedEntityInfo info) {
BlockPos pos = info.lastCollidedPos;
Level world = beltTe.getLevel();
BlockEntity te = world.getBlockEntity(pos);
BlockEntity tileEntityBelowPassenger = world.getBlockEntity(entityIn.blockPosition());
BlockState blockState = info.lastCollidedState;
Direction movementFacing = Direction.fromAxisAndDirection(blockState.getValue(BlockStateProperties.HORIZONTAL_FACING).getAxis(), beltTe.getSpeed() < 0 ? POSITIVE : NEGATIVE);
boolean collidedWithBelt = te instanceof BeltTileEntity;
boolean betweenBelts = tileEntityBelowPassenger instanceof BeltTileEntity && tileEntityBelowPassenger != te;
// Don't fight other Belts
if (!collidedWithBelt || betweenBelts) {
return;
}
// Too slow
boolean notHorizontal = beltTe.getBlockState().getValue(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL;
if (Math.abs(beltTe.getSpeed()) < 1)
return;
// Not on top
if (entityIn.getY() - .25f < pos.getY())
return;
// Lock entities in place
boolean isPlayer = entityIn instanceof Player;
if (entityIn instanceof LivingEntity && !isPlayer)
((LivingEntity) entityIn).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 1, false, false));
final Direction beltFacing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING);
final BeltSlope slope = blockState.getValue(BeltBlock.SLOPE);
final Axis axis = beltFacing.getAxis();
float movementSpeed = beltTe.getBeltMovementSpeed();
final Direction movementDirection = Direction.get(axis == Axis.X ? NEGATIVE : POSITIVE, axis);
Vec3i centeringDirection = Direction.get(POSITIVE, beltFacing.getClockWise().getAxis()).getNormal();
Vec3 movement = Vec3.atLowerCornerOf(movementDirection.getNormal()).scale(movementSpeed);
double diffCenter = axis == Axis.Z ? (pos.getX() + .5f - entityIn.getX()) : (pos.getZ() + .5f - entityIn.getZ());
if (Math.abs(diffCenter) > 48 / 64f)
return;
BeltPart part = blockState.getValue(BeltBlock.PART);
float top = 13 / 16f;
boolean onSlope = notHorizontal && (part == BeltPart.MIDDLE || part == BeltPart.PULLEY || part == (slope == BeltSlope.UPWARD ? BeltPart.END : BeltPart.START) && entityIn.getY() - pos.getY() < top || part == (slope == BeltSlope.UPWARD ? BeltPart.START : BeltPart.END) && entityIn.getY() - pos.getY() > top);
boolean movingDown = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.DOWNWARD : BeltSlope.UPWARD);
boolean movingUp = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.UPWARD : BeltSlope.DOWNWARD);
if (beltFacing.getAxis() == Axis.Z) {
boolean b = movingDown;
movingDown = movingUp;
movingUp = b;
}
if (movingUp)
movement = movement.add(0, Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
if (movingDown)
movement = movement.add(0, -Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
Vec3 centering = Vec3.atLowerCornerOf(centeringDirection).scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4);
if (!(entityIn instanceof LivingEntity) || ((LivingEntity) entityIn).zza == 0 && ((LivingEntity) entityIn).xxa == 0)
movement = movement.add(centering);
float step = entityIn.maxUpStep;
if (!isPlayer)
entityIn.maxUpStep = 1;
// Entity Collisions
if (Math.abs(movementSpeed) < .5f) {
Vec3 checkDistance = movement.normalize().scale(0.5);
AABB bb = entityIn.getBoundingBox();
AABB checkBB = new AABB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
checkBB = checkBB.move(checkDistance).inflate(-Math.abs(checkDistance.x), -Math.abs(checkDistance.y), -Math.abs(checkDistance.z));
List<Entity> list = world.getEntities(entityIn, checkBB);
list.removeIf(e -> shouldIgnoreBlocking(entityIn, e));
if (!list.isEmpty()) {
entityIn.setDeltaMovement(0, 0, 0);
info.ticksSinceLastCollision--;
return;
}
}
entityIn.fallDistance = 0;
if (movingUp) {
float minVelocity = .13f;
float yMovement = (float) -(Math.max(Math.abs(movement.y), minVelocity));
entityIn.move(SELF, new Vec3(0, yMovement, 0));
entityIn.move(SELF, movement.multiply(1, 0, 1));
} else if (movingDown) {
entityIn.move(SELF, movement.multiply(1, 0, 1));
entityIn.move(SELF, movement.multiply(0, 1, 0));
} else {
entityIn.move(SELF, movement);
}
entityIn.setOnGround(true);
if (!isPlayer)
entityIn.maxUpStep = step;
boolean movedPastEndingSlope = onSlope && (AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition())) || AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition().below())));
if (movedPastEndingSlope && !movingDown && Math.abs(movementSpeed) > 0)
entityIn.setPos(entityIn.getX(), entityIn.getY() + movement.y, entityIn.getZ());
if (movedPastEndingSlope) {
entityIn.setDeltaMovement(movement);
entityIn.hurtMarked = true;
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BracketedKineticTileInstance method getModel.
@Override
protected Instancer<RotatingData> getModel() {
if (!ICogWheel.isLargeCog(blockEntity.getBlockState()))
return super.getModel();
Axis axis = KineticTileEntityRenderer.getRotationAxisOf(blockEntity);
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
return getRotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_LARGE_COGWHEEL, blockState, facing, () -> this.rotateToAxis(axis));
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BracketedKineticTileInstance method init.
@Override
public void init() {
super.init();
if (!ICogWheel.isLargeCog(blockEntity.getBlockState()))
return;
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
float speed = blockEntity.getSpeed();
Axis axis = KineticTileEntityRenderer.getRotationAxisOf(blockEntity);
BlockPos pos = blockEntity.getBlockPos();
float offset = BracketedKineticTileRenderer.getShaftAngleOffset(axis, pos);
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
Instancer<RotatingData> half = getRotatingMaterial().getModel(AllBlockPartials.COGWHEEL_SHAFT, blockState, facing, () -> this.rotateToAxis(axis));
additionalShaft = setup(half.createInstance(), speed);
additionalShaft.setRotationOffset(offset);
}
Aggregations