use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BracketedKineticTileRenderer method renderSafe.
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (Backend.canUseInstancing(te.getLevel()))
return;
if (!AllBlocks.LARGE_COGWHEEL.has(te.getBlockState())) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
return;
}
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
Axis axis = getRotationAxisOf(te);
BlockPos pos = te.getBlockPos();
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
renderRotatingBuffer(te, CachedBufferer.partialFacingVertical(AllBlockPartials.SHAFTLESS_LARGE_COGWHEEL, te.getBlockState(), facing), ms, buffer.getBuffer(RenderType.solid()), light);
float offset = getShaftAngleOffset(axis, pos);
float time = AnimationTickHolder.getRenderTime(te.getLevel());
float angle = ((time * te.getSpeed() * 3f / 10 + offset) % 360) / 180 * (float) Math.PI;
SuperByteBuffer shaft = CachedBufferer.partialFacingVertical(AllBlockPartials.COGWHEEL_SHAFT, te.getBlockState(), facing);
kineticRotationTransform(shaft, te, axis, angle, light);
shaft.renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BeltConnectorHandler method tick.
public static void tick() {
Player player = Minecraft.getInstance().player;
Level world = Minecraft.getInstance().level;
if (player == null || world == null)
return;
if (Minecraft.getInstance().screen != null)
return;
for (InteractionHand hand : InteractionHand.values()) {
ItemStack heldItem = player.getItemInHand(hand);
if (!AllItems.BELT_CONNECTOR.isIn(heldItem))
continue;
if (!heldItem.hasTag())
continue;
CompoundTag tag = heldItem.getTag();
if (!tag.contains("FirstPulley"))
continue;
BlockPos first = NbtUtils.readBlockPos(tag.getCompound("FirstPulley"));
if (!world.getBlockState(first).hasProperty(BlockStateProperties.AXIS))
continue;
Axis axis = world.getBlockState(first).getValue(BlockStateProperties.AXIS);
HitResult rayTrace = Minecraft.getInstance().hitResult;
if (rayTrace == null || !(rayTrace instanceof BlockHitResult)) {
if (r.nextInt(50) == 0) {
world.addParticle(new DustParticleOptions(new Vector3f(.3f, .9f, .5f), 1), first.getX() + .5f + randomOffset(.25f), first.getY() + .5f + randomOffset(.25f), first.getZ() + .5f + randomOffset(.25f), 0, 0, 0);
}
return;
}
BlockPos selected = ((BlockHitResult) rayTrace).getBlockPos();
if (world.getBlockState(selected).getMaterial().isReplaceable())
return;
if (!ShaftBlock.isShaft(world.getBlockState(selected)))
selected = selected.relative(((BlockHitResult) rayTrace).getDirection());
if (!selected.closerThan(first, AllConfigs.SERVER.kinetics.maxBeltLength.get()))
return;
boolean canConnect = BeltConnectorItem.validateAxis(world, selected) && BeltConnectorItem.canConnect(world, first, selected);
Vec3 start = Vec3.atLowerCornerOf(first);
Vec3 end = Vec3.atLowerCornerOf(selected);
Vec3 actualDiff = end.subtract(start);
end = end.subtract(axis.choose(actualDiff.x, 0, 0), axis.choose(0, actualDiff.y, 0), axis.choose(0, 0, actualDiff.z));
Vec3 diff = end.subtract(start);
double x = Math.abs(diff.x);
double y = Math.abs(diff.y);
double z = Math.abs(diff.z);
float length = (float) Math.max(x, Math.max(y, z));
Vec3 step = diff.normalize();
int sames = ((x == y) ? 1 : 0) + ((y == z) ? 1 : 0) + ((z == x) ? 1 : 0);
if (sames == 0) {
List<Vec3> validDiffs = new LinkedList<>();
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) for (int k = -1; k <= 1; k++) {
if (axis.choose(i, j, k) != 0)
continue;
if (axis == Axis.Y && i != 0 && k != 0)
continue;
if (i == 0 && j == 0 && k == 0)
continue;
validDiffs.add(new Vec3(i, j, k));
}
int closestIndex = 0;
float closest = Float.MAX_VALUE;
for (Vec3 validDiff : validDiffs) {
double distanceTo = step.distanceTo(validDiff);
if (distanceTo < closest) {
closest = (float) distanceTo;
closestIndex = validDiffs.indexOf(validDiff);
}
}
step = validDiffs.get(closestIndex);
}
if (axis == Axis.Y && step.x != 0 && step.z != 0)
return;
step = new Vec3(Math.signum(step.x), Math.signum(step.y), Math.signum(step.z));
for (float f = 0; f < length; f += .0625f) {
Vec3 position = start.add(step.scale(f));
if (r.nextInt(10) == 0) {
world.addParticle(new DustParticleOptions(new Vector3f(canConnect ? .3f : .9f, canConnect ? .9f : .3f, .5f), 1), position.x + .5f, position.y + .5f, position.z + .5f, 0, 0, 0);
}
}
return;
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BeltConnectorItem method getFacingFromTo.
private static Direction getFacingFromTo(BlockPos start, BlockPos end) {
Axis beltAxis = start.getX() == end.getX() ? Axis.Z : Axis.X;
BlockPos diff = end.subtract(start);
AxisDirection axisDirection = AxisDirection.POSITIVE;
if (diff.getX() == 0 && diff.getZ() == 0)
axisDirection = diff.getY() > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE;
else
axisDirection = beltAxis.choose(diff.getX(), 0, diff.getZ()) > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE;
return Direction.get(axisDirection, beltAxis);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class PaletteBlockPattern method pillar.
public IBlockStateProvider pillar(String variant) {
ResourceLocation side = toLocation(variant, textures[0]);
ResourceLocation end = toLocation(variant, textures[1]);
return (ctx, prov) -> prov.getVariantBuilder(ctx.getEntry()).forAllStatesExcept(state -> {
Axis axis = state.getValue(BlockStateProperties.AXIS);
if (axis == Axis.Y)
return ConfiguredModel.builder().modelFile(prov.models().cubeColumn(createName(variant), side, end)).uvLock(false).build();
return ConfiguredModel.builder().modelFile(prov.models().cubeColumnHorizontal(createName(variant) + "_horizontal", side, end)).uvLock(false).rotationX(90).rotationY(axis == Axis.X ? 90 : 0).build();
}, BlockStateProperties.WATERLOGGED, ConnectedPillarBlock.NORTH, ConnectedPillarBlock.SOUTH, ConnectedPillarBlock.EAST, ConnectedPillarBlock.WEST);
}
use of net.minecraft.core.Direction.Axis in project Cyclic by Lothrazar.
the class UtilPlaceBlocks method rotateBlockValidState.
public static boolean rotateBlockValidState(Level world, BlockPos pos, Direction side) {
BlockState clicked = world.getBlockState(pos);
if (clicked.getBlock() == null) {
return false;
}
Block clickedBlock = clicked.getBlock();
BlockState newState = null;
if (clicked.is(BlockTags.SLABS)) {
// top or bottom
final String key = "type";
// actually theres 3 but dont worry about it
final String valueDupe = "double";
// clicked.get(property)
for (Property<?> prop : clicked.getProperties()) {
// yes
if (prop.getName().equals(key)) {
// then cycle me
// cycle
newState = clicked.cycle(prop);
if (newState.getValue(prop).toString().equals(valueDupe)) {
// haha just hack and skip. turns into length 2. dont worry about it
newState = newState.cycle(prop);
}
}
}
} else if (clicked.hasProperty(RotatedPillarBlock.AXIS)) {
// axis
Axis current = clicked.getValue(RotatedPillarBlock.AXIS);
switch(current) {
case X:
newState = clicked.setValue(RotatedPillarBlock.AXIS, Axis.Y);
break;
case Y:
newState = clicked.setValue(RotatedPillarBlock.AXIS, Axis.Z);
break;
case Z:
newState = clicked.setValue(RotatedPillarBlock.AXIS, Axis.X);
break;
default:
break;
}
// clicked.rot
} else {
// default whatever
switch(side) {
case DOWN:
newState = clicked.rotate(world, pos, Rotation.CLOCKWISE_180);
break;
case UP:
newState = clicked.rotate(world, pos, Rotation.CLOCKWISE_180);
break;
case EAST:
newState = clicked.rotate(world, pos, Rotation.CLOCKWISE_90);
break;
case NORTH:
newState = clicked.rotate(world, pos, Rotation.COUNTERCLOCKWISE_90);
break;
case SOUTH:
newState = clicked.rotate(world, pos, Rotation.CLOCKWISE_90);
break;
case WEST:
newState = clicked.rotate(world, pos, Rotation.COUNTERCLOCKWISE_90);
break;
default:
break;
}
}
boolean win = false;
if (newState != null) {
win = world.setBlockAndUpdate(pos, newState);
}
if (!win) {
ModCyclic.LOGGER.error("Could not rotate " + clickedBlock);
}
return win;
}
Aggregations