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 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);
}
}
use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle 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.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.
the class PacketUtil method broadcastEntityPacket.
/**
* Sends a packet relating a certain entity to all players that can see it
*
* @param entity the packet is about
* @param packet to send
* @param sendToSelf whether to also send to the player itself, if the entity is a player
*/
public static void broadcastEntityPacket(Entity entity, CommonPacket packet, boolean sendToSelf) {
if (entity == null || packet == null)
return;
EntityTracker tracker = WorldUtil.getTracker(entity.getWorld());
EntityTrackerEntryHandle entry = tracker.getEntry(entity);
if (entry != null) {
for (Player viewer : entry.getViewers()) {
sendPacket(viewer, packet);
}
}
if (sendToSelf && entity instanceof Player) {
sendPacket((Player) entity, packet);
}
}
use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.
the class ItemFrameInfo method updateViewers.
/**
* Synchronizes the viewers that view this item frame.
* For every viewer that is added or removed, the synchronizer callbacks are called.
*
* @param viewerSynchronizer Synchronizer to call callbacks of
*/
public void updateViewers(LogicUtil.ItemSynchronizer<Player, Player> viewerSynchronizer) {
// Update list of players for item frames showing maps
if (lastMapUUID != null) {
if (entityTrackerEntryState == null) {
EntityTrackerEntryHandle entry = WorldUtil.getTracker(itemFrame.getWorld()).getEntry(itemFrame);
// Item Frame isn't tracked on the server, so no players can view it
if (entry == null) {
this.removed = true;
this.needsItemRefresh.set(false);
return;
}
entityTrackerEntryState = entry.getState();
entityTrackerViewers = entry.getViewers();
}
boolean changes = LogicUtil.synchronizeUnordered(viewers, entityTrackerViewers, viewerSynchronizer);
if (changes && displayInfo != null) {
displayInfo.hasFrameViewerChanges.set(true);
}
// Only do this for non-vanilla maps
if (!lastMapUUID.isStaticUUID()) {
entityTrackerEntryState.setTickCounter(1);
}
}
}
Aggregations