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