Search in sources :

Example 21 with Direction

use of net.minecraft.util.math.Direction in project fabric by FabricMC.

the class ModelHelper method toQuadLists.

/**
 * Converts a mesh into an array of lists of vanilla baked quads.
 * Useful for creating vanilla baked models when required for compatibility.
 * The array indexes correspond to {@link Direction#getId()} with the
 * addition of {@link #NULL_FACE_ID}.<p>
 *
 * Retrieves sprites from the block texture atlas via {@link SpriteFinder}.
 */
public static List<BakedQuad>[] toQuadLists(Mesh mesh) {
    SpriteFinder finder = SpriteFinder.get(MinecraftClient.getInstance().getSpriteAtlas());
    @SuppressWarnings("unchecked") final ImmutableList.Builder<BakedQuad>[] builders = new ImmutableList.Builder[7];
    for (int i = 0; i < 7; i++) {
        builders[i] = ImmutableList.builder();
    }
    mesh.forEach(q -> {
        final int limit = q.material().spriteDepth();
        for (int l = 0; l < limit; l++) {
            Direction face = q.cullFace();
            builders[face == null ? 6 : face.getId()].add(q.toBakedQuad(l, finder.find(q, l), false));
        }
    });
    @SuppressWarnings("unchecked") List<BakedQuad>[] result = new List[7];
    for (int i = 0; i < 7; i++) {
        result[i] = builders[i].build();
    }
    return result;
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Direction(net.minecraft.util.math.Direction)

Example 22 with Direction

use of net.minecraft.util.math.Direction in project Liminal-Library by LudoCrypt.

the class NbtPlacerUtil method spawnEntities.

public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos pos, BlockRotation rotation) {
    this.entities.forEach((nbtElement) -> {
        NbtCompound entityCompound = (NbtCompound) nbtElement;
        NbtList nbtPos = entityCompound.getList("blockPos", 3);
        Vec3d realPosition = rotate(new Vec3d(nbtPos.getInt(0), nbtPos.getInt(1), nbtPos.getInt(2)), rotation).subtract(Vec3d.of(lowestPos)).add(pos.getX(), pos.getY(), pos.getZ());
        NbtCompound nbt = entityCompound.getCompound("nbt").copy();
        nbt.remove("Pos");
        nbt.remove("UUID");
        NbtList posList = new NbtList();
        posList.add(NbtDouble.of(realPosition.x));
        posList.add(NbtDouble.of(realPosition.y));
        posList.add(NbtDouble.of(realPosition.z));
        nbt.put("Pos", posList);
        NbtList rotationList = new NbtList();
        NbtList entityRotationList = nbt.getList("Rotation", 5);
        float yawRotation = applyRotation(entityRotationList.getFloat(0), rotation);
        rotationList.add(NbtFloat.of(yawRotation));
        rotationList.add(NbtFloat.of(entityRotationList.getFloat(1)));
        nbt.remove("Rotation");
        nbt.put("Rotation", rotationList);
        if (nbt.contains("Facing")) {
            Direction dir = rotation.rotate(Direction.fromHorizontal(nbt.getByte("Facing")));
            nbt.remove("Facing");
            nbt.putByte("Facing", (byte) dir.getHorizontal());
        }
        getEntity(region, nbt).ifPresent((entity) -> {
            entity.refreshPositionAndAngles(realPosition.x, realPosition.y, realPosition.z, yawRotation, entity.getPitch());
            region.spawnEntity(entity);
        });
    });
    return this;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 23 with Direction

use of net.minecraft.util.math.Direction in project frame-fabric by moddingplayground.

the class InteractiveBlocks method fenceGate.

public static StateGen fenceGate(Identifier name, Identifier texName) {
    VariantsStateGen gen = VariantsStateGen.variants();
    ModelGen[] gens = { InheritingModelGen.fenceGate(texName, false), InheritingModelGen.fenceGate(texName, true), InheritingModelGen.fenceGateWall(texName, false), InheritingModelGen.fenceGateWall(texName, true) };
    String[] names = { name.toString(), name + "_open", name + "_wall", name + "_wall_open" };
    for (Direction facing : Direction.Type.HORIZONTAL) {
        int baseRot = 0;
        if (facing == Direction.WEST)
            baseRot = 90;
        if (facing == Direction.NORTH)
            baseRot = 180;
        if (facing == Direction.EAST)
            baseRot = 270;
        for (int i = 0; i < 4; i++) {
            boolean open = (i & 1) != 0;
            boolean inWall = (i & 2) != 0;
            String variant = "facing=" + facing.asString() + "," + "in_wall=" + inWall + "," + "open=" + open;
            ModelGen modelGen = gens[i];
            gens[i] = null;
            gen.variant(variant, StateModelInfo.create(Identifier.tryParse(names[i]), modelGen).rotate(0, baseRot).uvlock(true));
        }
    }
    return gen;
}
Also used : InheritingModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.InheritingModelGen) ModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.ModelGen) Direction(net.minecraft.util.math.Direction)

Example 24 with Direction

use of net.minecraft.util.math.Direction in project frame-fabric by moddingplayground.

the class InteractiveBlocks method button.

public static StateGen button(Identifier name, Identifier texName) {
    VariantsStateGen gen = VariantsStateGen.variants();
    ModelGen[] gens = { InheritingModelGen.button(texName, false), InheritingModelGen.button(texName, true) };
    String[] names = { name.toString(), name + "_pressed" };
    for (Direction facing : Direction.Type.HORIZONTAL) {
        for (WallMountLocation face : WallMountLocation.values()) {
            int yr = 0;
            int xr = 0;
            if (face == WallMountLocation.CEILING) {
                xr = 180;
                if (facing == Direction.WEST)
                    yr = 90;
                if (facing == Direction.NORTH)
                    yr = 180;
                if (facing == Direction.EAST)
                    yr = 270;
            } else {
                if (face == WallMountLocation.WALL)
                    xr = 90;
                if (facing == Direction.EAST)
                    yr = 90;
                if (facing == Direction.SOUTH)
                    yr = 180;
                if (facing == Direction.WEST)
                    yr = 270;
            }
            for (int i = 0; i < 2; i++) {
                boolean powered = (i & 1) != 0;
                String variant = "face=" + face.asString() + "," + "facing=" + facing.asString() + "," + "powered=" + powered;
                ModelGen modelGen = gens[i];
                gens[i] = null;
                gen.variant(variant, StateModelInfo.create(Identifier.tryParse(names[i]), modelGen).rotate(xr, yr).uvlock(xr == 90));
            }
        }
    }
    return gen;
}
Also used : InheritingModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.InheritingModelGen) ModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.ModelGen) WallMountLocation(net.minecraft.block.enums.WallMountLocation) Direction(net.minecraft.util.math.Direction)

Example 25 with Direction

use of net.minecraft.util.math.Direction in project frame-fabric by moddingplayground.

the class InteractiveBlocks method trapdoor.

@SuppressWarnings("ConstantConditions")
public static StateGen trapdoor(Identifier name) {
    VariantsStateGen gen = VariantsStateGen.variants();
    ModelGen[] gens = { InheritingModelGen.trapdoorOpen(name), InheritingModelGen.trapdoorTop(name), InheritingModelGen.trapdoorBottom(name) };
    String[] names = { name + "_open", name + "_top", name + "_bottom" };
    for (Direction facing : Direction.Type.HORIZONTAL) {
        int baseRot = 0;
        if (facing == Direction.EAST)
            baseRot = 90;
        if (facing == Direction.SOUTH)
            baseRot = 180;
        if (facing == Direction.WEST)
            baseRot = 270;
        for (BlockHalf half : BlockHalf.values()) {
            for (int i = 0; i < 2; i++) {
                boolean open = (i & 1) == 0;
                boolean top = half == BlockHalf.TOP;
                int xr = open && top ? 180 : 0;
                int yr = open && top ? 180 : 0;
                yr = (baseRot + yr) % 360;
                if (yr < 0)
                    yr += 360;
                String variant = "facing=" + facing.asString() + "," + "half=" + half.asString() + "," + "open=" + open;
                int gi = open ? 0 : top ? 1 : 2;
                ModelGen modelGen = gens[gi];
                gens[gi] = null;
                gen.variant(variant, StateModelInfo.create(Identifier.tryParse(names[gi]), modelGen).rotate(xr, yr));
            }
        }
    }
    return gen;
}
Also used : InheritingModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.InheritingModelGen) ModelGen(net.moddingplayground.frame.api.toymaker.v0.generator.model.ModelGen) Direction(net.minecraft.util.math.Direction) BlockHalf(net.minecraft.block.enums.BlockHalf) DoubleBlockHalf(net.minecraft.block.enums.DoubleBlockHalf)

Aggregations

Direction (net.minecraft.util.math.Direction)184 BlockPos (net.minecraft.util.math.BlockPos)89 BlockState (net.minecraft.block.BlockState)46 Vec3d (net.minecraft.util.math.Vec3d)19 Block (net.minecraft.block.Block)14 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 Box (net.minecraft.util.math.Box)11 VoxelShape (net.minecraft.util.shape.VoxelShape)8 SculkVeinBlock (frozenblock.wild.mod.blocks.SculkVeinBlock)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 ArrayList (java.util.ArrayList)6 World (net.minecraft.world.World)6 Random (java.util.Random)5 Environment (net.fabricmc.api.Environment)5 BakedQuad (net.minecraft.client.render.model.BakedQuad)5 Nullable (org.jetbrains.annotations.Nullable)5 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 EventHandler (meteordevelopment.orbit.EventHandler)4