Search in sources :

Example 6 with MetaType

use of com.viaversion.viaversion.api.minecraft.metadata.MetaType in project ViaBackwards by ViaVersion.

the class EntityPackets1_17 method registerRewrites.

@Override
protected void registerRewrites() {
    filter().handler((event, meta) -> {
        meta.setMetaType(Types1_16.META_TYPES.byId(meta.metaType().typeId()));
        MetaType type = meta.metaType();
        if (type == Types1_16.META_TYPES.particleType) {
            Particle particle = (Particle) meta.getValue();
            if (particle.getId() == 16) {
                // Dust / Dust Transition
                // Remove transition target color values 4-6
                particle.getArguments().subList(4, 7).clear();
            } else if (particle.getId() == 37) {
                // Vibration Signal
                // No nice mapping possible without tracking entity positions and doing particle tasks
                particle.setId(0);
                particle.getArguments().clear();
                return;
            }
            rewriteParticle(particle);
        } else if (type == Types1_16.META_TYPES.poseType) {
            // Goat LONG_JUMP added at 6
            int pose = meta.value();
            if (pose == 6) {
                // FALL_FLYING
                meta.setValue(1);
            } else if (pose > 6) {
                meta.setValue(pose - 1);
            }
        }
    });
    // Particles have already been handled
    registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.optionalComponentType);
    mapTypes(Entity1_17Types.values(), Entity1_16_2Types.class);
    filter().type(Entity1_17Types.AXOLOTL).cancel(17);
    filter().type(Entity1_17Types.AXOLOTL).cancel(18);
    filter().type(Entity1_17Types.AXOLOTL).cancel(19);
    filter().type(Entity1_17Types.GLOW_SQUID).cancel(16);
    filter().type(Entity1_17Types.GOAT).cancel(17);
    mapEntityTypeWithData(Entity1_17Types.AXOLOTL, Entity1_17Types.TROPICAL_FISH).jsonName();
    mapEntityTypeWithData(Entity1_17Types.GOAT, Entity1_17Types.SHEEP).jsonName();
    mapEntityTypeWithData(Entity1_17Types.GLOW_SQUID, Entity1_17Types.SQUID).jsonName();
    mapEntityTypeWithData(Entity1_17Types.GLOW_ITEM_FRAME, Entity1_17Types.ITEM_FRAME);
    // TODO Handle attachment pos?
    filter().type(Entity1_17Types.SHULKER).addIndex(17);
    // Ticks frozen
    filter().removeIndex(7);
}
Also used : Particle(com.viaversion.viaversion.api.type.types.Particle) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType)

Example 7 with MetaType

use of com.viaversion.viaversion.api.minecraft.metadata.MetaType in project ViaBackwards by ViaVersion.

the class EntityPackets1_18 method registerRewrites.

@Override
protected void registerRewrites() {
    filter().handler((event, meta) -> {
        meta.setMetaType(Types1_17.META_TYPES.byId(meta.metaType().typeId()));
        MetaType type = meta.metaType();
        if (type == Types1_17.META_TYPES.particleType) {
            Particle particle = (Particle) meta.getValue();
            if (particle.getId() == 3) {
                // Block marker
                Particle.ParticleData data = particle.getArguments().remove(0);
                int blockState = (int) data.getValue();
                if (blockState == 7786) {
                    // Light block
                    particle.setId(3);
                } else {
                    // Else assume barrier block
                    particle.setId(2);
                }
                return;
            }
            rewriteParticle(particle);
        }
    });
    // Particles have already been handled
    registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, Types1_17.META_TYPES.optionalComponentType);
}
Also used : Particle(com.viaversion.viaversion.api.type.types.Particle) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType)

Example 8 with MetaType

use of com.viaversion.viaversion.api.minecraft.metadata.MetaType in project ViaBackwards by ViaVersion.

the class EntityPackets1_16 method registerRewrites.

@Override
protected void registerRewrites() {
    filter().handler((event, meta) -> {
        meta.setMetaType(Types1_14.META_TYPES.byId(meta.metaType().typeId()));
        MetaType type = meta.metaType();
        if (type == Types1_14.META_TYPES.itemType) {
            meta.setValue(protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()));
        } else if (type == Types1_14.META_TYPES.blockStateType) {
            meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
        } else if (type == Types1_14.META_TYPES.particleType) {
            rewriteParticle((Particle) meta.getValue());
        } else if (type == Types1_14.META_TYPES.optionalComponentType) {
            JsonElement text = meta.value();
            if (text != null) {
                protocol.getTranslatableRewriter().processText(text);
            }
        }
    });
    mapEntityType(Entity1_16Types.ZOMBIFIED_PIGLIN, Entity1_15Types.ZOMBIE_PIGMAN);
    mapTypes(Entity1_16Types.values(), Entity1_15Types.class);
    mapEntityTypeWithData(Entity1_16Types.HOGLIN, Entity1_16Types.COW).jsonName();
    mapEntityTypeWithData(Entity1_16Types.ZOGLIN, Entity1_16Types.COW).jsonName();
    mapEntityTypeWithData(Entity1_16Types.PIGLIN, Entity1_16Types.ZOMBIFIED_PIGLIN).jsonName();
    mapEntityTypeWithData(Entity1_16Types.STRIDER, Entity1_16Types.MAGMA_CUBE).jsonName();
    filter().type(Entity1_16Types.ZOGLIN).cancel(16);
    filter().type(Entity1_16Types.HOGLIN).cancel(15);
    filter().type(Entity1_16Types.PIGLIN).cancel(16);
    filter().type(Entity1_16Types.PIGLIN).cancel(17);
    filter().type(Entity1_16Types.PIGLIN).cancel(18);
    filter().type(Entity1_16Types.STRIDER).index(15).handler((event, meta) -> {
        boolean baby = meta.value();
        meta.setTypeAndValue(Types1_14.META_TYPES.varIntType, baby ? 1 : 3);
    });
    filter().type(Entity1_16Types.STRIDER).cancel(16);
    filter().type(Entity1_16Types.STRIDER).cancel(17);
    filter().type(Entity1_16Types.STRIDER).cancel(18);
    filter().type(Entity1_16Types.FISHING_BOBBER).cancel(8);
    filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).cancel(8);
    filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).handler((event, meta) -> {
        if (event.index() >= 8) {
            event.setIndex(event.index() + 1);
        }
    });
    filter().type(Entity1_16Types.WOLF).index(16).handler((event, meta) -> {
        byte mask = meta.value();
        StoredEntityData data = tracker(event.user()).entityData(event.entityId());
        data.put(new WolfDataMaskStorage(mask));
    });
    filter().type(Entity1_16Types.WOLF).index(20).handler((event, meta) -> {
        StoredEntityData data = tracker(event.user()).entityDataIfPresent(event.entityId());
        byte previousMask = 0;
        if (data != null) {
            WolfDataMaskStorage wolfData = data.get(WolfDataMaskStorage.class);
            if (wolfData != null) {
                previousMask = wolfData.tameableMask();
            }
        }
        int angerTime = meta.value();
        byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3);
        event.createExtraMeta(new Metadata(16, Types1_14.META_TYPES.byteType, tameableMask));
        event.cancel();
    });
}
Also used : Item(com.viaversion.viaversion.api.minecraft.item.Item) WolfDataMaskStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.WolfDataMaskStorage) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType)

Example 9 with MetaType

use of com.viaversion.viaversion.api.minecraft.metadata.MetaType in project ViaVersion by ViaVersion.

the class OldMetaType method read.

@Override
public Metadata read(final ByteBuf buffer) throws Exception {
    final byte index = buffer.readByte();
    // End of metadata
    if (index == END)
        return null;
    final MetaType type = this.getType((index & 224) >> 5);
    return new Metadata(index & 31, type, type.type().read(buffer));
}
Also used : Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType)

Aggregations

MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)9 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)5 Particle (com.viaversion.viaversion.api.type.types.Particle)3 Item (com.viaversion.viaversion.api.minecraft.item.Item)2 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)1 EntityData (com.viaversion.viabackwards.api.entities.storage.EntityData)1 EntityPositionHandler (com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler)1 LegacyEntityRewriter (com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter)1 Protocol1_13_2To1_14 (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14)1 ChunkLightStorage (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage)1 DifficultyStorage (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage)1 EntityPositionStorage1_14 (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14)1 WolfDataMaskStorage (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.WolfDataMaskStorage)1 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)1 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)1 EulerAngle (com.viaversion.viaversion.api.minecraft.EulerAngle)1 Position (com.viaversion.viaversion.api.minecraft.Position)1 Vector (com.viaversion.viaversion.api.minecraft.Vector)1 VillagerData (com.viaversion.viaversion.api.minecraft.VillagerData)1 Entity1_13Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types)1