Search in sources :

Example 1 with ParrotStorage

use of com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage in project ViaBackwards by ViaVersion.

the class EntityPackets1_12 method registerRewrites.

@Override
protected void registerRewrites() {
    mapEntityTypeWithData(Entity1_12Types.EntityType.PARROT, Entity1_12Types.EntityType.BAT).plainName().spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
    mapEntityTypeWithData(Entity1_12Types.EntityType.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).plainName();
    // Handle Illager
    filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).cancel(12);
    filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);
    filter().type(Entity1_12Types.EntityType.ILLUSION_ILLAGER).index(0).handler((event, meta) -> {
        byte mask = (byte) meta.getValue();
        if ((mask & 0x20) == 0x20) {
            mask &= ~0x20;
        }
        meta.setValue(mask);
    });
    // Create Parrot storage
    filter().filterFamily(Entity1_12Types.EntityType.PARROT).handler((event, meta) -> {
        StoredEntityData data = storedEntityData(event);
        if (!data.has(ParrotStorage.class)) {
            data.put(new ParrotStorage());
        }
    });
    // Parrot remove animal metadata
    // Is baby
    filter().type(Entity1_12Types.EntityType.PARROT).cancel(12);
    filter().type(Entity1_12Types.EntityType.PARROT).index(13).handler((event, meta) -> {
        StoredEntityData data = storedEntityData(event);
        ParrotStorage storage = data.get(ParrotStorage.class);
        boolean isSitting = (((byte) meta.getValue()) & 0x01) == 0x01;
        boolean isTamed = (((byte) meta.getValue()) & 0x04) == 0x04;
        if (!storage.isTamed() && isTamed) {
        // TODO do something to let the user know it's done
        }
        storage.setTamed(isTamed);
        if (isSitting) {
            event.setIndex(12);
            meta.setValue((byte) 0x01);
            storage.setSitting(true);
        } else if (storage.isSitting()) {
            event.setIndex(12);
            meta.setValue((byte) 0x00);
            storage.setSitting(false);
        } else {
            event.cancel();
        }
    });
    // Flags (Is sitting etc, might be useful in the future
    // Owner
    filter().type(Entity1_12Types.EntityType.PARROT).cancel(14);
    // Variant
    filter().type(Entity1_12Types.EntityType.PARROT).cancel(15);
    // Left shoulder entity data
    filter().type(Entity1_12Types.EntityType.PLAYER).index(15).handler((event, meta) -> {
        CompoundTag tag = (CompoundTag) meta.getValue();
        ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
        if (tag.isEmpty() && tracker.getLeftShoulder() != null) {
            tracker.setLeftShoulder(null);
            tracker.update();
        } else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
            String id = (String) tag.get("id").getValue();
            if (tracker.getLeftShoulder() == null || !tracker.getLeftShoulder().equals(id)) {
                tracker.setLeftShoulder(id);
                tracker.update();
            }
        }
        event.cancel();
    });
    // Right shoulder entity data
    filter().type(Entity1_12Types.EntityType.PLAYER).index(16).handler((event, meta) -> {
        CompoundTag tag = (CompoundTag) event.meta().getValue();
        ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
        if (tag.isEmpty() && tracker.getRightShoulder() != null) {
            tracker.setRightShoulder(null);
            tracker.update();
        } else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
            String id = (String) tag.get("id").getValue();
            if (tracker.getRightShoulder() == null || !tracker.getRightShoulder().equals(id)) {
                tracker.setRightShoulder(id);
                tracker.update();
            }
        }
        event.cancel();
    });
}
Also used : ShoulderTracker(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ParrotStorage(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage)

Aggregations

ParrotStorage (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage)1 ShoulderTracker (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker)1 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)1 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)1 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)1