Search in sources :

Example 1 with MultiblockResult.error

use of slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error in project TinkersConstruct by SlimeKnights.

the class MultiblockCuboid method detectCap.

/**
 * Detects the floor or ceiling of the structure
 * @param world     Level instance
 * @param from      Start position for the cap
 * @param to        End position for the cap
 * @param side      Side of the cube
 * @param consumer  Consumer for any extra positions in this region, specifically frame positions when frame is disabled
 * @return  True if this "cap" is valid, false if not
 */
@SuppressWarnings("deprecation")
protected MultiblockResult detectCap(Level world, BlockPos from, BlockPos to, CuboidSide side, Consumer<Collection<BlockPos>> consumer) {
    // ensure the area is loaded before trying
    if (!world.hasChunksAt(from, to)) {
        return NOT_LOADED;
    }
    // validate frame first
    MutableBlockPos mutable = new MutableBlockPos();
    int height = from.getY();
    if (hasFrame) {
        // function to check a single position in the frame
        Predicate<BlockPos> frameCheck = pos -> isValidBlock(world, pos, side, true);
        // calculate blocks
        // x direction
        Component frameError = side == CuboidSide.CEILING ? INVALID_CEILING_FRAME : INVALID_FLOOR_FRAME;
        for (int x = from.getX(); x <= to.getX(); x++) {
            if (!frameCheck.test(mutable.set(x, height, from.getZ())))
                return MultiblockResult.error(mutable.immutable(), frameError);
            if (!frameCheck.test(mutable.set(x, height, to.getZ())))
                return MultiblockResult.error(mutable.immutable(), frameError);
        }
        // z direction. don't doublecheck corners
        for (int z = from.getZ() + 1; z < to.getZ(); z++) {
            if (!frameCheck.test(mutable.set(from.getX(), height, z)))
                return MultiblockResult.error(mutable.immutable(), frameError);
            if (!frameCheck.test(mutable.set(to.getX(), height, z)))
                return MultiblockResult.error(mutable.immutable(), frameError);
        }
    }
    // validate inside of the floor
    Component blockError = side == CuboidSide.CEILING ? INVALID_CEILING_BLOCK : INVALID_FLOOR_BLOCK;
    for (int z = from.getZ() + 1; z < to.getZ(); z++) {
        for (int x = from.getX() + 1; x < to.getX(); x++) {
            if (!isValidBlock(world, mutable.set(x, height, z), side, false)) {
                return MultiblockResult.error(mutable.immutable(), blockError);
            }
        }
    }
    return MultiblockResult.SUCCESS;
}
Also used : Setter(lombok.Setter) Tag(net.minecraft.nbt.Tag) Getter(lombok.Getter) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BlockState(net.minecraft.world.level.block.state.BlockState) MultiblockResult.error(slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error) ArrayList(java.util.ArrayList) TagUtil(slimeknights.tconstruct.library.utils.TagUtil) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) Nullable(javax.annotation.Nullable) Plane(net.minecraft.core.Direction.Plane) ImmutableSet(com.google.common.collect.ImmutableSet) Component(net.minecraft.network.chat.Component) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TConstruct(slimeknights.tconstruct.TConstruct) Consumer(java.util.function.Consumer) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) ListTag(net.minecraft.nbt.ListTag) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) Component(net.minecraft.network.chat.Component) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 2 with MultiblockResult.error

use of slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error in project TinkersConstruct by SlimeKnights.

the class MultiblockCuboid method detectLayer.

/**
 * Detects an inner layer of the structure. That is, an area with an empty center
 * @param world     Level instance
 * @param from      Start position for the layer
 * @param to        End position for the layer
 * @param consumer  Consumer for any extra positions in this region
 * @return  True if this layer is valid, false otherwise
 */
@SuppressWarnings("deprecation")
protected MultiblockResult detectLayer(Level world, BlockPos from, BlockPos to, Consumer<Collection<BlockPos>> consumer) {
    // ensure its loaded
    if (!world.hasChunksAt(from, to)) {
        return NOT_LOADED;
    }
    // temporary list of position candidates, so we can only add them if successful
    List<BlockPos> candidates = Lists.newArrayList();
    // validate frame first
    MutableBlockPos mutable = new MutableBlockPos();
    int height = from.getY();
    if (hasFrame) {
        // function to check a single position in the frame
        Predicate<BlockPos> frameCheck = pos -> isValidBlock(world, pos, CuboidSide.WALL, true);
        // we only have 4 corner blocks to check
        if (!frameCheck.test(from))
            return MultiblockResult.error(from.immutable(), INVALID_WALL_FRAME);
        if (!frameCheck.test(mutable.set(from.getX(), height, to.getZ())))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_FRAME);
        if (!frameCheck.test(mutable.set(to.getX(), height, from.getZ())))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_FRAME);
        if (!frameCheck.test(to))
            return MultiblockResult.error(to.immutable(), INVALID_WALL_FRAME);
    }
    // validate the inside
    for (int x = from.getX() + 1; x < to.getX(); x++) {
        for (int z = from.getZ() + 1; z < to.getZ(); z++) {
            // ensure its a valid block for inside the structure
            mutable.set(x, height, z);
            if (isInnerBlock(world, mutable)) {
                // any non airblocks are added to extra blocks, this region is ignored by default
                if (!world.isEmptyBlock(mutable)) {
                    candidates.add(mutable.immutable());
                }
            } else {
                return MultiblockResult.error(mutable.immutable(), INVALID_INNER_BLOCK);
            }
        }
    }
    // validate the 4 sides
    Predicate<BlockPos> wallCheck = pos -> isValidBlock(world, pos, CuboidSide.WALL, false);
    for (int x = from.getX() + 1; x < to.getX(); x++) {
        if (!wallCheck.test(mutable.set(x, height, from.getZ())))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
        if (!wallCheck.test(mutable.set(x, height, to.getZ())))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
    }
    for (int z = from.getZ() + 1; z < to.getZ(); z++) {
        if (!wallCheck.test(mutable.set(from.getX(), height, z)))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
        if (!wallCheck.test(mutable.set(to.getX(), height, z)))
            return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
    }
    // was successful, add all candidates
    consumer.accept(candidates);
    return MultiblockResult.SUCCESS;
}
Also used : Setter(lombok.Setter) Tag(net.minecraft.nbt.Tag) Getter(lombok.Getter) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BlockState(net.minecraft.world.level.block.state.BlockState) MultiblockResult.error(slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error) ArrayList(java.util.ArrayList) TagUtil(slimeknights.tconstruct.library.utils.TagUtil) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) Nullable(javax.annotation.Nullable) Plane(net.minecraft.core.Direction.Plane) ImmutableSet(com.google.common.collect.ImmutableSet) Component(net.minecraft.network.chat.Component) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TConstruct(slimeknights.tconstruct.TConstruct) Consumer(java.util.function.Consumer) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) ListTag(net.minecraft.nbt.ListTag) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)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 Getter (lombok.Getter)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 Setter (lombok.Setter)2 BlockPos (net.minecraft.core.BlockPos)2 MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)2 Direction (net.minecraft.core.Direction)2 Plane (net.minecraft.core.Direction.Plane)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2