Search in sources :

Example 1 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class BlockInfo method updateLightMatrix.

public void updateLightMatrix() {
    for (int x = 0; x <= 2; x++) {
        for (int y = 0; y <= 2; y++) {
            for (int z = 0; z <= 2; z++) {
                BlockPos pos = blockPos.offset(x - 1, y - 1, z - 1);
                BlockState state = level.getBlockState(pos);
                t[x][y][z] = state.getLightBlock(level, pos) < 15;
                int brightness = LevelRenderer.getLightColor(level, pos);
                s[x][y][z] = LightTexture.sky(brightness);
                b[x][y][z] = LightTexture.block(brightness);
                ao[x][y][z] = state.getShadeBrightness(level, pos);
            }
        }
    }
    for (Direction side : SIDES) {
        BlockPos pos = blockPos.relative(side);
        BlockState state = level.getBlockState(pos);
        BlockState thisStateShape = this.state.canOcclude() && this.state.useShapeForLightOcclusion() ? this.state : Blocks.AIR.defaultBlockState();
        BlockState otherStateShape = state.canOcclude() && state.useShapeForLightOcclusion() ? state : Blocks.AIR.defaultBlockState();
        if (state.getLightBlock(level, pos) == 15 || Shapes.faceShapeOccludes(thisStateShape.getFaceOcclusionShape(level, blockPos, side), otherStateShape.getFaceOcclusionShape(level, pos, side.getOpposite()))) {
            int x = side.getStepX() + 1;
            int y = side.getStepY() + 1;
            int z = side.getStepZ() + 1;
            s[x][y][z] = Math.max(s[1][1][1] - 1, s[x][y][z]);
            b[x][y][z] = Math.max(b[1][1][1] - 1, b[x][y][z]);
        }
    }
    for (int x = 0; x < 2; x++) {
        for (int y = 0; y < 2; y++) {
            for (int z = 0; z < 2; z++) {
                int x1 = x * 2;
                int y1 = y * 2;
                int z1 = z * 2;
                int sxyz = s[x1][y1][z1];
                int bxyz = b[x1][y1][z1];
                boolean txyz = t[x1][y1][z1];
                int sxz = s[x1][1][z1], sxy = s[x1][y1][1], syz = s[1][y1][z1];
                int bxz = b[x1][1][z1], bxy = b[x1][y1][1], byz = b[1][y1][z1];
                boolean txz = t[x1][1][z1], txy = t[x1][y1][1], tyz = t[1][y1][z1];
                int sx = s[x1][1][1], sy = s[1][y1][1], sz = s[1][1][z1];
                int bx = b[x1][1][1], by = b[1][y1][1], bz = b[1][1][z1];
                boolean tx = t[x1][1][1], ty = t[1][y1][1], tz = t[1][1][z1];
                skyLight[0][x][y][z] = combine(sx, sxz, sxy, txz || txy ? sxyz : sx, tx, txz, txy, txz || txy ? txyz : tx);
                blockLight[0][x][y][z] = combine(bx, bxz, bxy, txz || txy ? bxyz : bx, tx, txz, txy, txz || txy ? txyz : tx);
                skyLight[1][x][y][z] = combine(sy, sxy, syz, txy || tyz ? sxyz : sy, ty, txy, tyz, txy || tyz ? txyz : ty);
                blockLight[1][x][y][z] = combine(by, bxy, byz, txy || tyz ? bxyz : by, ty, txy, tyz, txy || tyz ? txyz : ty);
                skyLight[2][x][y][z] = combine(sz, syz, sxz, tyz || txz ? sxyz : sz, tz, tyz, txz, tyz || txz ? txyz : tz);
                blockLight[2][x][y][z] = combine(bz, byz, bxz, tyz || txz ? bxyz : bz, tz, tyz, txz, tyz || txz ? txyz : tz);
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 2 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class GenerateCommand method execute.

private static int execute(CommandSourceStack source, BlockPos pos, int count, ServerLevel dim, int interval) throws CommandRuntimeException {
    BlockPos chunkpos = new BlockPos(pos.getX() >> 4, 0, pos.getZ() >> 4);
    ChunkGenWorker worker = new ChunkGenWorker(source, chunkpos, count, dim, interval);
    source.sendSuccess(worker.getStartMessage(source), true);
    WorldWorkerManager.addWorker(worker);
    return 0;
}
Also used : BlockPos(net.minecraft.core.BlockPos)

Example 3 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method dumpContainer.

/**
 * Drains a filled container and places the fluid in front of the Dispenser.
 */
@Nonnull
private ItemStack dumpContainer(BlockSource source, @Nonnull ItemStack stack) {
    ItemStack singleStack = stack.copy();
    singleStack.setCount(1);
    IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack).orElse(null);
    if (fluidHandler == null) {
        return super.execute(source, stack);
    }
    FluidStack fluidStack = fluidHandler.drain(FluidAttributes.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE);
    Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
    BlockPos blockpos = source.getPos().relative(dispenserFacing);
    FluidActionResult result = FluidUtil.tryPlaceFluid(null, source.getLevel(), InteractionHand.MAIN_HAND, blockpos, stack, fluidStack);
    if (result.isSuccess()) {
        ItemStack drainedStack = result.getResult();
        if (drainedStack.getCount() == 1) {
            return drainedStack;
        } else if (!drainedStack.isEmpty() && ((DispenserBlockEntity) source.getEntity()).addItem(drainedStack) < 0) {
            this.dispenseBehavior.dispense(source, drainedStack);
        }
        ItemStack stackCopy = drainedStack.copy();
        stackCopy.shrink(1);
        return stackCopy;
    } else {
        return this.dispenseBehavior.dispense(source, stack);
    }
}
Also used : IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Example 4 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class VanillaInventoryCodeHooks method dropperInsertHook.

/**
 * Copied from BlockDropper#dispense and added capability support
 */
public static boolean dropperInsertHook(Level world, BlockPos pos, DispenserBlockEntity dropper, int slot, @Nonnull ItemStack stack) {
    Direction enumfacing = world.getBlockState(pos).getValue(DropperBlock.FACING);
    BlockPos blockpos = pos.relative(enumfacing);
    return getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite()).map(destinationResult -> {
        IItemHandler itemHandler = destinationResult.getKey();
        Object destination = destinationResult.getValue();
        ItemStack dispensedStack = stack.copy().split(1);
        ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
        if (remainder.isEmpty()) {
            remainder = stack.copy();
            remainder.shrink(1);
        } else {
            remainder = stack.copy();
        }
        dropper.setItem(slot, remainder);
        return false;
    }).orElse(true);
}
Also used : HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DropperBlock(net.minecraft.world.level.block.DropperBlock) Pair(org.apache.commons.lang3.tuple.Pair) BlockPos(net.minecraft.core.BlockPos) HopperBlock(net.minecraft.world.level.block.HopperBlock) Optional(java.util.Optional) ItemStack(net.minecraft.world.item.ItemStack) Hopper(net.minecraft.world.level.block.entity.Hopper) Level(net.minecraft.world.level.Level) Mth(net.minecraft.util.Mth) Nonnull(javax.annotation.Nonnull) DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity) Nullable(javax.annotation.Nullable) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 5 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class VanillaInventoryCodeHooks method getItemHandler.

public static Optional<Pair<IItemHandler, Object>> getItemHandler(Level worldIn, double x, double y, double z, final Direction side) {
    int i = Mth.floor(x);
    int j = Mth.floor(y);
    int k = Mth.floor(z);
    BlockPos blockpos = new BlockPos(i, j, k);
    net.minecraft.world.level.block.state.BlockState state = worldIn.getBlockState(blockpos);
    if (state.hasBlockEntity()) {
        BlockEntity blockEntity = worldIn.getBlockEntity(blockpos);
        if (blockEntity != null) {
            return blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side).map(capability -> ImmutablePair.<IItemHandler, Object>of(capability, blockEntity));
        }
    }
    return Optional.empty();
}
Also used : BlockPos(net.minecraft.core.BlockPos) HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity)

Aggregations

BlockPos (net.minecraft.core.BlockPos)54 BlockState (net.minecraft.world.level.block.state.BlockState)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)8 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)8 Level (net.minecraft.world.level.Level)7 Direction (net.minecraft.core.Direction)6 Vec3 (net.minecraft.world.phys.Vec3)6 Nonnull (javax.annotation.Nonnull)5 ResourceLocation (net.minecraft.resources.ResourceLocation)5 ItemStack (net.minecraft.world.item.ItemStack)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 Nullable (javax.annotation.Nullable)3 GameTest (net.minecraft.gametest.framework.GameTest)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)2 CompoundTagBuilder (com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2