Search in sources :

Example 36 with Axis

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()));
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 37 with Axis

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;
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) InteractionHand(net.minecraft.world.InteractionHand) LinkedList(java.util.LinkedList) BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) DustParticleOptions(net.minecraft.core.particles.DustParticleOptions) Vector3f(com.mojang.math.Vector3f) Vec3(net.minecraft.world.phys.Vec3) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) CompoundTag(net.minecraft.nbt.CompoundTag) Axis(net.minecraft.core.Direction.Axis)

Example 38 with Axis

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);
}
Also used : AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

Example 39 with Axis

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);
}
Also used : HorizontalCTBehaviour(com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour) ResourceLocation(net.minecraft.resources.ResourceLocation) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) RotatedPillarCTBehaviour(com.simibubi.create.foundation.block.connected.RotatedPillarCTBehaviour) Item(net.minecraft.world.item.Item) CTType(com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Dist(net.minecraftforge.api.distmarker.Dist) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) RegistrateRecipeProvider(com.tterrag.registrate.providers.RegistrateRecipeProvider) Axis(net.minecraft.core.Direction.Axis) NonNullSupplier(com.tterrag.registrate.util.nullness.NonNullSupplier) FOR_POLISHED(com.simibubi.create.content.palettes.PaletteBlockPartial.FOR_POLISHED) Create(com.simibubi.create.Create) WRAP(com.simibubi.create.content.palettes.PaletteBlockPattern.PatternNameType.WRAP) NonNullFunction(com.tterrag.registrate.util.nullness.NonNullFunction) DataGenContext(com.tterrag.registrate.providers.DataGenContext) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) CTSpriteShifter(com.simibubi.create.foundation.block.connected.CTSpriteShifter) SUFFIX(com.simibubi.create.content.palettes.PaletteBlockPattern.PatternNameType.SUFFIX) ALL_PARTIALS(com.simibubi.create.content.palettes.PaletteBlockPartial.ALL_PARTIALS) RenderType(net.minecraft.client.renderer.RenderType) RegistrateBlockstateProvider(com.tterrag.registrate.providers.RegistrateBlockstateProvider) DataIngredient(com.tterrag.registrate.util.DataIngredient) Tag(net.minecraft.tags.Tag) PREFIX(com.simibubi.create.content.palettes.PaletteBlockPattern.PatternNameType.PREFIX) ConnectedTextureBehaviour(com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour) CTSpriteShiftEntry(com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry) NonNullBiConsumer(com.tterrag.registrate.util.nullness.NonNullBiConsumer) ConfiguredModel(net.minecraftforge.client.model.generators.ConfiguredModel) Optional(java.util.Optional) Block(net.minecraft.world.level.block.Block) ResourceLocation(net.minecraft.resources.ResourceLocation) Axis(net.minecraft.core.Direction.Axis)

Example 40 with Axis

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;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) RotatedPillarBlock(net.minecraft.world.level.block.RotatedPillarBlock) Axis(net.minecraft.core.Direction.Axis)

Aggregations

Axis (net.minecraft.core.Direction.Axis)85 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)35 AxisDirection (net.minecraft.core.Direction.AxisDirection)24 Vec3 (net.minecraft.world.phys.Vec3)14 Level (net.minecraft.world.level.Level)13 IRotate (com.simibubi.create.content.contraptions.base.IRotate)9 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)7 Block (net.minecraft.world.level.block.Block)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)6 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)5 Player (net.minecraft.world.entity.player.Player)5 HashSet (java.util.HashSet)4 ItemStack (net.minecraft.world.item.ItemStack)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 Part (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part)3 ArrayList (java.util.ArrayList)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)3