Search in sources :

Example 26 with Direction

use of net.minecraft.util.math.Direction in project sodium-fabric by CaffeineMC.

the class ChunkBlockRenderPipeline method renderModel.

public boolean renderModel(BlockRenderView world, BakedModel model, BlockState state, BlockPos pos, Vector3f translation, VertexConsumer builder, boolean cull, Random random, long seed) {
    LightPipeline lighter = this.getLightPipeline(state, model);
    lighter.reset();
    this.cachedColors.clear();
    Vec3d blockOffset = state.getOffsetPos(world, pos);
    translation.add((float) blockOffset.getX(), (float) blockOffset.getY(), (float) blockOffset.getZ());
    boolean rendered = false;
    for (Direction dir : DirectionUtil.ALL_DIRECTIONS) {
        random.setSeed(seed);
        List<BakedQuad> sided = model.getQuads(state, dir, random);
        if (sided.isEmpty()) {
            continue;
        }
        if (!cull || this.occlusionCache.shouldDrawSide(state, world, pos, dir)) {
            this.renderQuadList(world, state, pos, lighter, translation, builder, sided, dir);
            rendered = true;
        }
    }
    random.setSeed(seed);
    List<BakedQuad> all = model.getQuads(state, null, random);
    if (!all.isEmpty()) {
        this.renderQuadList(world, state, pos, lighter, translation, builder, all, null);
        rendered = true;
    }
    return rendered;
}
Also used : BakedQuad(net.minecraft.client.render.model.BakedQuad) FlatLightPipeline(me.jellysquid.mods.sodium.client.render.light.flat.FlatLightPipeline) LightPipeline(me.jellysquid.mods.sodium.client.render.light.LightPipeline) SmoothLightPipeline(me.jellysquid.mods.sodium.client.render.light.smooth.SmoothLightPipeline) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 27 with Direction

use of net.minecraft.util.math.Direction in project sodium-fabric by CaffeineMC.

the class SmoothLightPipeline method apply.

@Override
public void apply(ModelQuadView quad, BlockPos pos, LightResult out) {
    Direction face = quad.getFacing();
    int flags = quad.getFlags();
    final AoNeighborInfo neighborInfo = AoNeighborInfo.get(face);
    if (!ModelQuadFlags.contains(flags, ModelQuadFlags.IS_ALIGNED) || ModelQuadFlags.contains(flags, ModelQuadFlags.IS_PARTIAL)) {
        this.applyComplex(neighborInfo, quad, pos, face, out);
    } else {
        this.applyAlignedFullFace(neighborInfo, pos, face, out);
    }
}
Also used : Direction(net.minecraft.util.math.Direction)

Example 28 with Direction

use of net.minecraft.util.math.Direction in project SeedcrackerX by 19MisterX98.

the class ShipwreckFinder method onChestFound.

/**
 * Source: https://github.com/skyrising/casual-mod/blob/master/src/main/java/de/skyrising/casual/ShipwreckFinder.java
 */
private boolean onChestFound(BlockPos pos) {
    BlockPos.Mutable mutablePos = new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ());
    Direction chestFacing = world.getBlockState(pos).get(ChestBlock.FACING);
    int[] stairs = new int[4];
    int totalStairs = 0;
    int[] trapdoors = new int[4];
    int totalTrapdoors = 0;
    for (int y = -1; y <= 2; y++) {
        for (int x = -1; x <= 1; x++) {
            for (int z = -1; z <= 1; z++) {
                if (x == 0 && y == 0 && z == 0)
                    continue;
                mutablePos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
                BlockState neighborState = world.getBlockState(mutablePos);
                Block neighborBlock = neighborState.getBlock();
                if (neighborBlock == Blocks.VOID_AIR)
                    return false;
                if (neighborBlock instanceof StairsBlock) {
                    stairs[y + 1]++;
                    totalStairs++;
                } else if (neighborBlock instanceof TrapdoorBlock) {
                    trapdoors[y + 1]++;
                    totalTrapdoors++;
                }
            }
        }
    }
    int chestX = 4;
    int chestY = 2;
    int chestZ = 0;
    int length = 16;
    int height = 9;
    Direction direction = chestFacing;
    if (trapdoors[3] > 4) {
        // with_mast[_degraded]
        chestZ = 9;
        height = 21;
        length = 28;
    } else if (totalTrapdoors == 0 && stairs[3] == 3) {
        // upsidedown_backhalf[_degraded]
        if (stairs[0] == 0) {
            chestX = 2;
            chestZ = 12;
            direction = chestFacing.getOpposite();
        } else {
            // upsidedown front
            chestX = 3;
            chestY = 5;
            chestZ = 17;
            length = 22;
            direction = chestFacing.rotateYClockwise();
        }
    } else if (totalTrapdoors == 0) {
        // rightsideup that have backhalf
        if (stairs[0] == 4) {
            if (totalStairs > 4) {
                chestX = 6;
                chestY = 4;
                chestZ = 12;
                direction = chestFacing.getOpposite();
            } else {
                // sideways backhalf
                chestX = 6;
                chestY = 3;
                chestZ = 8;
                length = 17;
                direction = chestFacing.getOpposite();
            }
        } else if (stairs[0] == 3 && totalStairs > 5) {
            chestX = 5;
            chestZ = 6;
            direction = chestFacing.rotateYCounterclockwise();
        } else if (totalStairs == 3 && stairs[0] == 1 && stairs[2] == 1 && stairs[3] == 1) {
            // upsidedown full
            chestX = 3;
            chestY = 5;
            chestZ = 17;
            length = 28;
            direction = chestFacing.rotateYClockwise();
        }
        mutablePos.set(pos);
        mutablePos.move(0, -chestY, 0);
        mutablePos.move(direction.rotateYClockwise(), chestX - 4);
        mutablePos.move(direction, -chestZ - 1);
        if (this.world.getBlockState(mutablePos).getMaterial() == Material.WOOD) {
            if (length == 17) {
                // sideways
                chestZ += 11;
                length += 11;
            } else {
                chestZ += 12;
                length += 12;
            }
            mutablePos.move(0, 10, 0);
            if (this.world.getBlockState(mutablePos).isIn(BlockTags.LOGS)) {
                height = 21;
            }
        }
    } else if (totalTrapdoors == 2 && trapdoors[3] == 2 && stairs[3] == 3) {
        // rightsideup_fronthalf[_degraded]
        chestZ = 8;
        length = 24;
    } else if (totalTrapdoors == 2 && totalStairs == 4 && stairs[0] == 2) {
        // sideways-fronthalf
        chestX = 5;
        chestY = 3;
        chestZ = 8;
        length = 24;
    }
    if (chestZ != 0) {
        mutablePos.set(pos);
        mutablePos.move(direction, 15 - chestZ);
        mutablePos.move(direction.rotateYClockwise(), chestX - 4);
        BlockPos.Mutable pos2 = new BlockPos.Mutable(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ());
        pos2.move(0, -chestY, 0);
        pos2.move(direction, -15);
        pos2.move(direction.rotateYClockwise(), 4);
        BlockPos.Mutable pos3 = new BlockPos.Mutable(pos2.getX(), pos2.getY(), pos2.getZ());
        pos3.move(direction, length - 1);
        pos3.move(direction.rotateYClockwise(), -8);
        pos3.move(0, height - 1, 0);
        BlockBox box = new BlockBox(Math.min(pos2.getX(), pos3.getX()), pos2.getY(), Math.min(pos2.getZ(), pos3.getZ()), Math.max(pos2.getX(), pos3.getX()) + 1, pos3.getY() + 1, Math.max(pos2.getZ(), pos3.getZ()) + 1);
        mutablePos.move(-4, -chestY, -15);
        if ((mutablePos.getX() & 0xf) == 0 && (mutablePos.getZ() & 0xf) == 0) {
            RegionStructure.Data<?> data = Features.SHIPWRECK.at(new ChunkPos(mutablePos).x, new ChunkPos(mutablePos).z);
            if (SeedCracker.get().getDataStorage().addBaseData(data, DataAddedEvent.POKE_LIFTING)) {
                this.renderers.add(new Cuboid(box, new Color(0, 255, 255)));
                this.renderers.add(new Cube(new ChunkPos(mutablePos).getStartPos().offset(Direction.UP, mutablePos.getY()), new Color(0, 255, 255)));
                return true;
            }
        }
    }
    return false;
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) Color(kaptainwutax.seedcrackerX.render.Color) Cuboid(kaptainwutax.seedcrackerX.render.Cuboid) Direction(net.minecraft.util.math.Direction) Cube(kaptainwutax.seedcrackerX.render.Cube) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) RegionStructure(com.seedfinding.mcfeature.structure.RegionStructure)

Example 29 with Direction

use of net.minecraft.util.math.Direction in project orion by AntiCope.

the class AutoCityPlus method getDirection.

private Direction getDirection(BlockPos pos) {
    // stolen from supakeks ez
    Vec3d eyesPos = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
    for (Direction direction : Direction.values()) {
        RaycastContext raycastContext = new RaycastContext(eyesPos, new Vec3d(pos.getX() + 0.5 + direction.getVector().getX() * 0.5, pos.getY() + 0.5 + direction.getVector().getY() * 0.5, pos.getZ() + 0.5 + direction.getVector().getZ() * 0.5), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
        BlockHitResult result = mc.world.raycast(raycastContext);
        if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(pos)) {
            return direction;
        }
    }
    if ((double) pos.getY() > eyesPos.y) {
        // The player can never see the top of a block if they are under it
        return Direction.DOWN;
    }
    return Direction.UP;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 30 with Direction

use of net.minecraft.util.math.Direction in project wildmod by Osmiooo.

the class FrogEntitySpawnEgg method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    World world = context.getWorld();
    ItemStack itemStack = context.getStack();
    BlockPos blockPos = context.getBlockPos();
    Direction direction = context.getSide();
    BlockState blockState = world.getBlockState(blockPos);
    if (!(world instanceof ServerWorld)) {
        return ActionResult.SUCCESS;
    } else {
        if (blockState.isOf(Blocks.SPAWNER)) {
            BlockEntity blockEntity = world.getBlockEntity(blockPos);
            if (blockEntity instanceof MobSpawnerBlockEntity) {
                MobSpawnerLogic mobSpawnerLogic = ((MobSpawnerBlockEntity) blockEntity).getLogic();
                EntityType<?> entityType = this.getEntityType(itemStack.getNbt());
                mobSpawnerLogic.setEntityId(entityType);
                blockEntity.markDirty();
                world.updateListeners(blockPos, blockState, blockState, Block.NOTIFY_ALL);
                itemStack.decrement(1);
                return ActionResult.CONSUME;
            }
        }
        FrogEntity frogEntity = new FrogEntity(RegisterEntities.FROG, world);
        BlockPos blockPos3;
        if (blockState.getCollisionShape(world, blockPos).isEmpty()) {
            blockPos3 = blockPos;
        } else {
            blockPos3 = blockPos.offset(direction);
        }
        if (FrogEntity.canColdSpawn(world, blockPos3)) {
            frogEntity.setVariant(FrogEntity.Variant.COLD);
        } else if (FrogEntity.canTemperateSpawn(world, blockPos3)) {
            frogEntity.setVariant(FrogEntity.Variant.WARM);
        }
        frogEntity.setPos(blockPos3.getX() + 0.5, blockPos3.getY() + 0.1, blockPos3.getZ() + 0.5);
        frogEntity.setYaw((float) Math.random() * 360 * (float) Math.PI / 180);
        world.spawnEntity(frogEntity);
        itemStack.decrement(1);
        world.emitGameEvent(context.getPlayer(), GameEvent.ENTITY_PLACE, blockPos);
        return ActionResult.CONSUME;
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) FrogEntity(frozenblock.wild.mod.entity.FrogEntity) BlockState(net.minecraft.block.BlockState) MobSpawnerLogic(net.minecraft.world.MobSpawnerLogic) MobSpawnerBlockEntity(net.minecraft.block.entity.MobSpawnerBlockEntity) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.math.Direction) BlockEntity(net.minecraft.block.entity.BlockEntity) MobSpawnerBlockEntity(net.minecraft.block.entity.MobSpawnerBlockEntity)

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