net.minecraft.entity.data.DataTracker Java Examples

The following examples show how to use net.minecraft.entity.data.DataTracker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinDataTracker.java    From multiconnect with MIT License 6 votes vote down vote up
@Override
public void multiconnect_setEntityTo(Entity entity) {
    lock.writeLock().lock();
    this.trackedEntity = entity;
    //noinspection ConstantConditions
    Collection<DataTracker.Entry<?>> otherEntries = ((MixinDataTracker) (Object) entity.getDataTracker()).entries.values();
    Map<Integer, DataTracker.Entry<?>> oldThisEntries = new HashMap<>(this.entries);
    this.entries.clear();
    for (DataTracker.Entry<?> otherEntry : otherEntries) {
        int dataId = otherEntry.getData().getId();
        DataTracker.Entry<?> entry = oldThisEntries.getOrDefault(dataId, otherEntry);
        entries.put(dataId, entry);
        entry.setDirty(true);
    }
    dirty = true;
    lock.writeLock().unlock();
}
 
Example #2
Source File: FakePlayerEntity.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void copyPlayerModel(Entity from, Entity to)
{
	DataTracker fromTracker = from.getDataTracker();
	DataTracker toTracker = to.getDataTracker();
	Byte playerModel = fromTracker.get(PlayerEntity.PLAYER_MODEL_PARTS);
	toTracker.set(PlayerEntity.PLAYER_MODEL_PARTS, playerModel);
}
 
Example #3
Source File: DataTrackerManager.java    From multiconnect with MIT License 5 votes vote down vote up
private static void reregisterAll() {
    nextAbsentId = -1;
    NEXT_IDS.clear();
    oldTrackedData.clear();
    oldTrackedDataHandlers.clear();
    Set<Class<? extends Entity>> alreadyReregistered = new HashSet<>();
    for (Class<? extends Entity> clazz : DEFAULT_DATA.keySet()) {
        reregisterDataForClass(clazz, alreadyReregistered);
    }
    for (DataTracker tracker : trackerInstances) {
        ((IDataTracker) tracker).multiconnect_recomputeEntries();
    }
    dirty = false;
}
 
Example #4
Source File: PendingDataTrackerEntries.java    From multiconnect with MIT License 5 votes vote down vote up
public static void setEntries(int entityId, List<DataTracker.Entry<?>> entries) {
    synchronized (PendingDataTrackerEntries.entries) {
        if (entries == null) {
            PendingDataTrackerEntries.entries.remove(entityId);
        } else {
            PendingDataTrackerEntries.entries.put(entityId, entries);
        }
    }
}
 
Example #5
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
private void applyPendingEntityTrackerValues(int entityId) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_14_4) {
        List<DataTracker.Entry<?>> entries = PendingDataTrackerEntries.getEntries(entityId);
        if (entries != null) {
            PendingDataTrackerEntries.setEntries(entityId, null);
            EntityTrackerUpdateS2CPacket trackerPacket = new EntityTrackerUpdateS2CPacket();
            //noinspection ConstantConditions
            TrackerUpdatePacketAccessor trackerPacketAccessor = (TrackerUpdatePacketAccessor) trackerPacket;
            trackerPacketAccessor.setId(entityId);
            trackerPacketAccessor.setTrackedValues(entries);
            onEntityTrackerUpdate(trackerPacket);
        }
    }
}
 
Example #6
Source File: MixinDataTracker.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void multiconnect_recomputeEntries() {
    if (entries == null)
        return;
    List<DataTracker.Entry<?>> entryList = new ArrayList<>(entries.values());
    entries.clear();
    for (DataTracker.Entry entry : entryList) {
        entries.put(entry.getData().getId(), entry);
    }
}
 
Example #7
Source File: DataTrackerManager.java    From multiconnect with MIT License 4 votes vote down vote up
public static synchronized void addTrackerInstance(DataTracker instance) {
    trackerInstances.add(instance);
}
 
Example #8
Source File: PendingDataTrackerEntries.java    From multiconnect with MIT License 4 votes vote down vote up
public static List<DataTracker.Entry<?>> getEntries(int entityId) {
    synchronized (entries) {
        return entries.get(entityId);
    }
}
 
Example #9
Source File: TrackerUpdatePacketAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor
void setTrackedValues(List<DataTracker.Entry<?>> entries);
 
Example #10
Source File: EntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Mutable
@Accessor
void setDataTracker(DataTracker dataTracker);
 
Example #11
Source File: MixinDataTracker.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(Entity entity, CallbackInfo ci) {
    DataTrackerManager.addTrackerInstance((DataTracker) (Object) this);
}
 
Example #12
Source File: MixinDataTracker.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "writeEntryToPacket", at = @At("HEAD"), cancellable = true)
private static <T> void onWriteEntryToPacket(PacketByteBuf buf, DataTracker.Entry<T> entry, CallbackInfo ci) {
    if (entry.getData().getId() < 0)
        ci.cancel();
}
 
Example #13
Source File: MixinDataTracker.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "getEntry", at = @At("RETURN"))
private void assertCorrectType(TrackedData<?> requested, CallbackInfoReturnable<DataTracker.Entry<?>> ci) {
    if (ci.getReturnValue().getData().getType() != requested.getType()) {
        throw new AssertionError("getEntry returned wrong type!");
    }
}