Search in sources :

Example 16 with EntityHandle

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());
}
Also used : IntHashMapHandle(com.bergerkiller.generated.net.minecraft.util.IntHashMapHandle) WorldServerHandle(com.bergerkiller.generated.net.minecraft.server.level.WorldServerHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle) UUID(java.util.UUID) Map(java.util.Map)

Example 17 with EntityHandle

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);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) EntityTracker(com.bergerkiller.bukkit.common.wrappers.EntityTracker) ArrayList(java.util.ArrayList) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 18 with EntityHandle

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);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) EntityTrackerEntryStateHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle) EntityTracker(com.bergerkiller.bukkit.common.wrappers.EntityTracker) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 19 with EntityHandle

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);
                    }
                    */
            }
        }
    }
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 20 with EntityHandle

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;
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Aggregations

EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)22 AxisAlignedBBHandle (com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle)6 ArrayList (java.util.ArrayList)6 EntityTracker (com.bergerkiller.bukkit.common.wrappers.EntityTracker)4 EntityTrackerEntryHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle)4 WorldServerHandle (com.bergerkiller.generated.net.minecraft.server.level.WorldServerHandle)4 EntityTrackerEntryStateHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)2 IntHashMapHandle (com.bergerkiller.generated.net.minecraft.util.IntHashMapHandle)2 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)2 VoxelShapeHandle (com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle)2 CraftEntityHandle (com.bergerkiller.generated.org.bukkit.craftbukkit.entity.CraftEntityHandle)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Location (org.bukkit.Location)2 ExtendedEntity (com.bergerkiller.bukkit.common.bases.ExtendedEntity)1 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)1 CommonLivingEntity (com.bergerkiller.bukkit.common.entity.type.CommonLivingEntity)1 CommonPlayer (com.bergerkiller.bukkit.common.entity.type.CommonPlayer)1 EntityTrackerHook (com.bergerkiller.bukkit.common.internal.hooks.EntityTrackerHook)1