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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations