use of com.bergerkiller.generated.net.minecraft.server.level.PlayerChunkHandle in project BKCommonLib by bergerhealer.
the class EntityAddRemoveHandler_1_14_to_1_16_5 method replace.
@Override
public void replace(EntityHandle oldEntity, EntityHandle newEntity) {
WorldServerHandle world = oldEntity.getWorldServer();
if (newEntity == null) {
if (world != null) {
world.removeEntity(oldEntity);
world.getEntityTracker().stopTracking(oldEntity.getBukkitEntity());
}
// Works fine, no need to clean up any more
return;
}
Object worldHandle = world.getRaw();
// *** Remove from the entities to add queue ***
Queue<Object> entitiesToAdd = this.entitiesToAddField.get(oldEntity.getWorld().getRaw());
entitiesToAdd.remove(oldEntity.getRaw());
// *** Entities By UUID Map ***
{
Map<UUID, Object> entitiesByUUID = this.entitiesByUUIDField.get(worldHandle);
Object storedEntityHandle = entitiesByUUID.get(oldEntity.getUniqueID());
if (storedEntityHandle != null && storedEntityHandle != newEntity.getRaw()) {
if (!oldEntity.getUniqueID().equals(newEntity.getUniqueID())) {
entitiesByUUID.remove(oldEntity.getUniqueID());
}
entitiesByUUID.put(newEntity.getUniqueID(), newEntity.getRaw());
}
}
// *** Entities by Id Map ***
{
IntHashMapHandle entitiesById = IntHashMapHandle.createHandle(this.entitiesByIdField.get(worldHandle));
Object storedEntityHandle = entitiesById.get(oldEntity.getIdField());
if (storedEntityHandle != null && storedEntityHandle != newEntity.getRaw()) {
if (oldEntity.getIdField() != newEntity.getIdField()) {
entitiesById.remove(oldEntity.getIdField());
}
entitiesById.put(newEntity.getIdField(), newEntity.getRaw());
}
}
// *** Tuinity WorldServer EntityList field ***
if (tuinitySwapEntityInWorldEntityListMethod.isAvailable()) {
tuinitySwapEntityInWorldEntityListMethod.invoke(worldHandle, oldEntity.getRaw(), newEntity.getRaw());
}
// *** Tuinity WorldServer entitiesForIteration field ***
if (tuinitySwapEntityInWorldEntityIterationSetMethod.isAvailable()) {
tuinitySwapEntityInWorldEntityIterationSetMethod.invoke(worldHandle, oldEntity.getRaw(), newEntity.getRaw());
}
// *** EntityTrackerEntry ***
replaceInEntityTracker(oldEntity, oldEntity, newEntity);
if (oldEntity.getVehicle() != null) {
replaceInEntityTracker(oldEntity.getVehicle(), oldEntity, newEntity);
}
if (oldEntity.getPassengers() != null) {
for (EntityHandle passenger : oldEntity.getPassengers()) {
replaceInEntityTracker(passenger, oldEntity, newEntity);
}
}
// *** Entity Current Chunk ***
final int chunkX = newEntity.getChunkX();
final int chunkZ = newEntity.getChunkZ();
PlayerChunkMapHandle playerChunks = WorldServerHandle.T.getPlayerChunkMap.invoke(worldHandle);
Chunk loadedChunk = WorldUtil.getChunk(newEntity.getBukkitWorld(), chunkX, chunkZ);
if (loadedChunk != null) {
replaceInChunk(loadedChunk, oldEntity, newEntity);
} else {
// Chunk isn't loaded at this time. This gets difficult!
// It might still be in the updating chunks mapping
PlayerChunkHandle updatingChunk = playerChunks.getUpdatingChunk(chunkX, chunkZ);
Chunk loadedUpdatingChunk = (updatingChunk == null) ? null : updatingChunk.getChunkIfLoaded();
if (loadedUpdatingChunk == null && updatingChunk != null) {
// Try hard time! This allows any status the chunk is in.
loadedUpdatingChunk = PlayerChunkHandle.T.opt_getChunkTryHard_1_14.invoke(updatingChunk.getRaw());
}
// Let's go!
replaceInChunk(loadedUpdatingChunk, oldEntity, newEntity);
}
// See where the object is still referenced to check we aren't missing any places to replace
// This is SLOW, do not ever have this enabled on a release version!
// com.bergerkiller.bukkit.common.utils.DebugUtil.logInstances(oldEntity.getRaw());
}
use of com.bergerkiller.generated.net.minecraft.server.level.PlayerChunkHandle in project BKCommonLib by bergerhealer.
the class WorldUtil method queueChunkSendLight.
/**
* Queue a chunk for resending all its lighting information to all players that are in range of it.
*
* @param world
* @param chunkX
* @param chunkZ
* @return True if players were nearby, False if not
*/
public static boolean queueChunkSendLight(org.bukkit.World world, int chunkX, int chunkZ) {
PlayerChunkMapHandle playerChunkMap = CommonNMS.getHandle(world).getPlayerChunkMap();
PlayerChunkHandle playerChunk = playerChunkMap.getVisibleChunk(chunkX, chunkZ);
return playerChunk != null && playerChunk.resendAllLighting();
}
use of com.bergerkiller.generated.net.minecraft.server.level.PlayerChunkHandle in project BKCommonLib by bergerhealer.
the class WorldUtil method queueChunkSend.
/**
* Queue a chunk for resending to all players that are in range of it.
* Use this method to update chunk data after doing changes to its raw structure.
*
* @param player to send chunk data for
* @param chunkX - coordinate of the chunk
* @param chunkZ - coordinate of the chunk
* @return True if players were nearby, False if not
*/
public static boolean queueChunkSend(org.bukkit.World world, int chunkX, int chunkZ) {
PlayerChunkMapHandle playerChunkMap = CommonNMS.getHandle(world).getPlayerChunkMap();
PlayerChunkHandle playerChunk = playerChunkMap.getVisibleChunk(chunkX, chunkZ);
return playerChunk != null && playerChunk.resendChunk();
}
Aggregations