use of net.minecraft.world.level.chunk.LevelChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method doRandomTick.
@Override
public void doRandomTick(Location location) {
BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
LevelChunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
net.minecraft.world.level.block.state.BlockState nmsBlock = nmsChunk.getBlockState(pos);
ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
if (nmsBlock.isRandomlyTicking()) {
nmsBlock.randomTick(nmsWorld, pos, nmsWorld.random);
}
try {
// FluidState fluid = nmsBlock.getFluidState();
// if (fluid.isRandomlyTicking()) {
// fluid.animateTick(nmsWorld, pos, nmsWorld.random);
// }
Object fluid = BLOCKSTATEBASE_GETFLUIDSTATE.invoke(nmsBlock);
if ((boolean) FLUIDSTATE_ISRANDOMLYTICKING.invoke(fluid)) {
FLUIDSTATE_ANIMATETICK.invoke(fluid, nmsWorld, pos, nmsWorld.random);
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.LevelChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
try {
BlockPos pos = packet.getPos();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
LevelChunk chunk = world.getChunkAt(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof LevelChunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.LevelChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getBlockYMask();
List<byte[]> blockData = packet.getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.LevelChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getLightData().getBlockYMask();
List<byte[]> blockData = packet.getLightData().getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class ChunkHolderMixin method impl$throwChunkGeneratedEvent.
@Inject(method = "replaceProtoChunk(Lnet/minecraft/world/level/chunk/ImposterProtoChunk;)V", at = @At("TAIL"))
private void impl$throwChunkGeneratedEvent(final ImposterProtoChunk imposter, final CallbackInfo ci) {
if (!ShouldFire.CHUNK_EVENT_GENERATED) {
return;
}
final LevelChunk chunk = imposter.getWrapped();
final Vector3i chunkPos = VecHelper.toVector3i(chunk.getPos());
final ChunkEvent.Generated event = SpongeEventFactory.createChunkEventGenerated(PhaseTracker.getInstance().currentCause(), chunkPos, (ResourceKey) (Object) chunk.getLevel().dimension().location());
SpongeCommon.post(event);
}
Aggregations