net.minecraft.entity.data.TrackedData Java Examples

The following examples show how to use net.minecraft.entity.data.TrackedData. 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: Protocol_1_15_2.java    From multiconnect with MIT License 6 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (clazz == PersistentProjectileEntity.class && data == ProjectileEntityAccessor.getPierceLevel()) {
        DataTrackerManager.registerOldTrackedData(PersistentProjectileEntity.class, OLD_PROJECTILE_OWNER, Optional.empty(), (entity, val) -> {});
    }
    if (clazz == TameableEntity.class && data == TameableEntityAccessor.getTameableFlags()) {
        DataTrackerManager.registerOldTrackedData(TameableEntity.class, OLD_TAMEABLE_FLAGS, (byte)0, (entity, val) -> {
            byte newVal = val;
            if (entity instanceof WolfEntity) {
                ((WolfEntity) entity).setAngerTime((newVal & 2) != 0 ? 400 : 0);
                newVal = (byte) (newVal & ~2);
            }
            entity.getDataTracker().set(TameableEntityAccessor.getTameableFlags(), newVal);
        });
        return false;
    }
    if (clazz == WolfEntity.class && data == WolfEntityAccessor.getAngerTime()) {
        return false;
    }
    return super.acceptEntityData(clazz, data);
}
 
Example #2
Source File: Protocol_1_14_4.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (clazz == LivingEntity.class && data == LivingEntityAccessor.getStingerCount())
        return false;
    if (clazz == TridentEntity.class && data == TridentEntityAccessor.getHasEnchantmentGlint())
        return false;
    if (clazz == WolfEntity.class && data == WolfEntityAccessor.getBegging())
        DataTrackerManager.registerOldTrackedData(WolfEntity.class, OLD_WOLF_HEALTH, 20f, LivingEntity::setHealth);
    if (clazz == EndermanEntity.class && data == EndermanEntityAccessor.getProvoked())
        return false;

    return super.acceptEntityData(clazz, data);
}
 
Example #3
Source File: Protocol_1_11_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (clazz == PlayerEntity.class && (data == PlayerEntityAccessor.getLeftShoulderEntity() || data == PlayerEntityAccessor.getRightShoulderEntity())) {
        return false;
    }
    if (clazz == IllagerEntity.class && data == Protocol_1_13_2.OLD_ILLAGER_FLAGS) {
        return false;
    }
    return super.acceptEntityData(clazz, data);
}
 
Example #4
Source File: Protocol_1_11.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (clazz == FireworkRocketEntity.class && data == Protocol_1_13_2.OLD_FIREWORK_SHOOTER) {
        return false;
    }
    if (clazz == PigEntity.class && data == PigEntityAccessor.getBoostTime()) {
        return false;
    }
    return super.acceptEntityData(clazz, data);
}
 
Example #5
Source File: DataTrackerManager.java    From multiconnect with MIT License 5 votes vote down vote up
public static synchronized void startTrackingOldTrackedData(Entity entity) {
    for (Class<?> clazz = entity.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
        List<Pair<TrackedData<?>, ?>> trackedData = oldTrackedData.get(clazz);
        if (trackedData != null) {
            for (Pair<TrackedData<?>, ?> pair : trackedData) {
                doStartTracking(entity, pair.getLeft(), pair.getRight());
            }
        }
    }
}
 
Example #6
Source File: DataTrackerManager.java    From multiconnect with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void reregisterDataForClass(Class<? extends Entity> clazz, Set<Class<? extends Entity>> alreadyReregistered) {
    if (!alreadyReregistered.add(clazz))
        return;

    if (clazz != Entity.class)
        reregisterDataForClass((Class<? extends Entity>) clazz.getSuperclass(), alreadyReregistered);

    if (DEFAULT_DATA.containsKey(clazz))
        for (TrackedData<?> data : DEFAULT_DATA.get(clazz))
            reregisterData(clazz, data);
    ConnectionInfo.protocol.postEntityDataRegister(clazz);
}
 
Example #7
Source File: DataTrackerManager.java    From multiconnect with MIT License 5 votes vote down vote up
private static void reregisterData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (ConnectionInfo.protocol.acceptEntityData(clazz, data)) {
        int id = getNextId(clazz);
        NEXT_IDS.put(clazz, id + 1);
        ((TrackedDataAccessor) data).setId(id);
    } else {
        ((TrackedDataAccessor) data).setId(nextAbsentId--);
    }
}
 
Example #8
Source File: DataTrackerManager.java    From multiconnect with MIT License 5 votes vote down vote up
/**
 * Called from inside a protocol's acceptEntityData or postEntityDataRegister method to register an old
 * tracked data no longer in the current version. Will insert the new data before the current data being
 * checked.
 */
public static <T, U extends Entity> void registerOldTrackedData(Class<U> clazz, TrackedData<T> data, T _default, BiConsumer<? super U, ? super T> handler) {
    if (ConnectionInfo.protocol.acceptEntityData(clazz, data)) {
        int id = getNextId(clazz);
        NEXT_IDS.put(clazz, id + 1);
        ((TrackedDataAccessor) data).setId(id);
        oldTrackedData.computeIfAbsent(clazz, k -> new ArrayList<>()).add(Pair.of(data, _default));
        oldTrackedDataHandlers.put(data, handler);
    } else {
        ((TrackedDataAccessor) data).setId(nextAbsentId--);
    }
}
 
Example #9
Source File: MixinDataTracker.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "startTracking", at = @At(value = "INVOKE", target = "Ljava/lang/IllegalArgumentException;<init>(Ljava/lang/String;)V", ordinal = 2, remap = false), cancellable = true)
private <T> void allowUnregisteredTracker(TrackedData<T> data, T _default, CallbackInfo ci) {
    if (data.getId() < 0) {
        ci.cancel();
        addTrackedData(data, _default);
    }
}
 
Example #10
Source File: EvolvedCreeperEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void onTrackedDataSet(TrackedData<?> data) {
    if (BABY.equals(data)) {
        this.calculateDimensions();
    }

    super.onTrackedDataSet(data);
}
 
Example #11
Source File: EnderEyeEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("ITEM")
static TrackedData<ItemStack> getItem() {
    return MixinHelper.fakeInstance();
}
 
Example #12
Source File: CatEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("COLLAR_COLOR")
static TrackedData<Boolean> getCollarColor() {
    return MixinHelper.fakeInstance();
}
 
Example #13
Source File: FireworkEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("SHOOTER_ENTITY_ID")
static TrackedData<OptionalInt> getShooter() {
    return MixinHelper.fakeInstance();
}
 
Example #14
Source File: LivingEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("STINGER_COUNT")
static TrackedData<Integer> getStingerCount() {
    return MixinHelper.fakeInstance();
}
 
Example #15
Source File: CatEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("HEAD_DOWN")
static TrackedData<Boolean> getHeadDown() {
    return MixinHelper.fakeInstance();
}
 
Example #16
Source File: TridentEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("ENCHANTED")
static TrackedData<Boolean> getHasEnchantmentGlint() {
    return MixinHelper.fakeInstance();
}
 
Example #17
Source File: CatEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("SLEEPING_WITH_OWNER")
static TrackedData<Boolean> getSleepingWithOwner() {
    return MixinHelper.fakeInstance();
}
 
Example #18
Source File: EndermanEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("PROVOKED")
static TrackedData<Boolean> getProvoked() {
    return MixinHelper.fakeInstance();
}
 
Example #19
Source File: FireworkEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("SHOT_AT_ANGLE")
static TrackedData<Boolean> getShotAtAngle() {
    return MixinHelper.fakeInstance();
}
 
Example #20
Source File: VillagerEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("VILLAGER_DATA")
static TrackedData<VillagerData> getVillagerData() {
    return MixinHelper.fakeInstance();
}
 
Example #21
Source File: WolfEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("BEGGING")
static TrackedData<Boolean> getBegging() {
    return MixinHelper.fakeInstance();
}
 
Example #22
Source File: PigEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("BOOST_TIME")
static TrackedData<Integer> getBoostTime() {
    return MixinHelper.fakeInstance();
}
 
Example #23
Source File: Protocol_1_12_2.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (!super.acceptEntityData(clazz, data))
        return false;

    if (clazz == AreaEffectCloudEntity.class && data == AreaEffectCloudEntityAccessor.getParticleId()) {
        DataTrackerManager.registerOldTrackedData(AreaEffectCloudEntity.class,
                OLD_AREA_EFFECT_CLOUD_PARTICLE_ID,
                Registry.PARTICLE_TYPE.getRawId(ParticleTypes.ENTITY_EFFECT),
                (entity, val) -> {
            ParticleType<?> type = Registry.PARTICLE_TYPE.get(val);
            if (type == null)
                type = ParticleTypes.ENTITY_EFFECT;
            setParticleType(entity, type);
        });
        DataTrackerManager.registerOldTrackedData(AreaEffectCloudEntity.class,
                OLD_AREA_EFFECT_CLOUD_PARTICLE_PARAM1,
                0,
                (entity, val) -> {
            ((IAreaEffectCloudEntity) entity).multiconnect_setParam1(val);
            setParticleType(entity, entity.getParticleType().getType());
        });
        DataTrackerManager.registerOldTrackedData(AreaEffectCloudEntity.class,
                OLD_AREA_EFFECT_CLOUD_PARTICLE_PARAM2,
                0,
                (entity, val) -> {
            ((IAreaEffectCloudEntity) entity).multiconnect_setParam2(val);
            setParticleType(entity, entity.getParticleType().getType());
        });
        return false;
    }

    if (clazz == Entity.class && data == EntityAccessor.getCustomName()) {
        DataTrackerManager.registerOldTrackedData(Entity.class, OLD_CUSTOM_NAME, "",
                (entity, val) -> entity.setCustomName(val.isEmpty() ? null : new LiteralText(val)));
        return false;
    }

    if (clazz == BoatEntity.class && data == BoatEntityAccessor.getBubbleWobbleTicks()) {
        return false;
    }

    if (clazz == ZombieEntity.class && data == ZombieEntityAccessor.getConvertingInWater()) {
        return false;
    }

    if (clazz == AbstractMinecartEntity.class) {
        TrackedData<Integer> displayTile = AbstractMinecartEntityAccessor.getCustomBlockId();
        if (data == displayTile) {
            DataTrackerManager.registerOldTrackedData(AbstractMinecartEntity.class, OLD_MINECART_DISPLAY_TILE, 0,
                    (entity, val) -> entity.getDataTracker().set(displayTile, Blocks_1_12_2.convertToStateRegistryId(val)));
            return false;
        }
    }

    if (clazz == WolfEntity.class) {
        TrackedData<Integer> collarColor = WolfEntityAccessor.getCollarColor();
        if (data == collarColor) {
            DataTrackerManager.registerOldTrackedData(WolfEntity.class, OLD_WOLF_COLLAR_COLOR, 1,
                    (entity, val) -> entity.getDataTracker().set(collarColor, 15 - val));
            return false;
        }
    }

    return true;
}
 
Example #24
Source File: AbstractMinecartEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("CUSTOM_BLOCK_ID")
static TrackedData<Integer> getCustomBlockId() {
    return MixinHelper.fakeInstance();
}
 
Example #25
Source File: EntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("CUSTOM_NAME")
static TrackedData<Optional<Text>> getCustomName() {
    return MixinHelper.fakeInstance();
}
 
Example #26
Source File: AreaEffectCloudEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("PARTICLE_ID")
static TrackedData<ParticleEffect> getParticleId() {
    return MixinHelper.fakeInstance();
}
 
Example #27
Source File: BoatEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("BUBBLE_WOBBLE_TICKS")
static TrackedData<Integer> getBubbleWobbleTicks() {
    return MixinHelper.fakeInstance();
}
 
Example #28
Source File: WolfEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("COLLAR_COLOR")
static TrackedData<Integer> getCollarColor() {
    return MixinHelper.fakeInstance();
}
 
Example #29
Source File: MixinDataTracker.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "registerData", at = @At("RETURN"))
private static <T> void onRegisterData(Class<? extends Entity> clazz, TrackedDataHandler<T> dataType, CallbackInfoReturnable<TrackedData<T>> ci) {
    DataTrackerManager.onRegisterData(clazz, ci.getReturnValue());
}
 
Example #30
Source File: MixinDataTracker.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "startTracking", at = @At("HEAD"))
public <T> void onStartTracking(TrackedData<T> data, T _default, CallbackInfo ci) {
    DataTrackerManager.onCreateDataEntry();
}