Search in sources :

Example 6 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project additionaladditions by Dqu1J.

the class CopperPatinaBlock method updateIndirectNeighbourShapes.

public void updateIndirectNeighbourShapes(BlockState state, LevelAccessor world, BlockPos pos, int flags, int maxUpdateDepth) {
    MutableBlockPos mutable = new MutableBlockPos();
    Iterator var7 = Plane.HORIZONTAL.iterator();
    while (var7.hasNext()) {
        Direction direction = (Direction) var7.next();
        RedstoneSide wireConnection = (RedstoneSide) state.getValue((Property) DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction));
        if (wireConnection != RedstoneSide.NONE && !world.getBlockState(mutable.setWithOffset(pos, direction)).is(this)) {
            mutable.move(Direction.DOWN);
            BlockState blockState = world.getBlockState(mutable);
            if (!blockState.is(Blocks.OBSERVER)) {
                BlockPos blockPos = mutable.relative(direction.getOpposite());
                BlockState blockState2 = blockState.updateShape(direction.getOpposite(), world.getBlockState(blockPos), world, mutable, blockPos);
                updateOrDestroy(blockState, blockState2, world, mutable, flags, maxUpdateDepth);
            }
            mutable.setWithOffset(pos, direction).move(Direction.UP);
            BlockState blockState3 = world.getBlockState(mutable);
            if (!blockState3.is(Blocks.OBSERVER)) {
                BlockPos blockPos2 = mutable.relative(direction.getOpposite());
                BlockState blockState4 = blockState3.updateShape(direction.getOpposite(), world.getBlockState(blockPos2), world, mutable, blockPos2);
                updateOrDestroy(blockState3, blockState4, world, mutable, flags, maxUpdateDepth);
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Iterator(java.util.Iterator) UnmodifiableIterator(com.google.common.collect.UnmodifiableIterator) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) RedstoneSide(net.minecraft.world.level.block.state.properties.RedstoneSide) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction) EnumProperty(net.minecraft.world.level.block.state.properties.EnumProperty) Property(net.minecraft.world.level.block.state.properties.Property) IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty)

Example 7 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BCLib by paulevsGitch.

the class SDF method fillRecursive.

public void fillRecursive(StructureWorld world, BlockPos start) {
    Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
    Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
    Set<BlockPos> blocks = Sets.newHashSet();
    Set<BlockPos> ends = Sets.newHashSet();
    Set<BlockPos> add = Sets.newHashSet();
    ends.add(new BlockPos(0, 0, 0));
    boolean run = true;
    MutableBlockPos bPos = new MutableBlockPos();
    while (run) {
        for (BlockPos center : ends) {
            for (Direction dir : Direction.values()) {
                bPos.set(center).move(dir);
                BlockPos wpos = bPos.offset(start);
                if (!blocks.contains(bPos)) {
                    if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
                        BlockState state = getBlockState(wpos);
                        PosInfo.create(mapWorld, addInfo, wpos).setState(state);
                        add.add(bPos.immutable());
                    }
                }
            }
        }
        blocks.addAll(ends);
        ends.clear();
        ends.addAll(add);
        add.clear();
        run &= !ends.isEmpty();
    }
    List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
    Collections.sort(infos);
    postProcesses.forEach((postProcess) -> {
        infos.forEach((info) -> {
            info.setState(postProcess.apply(info));
        });
    });
    infos.forEach((info) -> {
        world.setBlock(info.getPos(), info.getState());
    });
    infos.clear();
    infos.addAll(addInfo.values());
    Collections.sort(infos);
    postProcesses.forEach((postProcess) -> {
        infos.forEach((info) -> {
            info.setState(postProcess.apply(info));
        });
    });
    infos.forEach((info) -> {
        world.setBlock(info.getPos(), info.getState());
    });
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction)

Example 8 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BCLib by paulevsGitch.

the class SDF method fillRecursive.

public void fillRecursive(ServerLevelAccessor world, BlockPos start) {
    Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
    Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
    Set<BlockPos> blocks = Sets.newHashSet();
    Set<BlockPos> ends = Sets.newHashSet();
    Set<BlockPos> add = Sets.newHashSet();
    ends.add(new BlockPos(0, 0, 0));
    boolean run = true;
    MutableBlockPos bPos = new MutableBlockPos();
    while (run) {
        for (BlockPos center : ends) {
            for (Direction dir : Direction.values()) {
                bPos.set(center).move(dir);
                BlockPos wpos = bPos.offset(start);
                if (!blocks.contains(bPos) && canReplace.apply(world.getBlockState(wpos))) {
                    if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
                        BlockState state = getBlockState(wpos);
                        PosInfo.create(mapWorld, addInfo, wpos).setState(state);
                        add.add(bPos.immutable());
                    }
                }
            }
        }
        blocks.addAll(ends);
        ends.clear();
        ends.addAll(add);
        add.clear();
        run &= !ends.isEmpty();
    }
    List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
    if (infos.size() > 0) {
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
        });
        infos.clear();
        infos.addAll(addInfo.values());
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            if (canReplace.apply(world.getBlockState(info.getPos()))) {
                BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
            }
        });
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction)

Example 9 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BCLib by paulevsGitch.

the class SDF method fillArea.

public void fillArea(ServerLevelAccessor world, BlockPos center, AABB box) {
    Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
    Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
    MutableBlockPos mut = new MutableBlockPos();
    for (int y = (int) box.minY; y <= box.maxY; y++) {
        mut.setY(y);
        for (int x = (int) box.minX; x <= box.maxX; x++) {
            mut.setX(x);
            for (int z = (int) box.minZ; z <= box.maxZ; z++) {
                mut.setZ(z);
                if (canReplace.apply(world.getBlockState(mut))) {
                    BlockPos fpos = mut.subtract(center);
                    if (this.getDistance(fpos.getX(), fpos.getY(), fpos.getZ()) < 0) {
                        PosInfo.create(mapWorld, addInfo, mut.immutable()).setState(getBlockState(mut));
                    }
                }
            }
        }
    }
    List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
    if (infos.size() > 0) {
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
        });
        infos.clear();
        infos.addAll(addInfo.values());
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            if (canReplace.apply(world.getBlockState(info.getPos()))) {
                BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 10 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BCLib by paulevsGitch.

the class SDF method fillRecursiveIgnore.

public void fillRecursiveIgnore(ServerLevelAccessor world, BlockPos start, Function<BlockState, Boolean> ignore) {
    Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
    Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
    Set<BlockPos> blocks = Sets.newHashSet();
    Set<BlockPos> ends = Sets.newHashSet();
    Set<BlockPos> add = Sets.newHashSet();
    ends.add(new BlockPos(0, 0, 0));
    boolean run = true;
    MutableBlockPos bPos = new MutableBlockPos();
    while (run) {
        for (BlockPos center : ends) {
            for (Direction dir : Direction.values()) {
                bPos.set(center).move(dir);
                BlockPos wpos = bPos.offset(start);
                BlockState state = world.getBlockState(wpos);
                boolean ign = ignore.apply(state);
                if (!blocks.contains(bPos) && (ign || canReplace.apply(state))) {
                    if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
                        PosInfo.create(mapWorld, addInfo, wpos).setState(ign ? state : getBlockState(bPos));
                        add.add(bPos.immutable());
                    }
                }
            }
        }
        blocks.addAll(ends);
        ends.clear();
        ends.addAll(add);
        add.clear();
        run &= !ends.isEmpty();
    }
    List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
    if (infos.size() > 0) {
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
        });
        infos.clear();
        infos.addAll(addInfo.values());
        Collections.sort(infos);
        postProcesses.forEach((postProcess) -> {
            infos.forEach((info) -> {
                info.setState(postProcess.apply(info));
            });
        });
        infos.forEach((info) -> {
            if (canReplace.apply(world.getBlockState(info.getPos()))) {
                BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState());
            }
        });
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction)

Aggregations

MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)60 BlockPos (net.minecraft.core.BlockPos)32 BlockState (net.minecraft.world.level.block.state.BlockState)31 Random (java.util.Random)16 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)16 Direction (net.minecraft.core.Direction)11 ArrayList (java.util.ArrayList)8 Block (net.minecraft.world.level.block.Block)4 Level (net.minecraft.world.level.Level)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Vector3f (com.mojang.math.Vector3f)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Nullable (javax.annotation.Nullable)2 AccessLevel (lombok.AccessLevel)2