use of com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityAddRemoveHandler_1_8_to_1_13_2 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();
// *** Entities By UUID Map ***
{
Map<UUID, Object> entitiesByUUID = 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.getId());
if (storedEntityHandle != null && storedEntityHandle != newEntity.getRaw()) {
if (oldEntity.getId() != newEntity.getId()) {
entitiesById.remove(oldEntity.getId());
}
entitiesById.put(newEntity.getId(), newEntity.getRaw());
}
}
// *** Entities By UUID Map ***
final Map<UUID, Object> entitiesByUUID = entitiesByUUIDField.get(worldHandle);
entitiesByUUID.put(newEntity.getUniqueID(), newEntity.getRaw());
// *** Entities by Id Map ***
IntHashMapHandle entitiesById = IntHashMapHandle.createHandle(this.entitiesByIdField.get(worldHandle));
entitiesById.put(newEntity.getId(), newEntity.getRaw());
// *** EntityTrackerEntry ***
replaceInEntityTracker(newEntity.getId(), newEntity);
if (newEntity.getVehicle() != null) {
replaceInEntityTracker(newEntity.getVehicle().getId(), newEntity);
}
if (newEntity.getPassengers() != null) {
for (EntityHandle passenger : newEntity.getPassengers()) {
replaceInEntityTracker(passenger.getId(), newEntity);
}
}
// *** World ***
replaceInList(entityListField.get(worldHandle), newEntity);
// Fixes for PaperSpigot
// if (!Common.IS_PAPERSPIGOT_SERVER) {
// replaceInList(WorldRef.entityRemovalList.get(oldInstance.world), newInstance);
// }
// *** Entity Current Chunk ***
final int chunkX = newEntity.getChunkX();
final int chunkZ = newEntity.getChunkZ();
Object chunkHandle = HandleConversion.toChunkHandle(WorldUtil.getChunk(newEntity.getWorld().getWorld(), chunkX, chunkZ));
if (chunkHandle != null) {
this.chunkEntitySliceHandler.replace(chunkHandle, 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(oldInstance.getRaw());
}
use of com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityAddRemoveHandler_1_8_to_1_13_2 method replaceInEntityTracker.
private static void replaceInEntityTracker(int entityId, EntityHandle newInstance) {
final EntityTracker trackerMap = WorldUtil.getTracker(newInstance.getWorld().getWorld());
EntityTrackerEntryHandle entry = trackerMap.getEntry(entityId);
if (entry != null) {
EntityHandle tracker = entry.getState().getEntity();
if (tracker != null && tracker.getId() == newInstance.getId()) {
entry.setEntity(newInstance);
}
List<EntityHandle> passengers = new ArrayList<EntityHandle>(tracker.getPassengers());
replaceInList(passengers, newInstance);
tracker.setPassengers(passengers);
}
}
use of com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityAddRemoveHandler_1_14_to_1_16_5 method replaceInEntityTracker.
@SuppressWarnings("unchecked")
private static void replaceInEntityTracker(EntityHandle entity, EntityHandle oldEntity, EntityHandle newEntity) {
final EntityTracker trackerMap = WorldUtil.getTracker(newEntity.getBukkitWorld());
EntityTrackerEntryHandle entry = trackerMap.getEntry(entity.getIdField());
if (entry != null) {
// PlayerChunkMap$EntityTracker entity
EntityHandle entryEntity = entry.getEntity();
if (entryEntity != null && entryEntity.getIdField() == oldEntity.getIdField()) {
entry.setEntity(newEntity);
}
// EntityTrackerEntry 'tracker' entity
EntityTrackerEntryStateHandle stateHandle = entry.getState();
EntityHandle stateEntity = stateHandle.getEntity();
if (stateEntity != null && stateEntity.getIdField() == oldEntity.getIdField() && stateEntity.getRaw() != newEntity.getRaw()) {
stateHandle.setEntity(newEntity);
}
// EntityTrackerEntry List of passengers
List<Object> statePassengers = (List<Object>) EntityTrackerEntryStateHandle.T.opt_passengers.raw.get(stateHandle.getRaw());
replaceInList(statePassengers, oldEntity, newEntity);
}
}
use of com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityMoveHandler_1_8 method world_addEntityCubes.
private void world_addEntityCubes(EntityHandle entity, AxisAlignedBBHandle axisalignedbb) {
if (entity != null && this.entityCollisionEnabled) {
List<EntityHandle> list = entity.getWorld().getNearbyEntities(entity, axisalignedbb.growUniform(0.25D));
for (EntityHandle entity1 : list) {
if (!entity.isInSameVehicle(entity1)) {
// BKCommonLib start: block collision event handler
AxisAlignedBBHandle axisalignedbb1 = entity1.getOtherBoundingBox();
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
collisions_buffer.add(axisalignedbb1);
}
axisalignedbb1 = entity.getEntityBoundingBox(entity1);
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
collisions_buffer.add(axisalignedbb1);
}
// BKCommonLib end
/*
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
axisalignedbb1 = entity.j(entity1);
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
*/
}
}
}
}
use of com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityMoveHandler_1_8 method world_getBlockCubes.
/**
* Adds all the bounding boxes of blocks that collide with the movedBounds boundingbox
*
* @param entity that moved
* @param movedBounds bounding box
* @param cubes result list
* @return True if cubes were found
*/
protected boolean world_getBlockCubes(EntityHandle entity, AxisAlignedBBHandle movedBounds, List<AxisAlignedBBHandle> cubes) {
List<AxisAlignedBBHandle> foundBounds = WorldHandle.T.opt_getCubes_1_8.invoke(entity.getWorld().getRaw(), entity, movedBounds);
if (foundBounds.isEmpty()) {
return false;
}
// Remove all collisions that have to do with Entities; not Blocks.
// This is a bit of a hacked in way for backwards <= 1.10.2 support
// Basically, we repeat getCubes() and ignore all found bounding boxes in here
List<EntityHandle> list = entity.getWorld().getNearbyEntities(entity, movedBounds.growUniform(0.25D));
for (EntityHandle entity1 : list) {
if (CommonCapabilities.VEHICLES_COLLIDE_WITH_PASSENGERS || !entity.isInSameVehicle(entity1)) {
// BKCommonLib start: block collision event handler
AxisAlignedBBHandle axisalignedbb1 = entity1.getOtherBoundingBox();
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(movedBounds)) {
removeFromList(foundBounds, axisalignedbb1);
}
axisalignedbb1 = entity.getEntityBoundingBox(entity1);
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(movedBounds)) {
removeFromList(foundBounds, axisalignedbb1);
}
// BKCommonLib end
/*
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
axisalignedbb1 = entity.j(entity1);
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
*/
}
}
cubes.addAll(foundBounds);
return true;
}
Aggregations