Search in sources :

Example 1 with EntityTrackerEntryStateHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle 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 EntityTrackerEntryStateHandle

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

the class EntityTrackerEntryHook_1_8_to_1_13_2 method track.

@HookMethod("public void track(List<EntityHuman> list)")
public void track(List<?> list) {
    EntityTrackerEntryStateHandle handle = EntityTrackerEntryStateHandle.createHandle(instance());
    if (handle.checkTrackNeeded()) {
        scanPlayers(list);
    }
    handle.setTimeSinceLocationSync(handle.getTimeSinceLocationSync() + 1);
    try {
        controller.onTick();
    } catch (Throwable t) {
        Logging.LOGGER_NETWORK.log(Level.SEVERE, "Failed to synchronize", t);
    }
    handle.setTickCounter(handle.getTickCounter() + 1);
}
Also used : EntityTrackerEntryStateHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)

Example 3 with EntityTrackerEntryStateHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle 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 4 with EntityTrackerEntryStateHandle

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

the class CommonEntity method copyEntityTrackerEntry.

private static void copyEntityTrackerEntry(EntityTrackerEntryHandle from, EntityTrackerEntryHandle to) {
    if (EntityTrackerEntryHandle.T.getType() == EntityTrackerEntryStateHandle.T.getType()) {
        // Pre-1.14: same class
        EntityTrackerEntryHandle.T.copyHandle(from, to);
    } else {
        // Post-1.14: got to copy state separately
        // Make sure to preserve the state field in the EntityTrackerEntry!
        EntityTrackerEntryStateHandle to_state = to.getState();
        EntityTrackerEntryHandle.T.copyHandle(from, to);
        EntityTrackerEntryHandle.T.setState.invoke(to.getRaw(), to_state);
        // Copy state too. Preserve the 'broadcast()' lambda, as it refers to the entry we want to keep!
        java.util.function.Consumer<?> to_state_broadcastMethod = EntityTrackerEntryStateHandle.T.broadcastMethod.get(to_state.getRaw());
        EntityTrackerEntryStateHandle.T.copyHandle(from.getState(), to_state);
        EntityTrackerEntryStateHandle.T.broadcastMethod.set(to_state.getRaw(), to_state_broadcastMethod);
    }
}
Also used : EntityTrackerEntryStateHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)

Aggregations

EntityTrackerEntryStateHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)4 EntityTracker (com.bergerkiller.bukkit.common.wrappers.EntityTracker)2 EntityTrackerEntryHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle)2 EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2