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);
}
}
}
}
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;
}
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);
}
}
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);
}
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();
}
Aggregations