use of net.minecraft.world.level.block.state.BlockState 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.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class FluidUtil method tryPickUpFluid.
/**
* Attempts to pick up a fluid in the world and put it in an empty container item.
*
* @param emptyContainer The empty container to fill.
* Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
* @param playerIn The player filling the container. Optional.
* @param worldIn The world the fluid is in.
* @param pos The position of the fluid in the world.
* @param side The side of the fluid that is being drained.
* @return a {@link FluidActionResult} holding the result and the resulting container.
*/
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable Player playerIn, Level worldIn, BlockPos pos, Direction side) {
if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
return FluidActionResult.FAILURE;
}
BlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
IFluidHandler targetFluidHandler;
if (block instanceof IFluidBlock) {
targetFluidHandler = new FluidBlockWrapper((IFluidBlock) block, worldIn, pos);
} else if (block instanceof BucketPickup) {
targetFluidHandler = new BucketPickupHandlerWrapper((BucketPickup) block, worldIn, pos);
} else {
Optional<IFluidHandler> fluidHandler = getFluidHandler(worldIn, pos, side).resolve();
if (!fluidHandler.isPresent()) {
return FluidActionResult.FAILURE;
}
targetFluidHandler = fluidHandler.get();
}
return tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class FluidUtil method tryPlaceFluid.
/**
* Tries to place a fluid resource into the world as a block and drains the fluidSource.
* Makes a fluid emptying or vaporization sound when successful.
* Honors the amount of fluid contained by the used container.
* Checks if water-like fluids should vaporize like in the nether.
*
* Modeled after {@link BucketItem#emptyContents(Player, Level, BlockPos, BlockHitResult)}
*
* @param player Player who places the fluid. May be null for blocks like dispensers.
* @param world Level to place the fluid in
* @param hand
* @param pos The position in the world to place the fluid block
* @param fluidSource The fluid source holding the fluidStack to place
* @param resource The fluidStack to place.
* @return true if the placement was successful, false otherwise
*/
public static boolean tryPlaceFluid(@Nullable Player player, Level world, InteractionHand hand, BlockPos pos, IFluidHandler fluidSource, FluidStack resource) {
if (world == null || pos == null) {
return false;
}
Fluid fluid = resource.getFluid();
if (fluid == Fluids.EMPTY || !fluid.getAttributes().canBePlacedInWorld(world, pos, resource)) {
return false;
}
if (fluidSource.drain(resource, IFluidHandler.FluidAction.SIMULATE).isEmpty()) {
return false;
}
BlockPlaceContext context = new BlockPlaceContext(world, player, hand, player == null ? ItemStack.EMPTY : player.getItemInHand(hand), new BlockHitResult(Vec3.ZERO, Direction.UP, pos, false));
// check that we can place the fluid at the destination
BlockState destBlockState = world.getBlockState(pos);
Material destMaterial = destBlockState.getMaterial();
boolean isDestNonSolid = !destMaterial.isSolid();
boolean isDestReplaceable = destBlockState.canBeReplaced(context);
boolean canDestContainFluid = destBlockState.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer) destBlockState.getBlock()).canPlaceLiquid(world, pos, destBlockState, fluid);
if (!world.isEmptyBlock(pos) && !isDestNonSolid && !isDestReplaceable && !canDestContainFluid) {
// Non-air, solid, unreplacable block. We can't put fluid here.
return false;
}
if (world.dimensionType().ultraWarm() && fluid.getAttributes().doesVaporize(world, pos, resource)) {
FluidStack result = fluidSource.drain(resource, IFluidHandler.FluidAction.EXECUTE);
if (!result.isEmpty()) {
result.getFluid().getAttributes().vaporize(player, world, pos, result);
return true;
}
} else {
// This fluid handler places the fluid block when filled
IFluidHandler handler;
if (canDestContainFluid) {
handler = new BlockWrapper.LiquidContainerBlockWrapper((LiquidBlockContainer) destBlockState.getBlock(), world, pos);
} else {
handler = getFluidBlockHandler(fluid, world, pos);
}
FluidStack result = tryFluidTransfer(handler, fluidSource, resource, true);
if (!result.isEmpty()) {
SoundEvent soundevent = resource.getFluid().getAttributes().getEmptySound(resource);
world.playSound(player, pos, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F);
return true;
}
}
return false;
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class BlockSnapshot method restoreToLocation.
public boolean restoreToLocation(LevelAccessor world, BlockPos pos, boolean force, boolean notifyNeighbors) {
BlockState current = getCurrentBlock();
BlockState replaced = getReplacedBlock();
int flags = notifyNeighbors ? Block.UPDATE_ALL : Block.UPDATE_CLIENTS;
if (current != replaced) {
if (force)
world.setBlock(pos, replaced, flags);
else
return false;
}
world.setBlock(pos, replaced, flags);
if (world instanceof Level)
((Level) world).sendBlockUpdated(pos, current, replaced, flags);
BlockEntity te = null;
if (getTag() != null) {
te = world.getBlockEntity(pos);
if (te != null) {
te.load(getTag());
te.setChanged();
}
}
if (DEBUG)
System.out.println("Restored " + this.toString());
return true;
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method renderPistonMovedBlocks.
public static void renderPistonMovedBlocks(BlockPos pos, BlockState state, PoseStack stack, MultiBufferSource buffer, Level world, boolean checkSides, int combinedOverlay, BlockRenderDispatcher blockRenderer) {
RenderType.chunkBufferLayers().stream().filter(t -> ItemBlockRenderTypes.canRenderInLayer(state, t)).forEach(rendertype -> {
setRenderType(rendertype);
VertexConsumer ivertexbuilder = buffer.getBuffer(rendertype == RenderType.translucent() ? RenderType.translucentMovingBlock() : rendertype);
blockRenderer.getModelRenderer().tesselateBlock(world, blockRenderer.getBlockModel(state), state, pos, stack, ivertexbuilder, checkSides, new Random(), state.getSeed(pos), combinedOverlay);
});
setRenderType(null);
}
Aggregations