use of net.minecraft.world.level.block.state.BlockState in project Denizen-For-Bukkit by DenizenScript.
the class FakeBlockHelper method handleMapChunkPacket.
public static ClientboundLevelChunkWithLightPacket handleMapChunkPacket(World world, ClientboundLevelChunkWithLightPacket originalPacket, int chunkX, int chunkZ, List<FakeBlock> blocks) {
try {
ClientboundLevelChunkWithLightPacket duplicateCorePacket = new ClientboundLevelChunkWithLightPacket(DenizenNetworkManagerImpl.copyPacket(originalPacket));
copyPacketPaperPatch(duplicateCorePacket, originalPacket);
FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
originalPacket.getChunkData().write(copier);
ClientboundLevelChunkPacketData packet = new ClientboundLevelChunkPacketData(copier, chunkX, chunkZ);
FriendlyByteBuf serial = originalPacket.getChunkData().getReadBuffer();
FriendlyByteBuf outputSerial = new FriendlyByteBuf(Unpooled.buffer(serial.readableBytes()));
List blockEntities = new ArrayList((List) CHUNKDATA_BLOCK_ENTITIES.get(originalPacket.getChunkData()));
CHUNKDATA_BLOCK_ENTITIES.set(packet, blockEntities);
ListIterator iterator = blockEntities.listIterator();
while (iterator.hasNext()) {
Object blockEnt = iterator.next();
int xz = CHUNKDATA_BLOCKENTITYINFO_PACKEDXZ.getInt(blockEnt);
int y = CHUNKDATA_BLOCKENTITYINFO_Y.getInt(blockEnt);
int x = (chunkX << 4) + ((xz >> 4) & 15);
int z = (chunkZ << 4) + (xz & 15);
for (FakeBlock block : blocks) {
LocationTag loc = block.location;
if (loc.getBlockX() == x && loc.getBlockY() == y && loc.getBlockZ() == z && block.material != null) {
iterator.remove();
break;
}
}
}
int worldMinY = world.getMinHeight();
int worldMaxY = world.getMaxHeight();
int minChunkY = worldMinY >> 4;
int maxChunkY = worldMaxY >> 4;
Registry<Biome> biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
for (int y = minChunkY; y < maxChunkY; y++) {
int blockCount = serial.readShort();
// reflected constructors as workaround for spigot remapper bug - Mojang "IdMap" became Spigot "IRegistry" but should be "Registry"
PalettedContainer<BlockState> states = (PalettedContainer<BlockState>) PALETTEDCONTAINER_CTOR.newInstance(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
states.read(serial);
PalettedContainer<Biome> biomes = (PalettedContainer<Biome>) PALETTEDCONTAINER_CTOR.newInstance(biomeRegistry, biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
biomes.read(serial);
if (anyBlocksInSection(blocks, y)) {
int minY = y << 4;
int maxY = (y << 4) + 16;
for (FakeBlock block : blocks) {
int blockY = block.location.getBlockY();
if (blockY >= minY && blockY < maxY && block.material != null) {
int blockX = block.location.getBlockX();
int blockZ = block.location.getBlockZ();
blockX -= (blockX >> 4) * 16;
blockY -= (blockY >> 4) * 16;
blockZ -= (blockZ >> 4) * 16;
BlockState oldState = states.get(blockX, blockY, blockZ);
BlockState newState = getNMSState(block);
if (oldState.isAir() && !newState.isAir()) {
blockCount++;
} else if (newState.isAir() && !oldState.isAir()) {
blockCount--;
}
states.set(blockX, blockY, blockZ, newState);
}
}
}
outputSerial.writeShort(blockCount);
states.write(outputSerial);
biomes.write(outputSerial);
}
byte[] outputBytes = outputSerial.array();
CHUNKDATA_BUFFER_SETTER.invoke(packet, outputBytes);
CHUNKPACKET_CHUNKDATA_SETTER.invoke(duplicateCorePacket, packet);
return duplicateCorePacket;
} catch (Throwable ex) {
Debug.echoError(ex);
}
return null;
}
use of net.minecraft.world.level.block.state.BlockState in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processShowFakeForPacket.
public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (FakeBlock.blocks.isEmpty()) {
return false;
}
try {
if (packet instanceof ClientboundLevelChunkWithLightPacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
int chunkX = ((ClientboundLevelChunkWithLightPacket) packet).getX();
int chunkZ = ((ClientboundLevelChunkWithLightPacket) packet).getZ();
ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
if (blocks == null || blocks.isEmpty()) {
return false;
}
ClientboundLevelChunkWithLightPacket newPacket = FakeBlockHelper.handleMapChunkPacket(player.getBukkitEntity().getWorld(), (ClientboundLevelChunkWithLightPacket) packet, chunkX, chunkZ, blocks);
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
if (!map.byChunk.containsKey(coordinateDenizen)) {
return false;
}
ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
for (int i = 0; i < offsetArray.length; i++) {
short offset = offsetArray[i];
BlockPos pos = coord.relativeToBlockPos(offset);
location.setX(pos.getX());
location.setY(pos.getY());
location.setZ(pos.getZ());
FakeBlock block = map.byLocation.get(location);
if (block != null) {
dataArray[i] = FakeBlockHelper.getNMSState(block);
}
}
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundBlockUpdatePacket) {
BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
oldManager.send(newPacket, genericfuturelistener);
return true;
}
} else if (packet instanceof ClientboundBlockBreakAckPacket) {
ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
BlockPos pos = origPack.pos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
oldManager.send(newPacket, genericfuturelistener);
return true;
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
return false;
}
use of net.minecraft.world.level.block.state.BlockState in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderFullMap.
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
} else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.setY(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method setFallingBlockType.
@Override
public void setFallingBlockType(FallingBlock entity, BlockData block) {
BlockState state = ((CraftBlockData) block).getState();
FallingBlockEntity nmsEntity = ((CraftFallingBlock) entity).getHandle();
try {
FALLINGBLOCK_TYPE_SETTER.invoke(nmsEntity, state);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class CowktailLayer method render.
public void render(PoseStack stack, MultiBufferSource bufferIn, int packedLightIn, T entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (!entitylivingbaseIn.isBaby() && !entitylivingbaseIn.isInvisible()) {
BlockRenderDispatcher renderer = Minecraft.getInstance().getBlockRenderer();
BlockState blockState = entitylivingbaseIn.getCowktailType().getRenderState();
int overlayCoords = LivingEntityRenderer.getOverlayCoords(entitylivingbaseIn, 0.0F);
stack.pushPose();
stack.translate(0.2F, -0.35F, 0.5D);
stack.mulPose(Vector3f.YP.rotationDegrees(-48.0F));
stack.scale(-1.0F, -1.0F, 1.0F);
stack.translate(-0.5D, -0.5D, -0.5D);
renderer.renderSingleBlock(blockState, stack, bufferIn, packedLightIn, overlayCoords);
stack.popPose();
stack.pushPose();
stack.translate(0.2F, -0.35F, 0.5D);
stack.mulPose(Vector3f.YP.rotationDegrees(42.0F));
stack.translate(0.1F, 0.0D, -0.6F);
stack.mulPose(Vector3f.YP.rotationDegrees(-48.0F));
stack.scale(-1.0F, -1.0F, 1.0F);
stack.translate(-0.5D, -0.5D, -0.5D);
renderer.renderSingleBlock(blockState, stack, bufferIn, packedLightIn, overlayCoords);
stack.popPose();
stack.pushPose();
this.getParentModel().getHead().translateAndRotate(stack);
stack.translate(0.0D, -0.7F, -0.2F);
stack.mulPose(Vector3f.YP.rotationDegrees(-78.0F));
stack.scale(-1.0F, -1.0F, 1.0F);
stack.translate(-0.5D, -0.5D, -0.5D);
renderer.renderSingleBlock(blockState, stack, bufferIn, packedLightIn, overlayCoords);
stack.popPose();
}
}
Aggregations