Search in sources :

Example 1 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityAddRemoveHandler_1_17 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 2 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityTrackerEntryHook_1_8_to_1_13_2 method hideForAll.

@HookMethod("public void hideForAll:???()")
public void hideForAll() {
    try {
        controller.makeHiddenForAll();
        // This is usually only called when the entity tracker entry is removed from the mapping
        // Detect that it is, and if it is, call onDetached() on the network controller
        CommonEntity<?> entity = controller.getEntity();
        if (entity != null) {
            World world = entity.getWorld();
            EntityTrackerEntryHandle eh = EntityTrackerEntryHandle.createHandle(instance());
            if (world != null && !WorldUtil.getTracker(world).containsEntry(eh)) {
                controller.bind(null, null);
            }
        }
    } catch (Throwable t) {
        Logging.LOGGER_NETWORK.log(Level.SEVERE, "Failed to hide for all viewers", t);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) World(org.bukkit.World)

Example 3 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityTypingHandler_1_8 method createEntityTrackerEntry.

@Override
public EntityTrackerEntryHandle createEntityTrackerEntry(EntityTracker entityTracker, Entity entity) {
    EntityTrackerEntryHandle createdEntry = null;
    try {
        // Reset
        this.entriesSet.clear();
        this.entriesMap.clear();
        // Track it!
        dummyTracker.setTrackingDistance((Bukkit.getViewDistance() - 1) * 16);
        dummyTracker.trackEntity(entity);
        // Retrieve it from the mapping
        List<IntHashMap.Entry<Object>> entries = this.entriesMap.entries();
        if (!entries.isEmpty()) {
            createdEntry = EntityTrackerEntryHandle.createHandle(entries.get(0).getValue());
        } else {
            Logging.LOGGER_REFLECTION.once(Level.WARNING, "No dummy entry created for " + entity.getName() + ", resolving to defaults");
        }
    } catch (Throwable t) {
        Logging.LOGGER_REFLECTION.once(Level.SEVERE, "Failed to create dummy entry", t);
    }
    if (createdEntry == null) {
        Object nmsEntity = HandleConversion.toEntityHandle(entity);
        createdEntry = EntityTrackerEntryHandle.createHandle(this.fallbackConstructor.invoke(null, nmsEntity, 80, (Bukkit.getViewDistance() - 1) * 16, 3, // defaults
        true));
    }
    // We must do this so that the next updatePlayer() update is properly synchronized
    if (EntityTrackerEntryStateHandle.T.opt_passengers.isAvailable()) {
        EntityTrackerEntryStateHandle.T.opt_passengers.set(createdEntry.getRaw(), (new ExtendedEntity<Entity>(entity)).getPassengers());
    }
    // We must do this so that the next updatePlayer() update is properly synchronized
    if (EntityTrackerEntryStateHandle.T.opt_vehicle.isAvailable()) {
        EntityTrackerEntryStateHandle.T.opt_vehicle.set(createdEntry.getRaw(), entity.getVehicle());
    }
    return createdEntry;
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) Entity(org.bukkit.entity.Entity) ExtendedEntity(com.bergerkiller.bukkit.common.bases.ExtendedEntity)

Example 4 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityTypingHandler_1_14 method createEntityTrackerEntry.

@Override
public EntityTrackerEntryHandle createEntityTrackerEntry(EntityTracker entityTracker, Entity entity) {
    Object handle = _handler.createEntry(entityTracker.getRawHandle(), HandleConversion.toEntityHandle(entity));
    EntityTrackerEntryHandle entry = EntityTrackerEntryHandle.createHandle(handle);
    // Set the passengers field to the current passengers
    EntityTrackerEntryStateHandle.T.opt_passengers.set(entry.getState().getRaw(), (new ExtendedEntity<Entity>(entity)).getPassengers());
    return entry;
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) Entity(org.bukkit.entity.Entity) ExtendedEntity(com.bergerkiller.bukkit.common.bases.ExtendedEntity)

Example 5 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityTrackerEntryHook_1_14 method hideForAll.

@HookMethod("public void hideForAll:???()")
public void hideForAll() {
    try {
        controller.makeHiddenForAll();
        // This is usually only called when the entity tracker entry is removed from the mapping
        // Detect that it is, and if it is, call onDetached() on the network controller
        CommonEntity<?> entity = controller.getEntity();
        if (entity != null) {
            World world = entity.getWorld();
            EntityTrackerEntryHandle eh = EntityTrackerEntryHandle.createHandle(instance());
            if (world != null && !WorldUtil.getTracker(world).containsEntry(eh)) {
                controller.bind(null, null);
            }
        }
    } catch (Throwable t) {
        Logging.LOGGER_NETWORK.log(Level.SEVERE, "Failed to hide for all viewers:");
        t.printStackTrace();
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) World(org.bukkit.World)

Aggregations

EntityTrackerEntryHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle)11 EntityTracker (com.bergerkiller.bukkit.common.wrappers.EntityTracker)5 EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)4 ArrayList (java.util.ArrayList)4 Entity (org.bukkit.entity.Entity)3 ExtendedEntity (com.bergerkiller.bukkit.common.bases.ExtendedEntity)2 CommonPacket (com.bergerkiller.bukkit.common.protocol.CommonPacket)2 EntityTrackerEntryStateHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 World (org.bukkit.World)2 CommonPlayer (com.bergerkiller.bukkit.common.entity.type.CommonPlayer)1 EntityTrackerEntryHook (com.bergerkiller.bukkit.common.internal.hooks.EntityTrackerEntryHook)1 org.bukkit.entity (org.bukkit.entity)1 Player (org.bukkit.entity.Player)1