us.myles.ViaVersion.api.minecraft.metadata.Metadata Java Examples

The following examples show how to use us.myles.ViaVersion.api.minecraft.metadata.Metadata. 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: WitherBossBar.java    From ViaRewind with MIT License 6 votes vote down vote up
private void spawnWither() {
	PacketWrapper packetWrapper = new PacketWrapper(0x0F, null, this.connection);
	packetWrapper.write(Type.VAR_INT, entityId);
	packetWrapper.write(Type.UNSIGNED_BYTE, (short)64);
	packetWrapper.write(Type.INT, (int) (locX * 32d));
	packetWrapper.write(Type.INT, (int) (locY * 32d));
	packetWrapper.write(Type.INT, (int) (locZ * 32d));
	packetWrapper.write(Type.BYTE, (byte)0);
	packetWrapper.write(Type.BYTE, (byte)0);
	packetWrapper.write(Type.BYTE, (byte)0);
	packetWrapper.write(Type.SHORT, (short)0);
	packetWrapper.write(Type.SHORT, (short)0);
	packetWrapper.write(Type.SHORT, (short)0);

	List<Metadata> metadata = new ArrayList<>();
	metadata.add(new Metadata(0, MetaType1_8.Byte, (byte) 0x20));
	metadata.add(new Metadata(2, MetaType1_8.String, title));
	metadata.add(new Metadata(3, MetaType1_8.Byte, (byte) 1));
	metadata.add(new Metadata(6, MetaType1_8.Float, health * 300f));

	packetWrapper.write(Types1_8.METADATA_LIST, metadata);

	PacketUtil.sendPacket(packetWrapper, Protocol1_8TO1_9.class, true, true);
}
 
Example #2
Source File: MetadataRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Entity ID
            if (oldMetaType != null) {
                map(oldMetaType, newMetaType);
            } else {
                map(newMetaType);
            }
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                List<Metadata> metadata = wrapper.get(newMetaType, 0);
                handleMetadata(entityId, metadata, wrapper.user());
            });
        }
    });
}
 
Example #3
Source File: MetadataRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
/**
 * Returns a packethandler to track and rewrite an entity.
 *
 * @param metaType type of the metadata list
 * @return handler for tracking and rewriting entities
 */
public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType) {
    return wrapper -> {
        int entityId = wrapper.get(Type.VAR_INT, 0);
        int type = wrapper.get(Type.VAR_INT, 1);

        int newType = getNewEntityId(type);
        if (newType != type) {
            wrapper.set(Type.VAR_INT, 1, newType);
        }

        EntityType entType = getTypeFromId(newType);
        // Register Type ID
        wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);

        if (metaType != null) {
            handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
        }
    };
}
 
Example #4
Source File: EntityTracker1_9.java    From ViaVersion with MIT License 6 votes vote down vote up
public void sendMetadataBuffer(int entityId) {
    List<Metadata> metadataList = metadataBuffer.get(entityId);
    if (metadataList != null) {
        PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
        wrapper.write(Type.VAR_INT, entityId);
        wrapper.write(Types1_9.METADATA_LIST, metadataList);
        getUser().getProtocolInfo().getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
                .handleMetadata(entityId, metadataList, getUser());
        handleMetadata(entityId, metadataList);
        if (!metadataList.isEmpty()) {
            try {
                wrapper.send(Protocol1_9To1_8.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        metadataBuffer.remove(entityId);
    }
}
 
Example #5
Source File: ShulkerReplacement.java    From ViaRewind with MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.VAR_INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==11 || metadata.getId()==12 || metadata.getId()==13) continue;
		metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue()));
	}
	metadataList.add(new Metadata(11, MetaType1_9.VarInt, 2));

	MetadataRewriter.transform(Entity1_10Types.EntityType.MAGMA_CUBE, metadataList);

	metadataPacket.write(Types1_8.METADATA_LIST, metadataList);

	PacketUtil.sendPacket(metadataPacket, Protocol1_8TO1_9.class);
}
 
Example #6
Source File: ElytraPatch.java    From ViaVersion with MIT License 6 votes vote down vote up
@Subscribe(order = PostOrder.LAST)
public void onServerConnected(ServerConnectedEvent event) {
    UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
    if (user == null) return;

    try {
        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
            int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();

            PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

            wrapper.write(Type.VAR_INT, entityId);
            wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));

            wrapper.send(Protocol1_9To1_8.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: GuardianReplacement.java    From ViaRewind with MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==16 || metadata.getId()==17) continue;
		metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue()));
	}

	MetadataRewriter.transform(Entity1_10Types.EntityType.SQUID, metadataList);

	metadataPacket.write(Types1_7_6_10.METADATA_LIST, metadataList);

	PacketUtil.sendPacket(metadataPacket, Protocol1_7_6_10TO1_8.class);
}
 
Example #8
Source File: ElytraPatch.java    From ViaVersion with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onServerConnected(ServerConnectedEvent event) {
    UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
    if (user == null) return;

    try {
        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
            int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();

            PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

            wrapper.write(Type.VAR_INT, entityId);
            wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));

            wrapper.send(Protocol1_9To1_8.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: LegacyEntityRewriter.java    From ViaBackwards with MIT License 6 votes vote down vote up
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
    return wrapper -> {
        int entityId = wrapper.get(Type.VAR_INT, 0);
        EntityType type = getEntityType(wrapper.user(), entityId);

        MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0));
        handleMeta(wrapper.user(), entityId, storage);

        EntityData entityData = getEntityData(type);
        if (entityData != null) {
            wrapper.set(Type.VAR_INT, 1, entityData.getReplacementId());
            if (entityData.hasBaseMeta()) {
                entityData.getDefaultMeta().createMeta(storage);
            }
        }

        // Rewrite Metadata
        wrapper.set(metaType, 0, storage.getMetaDataList());
    };
}
 
Example #10
Source File: MetadataListType.java    From ViaRewind with MIT License 6 votes vote down vote up
@Override
public List<Metadata> read(ByteBuf buffer) throws Exception {
	ArrayList<Metadata> list = new ArrayList();

	Metadata m;
	do {
		m = Types1_7_6_10.METADATA.read(buffer);
		if (m != null) {
			list.add(m);
		}
	} while(m != null);

	if (find(2, "Slot", list)!=null && find(8, "Slot", list)!=null) {
		list.removeIf(metadata -> metadata.getId()==2 || metadata.getId()==3);
	}

	return list;
}
 
Example #11
Source File: LegacyEntityRewriter.java    From ViaBackwards with MIT License 6 votes vote down vote up
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
    getProtocol().registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Entity ID
            if (oldMetaType != null) {
                map(oldMetaType, newMetaType);
            } else {
                map(newMetaType);
            }
            handler(wrapper -> {
                List<Metadata> metadata = wrapper.get(newMetaType, 0);
                wrapper.set(newMetaType, 0,
                        handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0), new MetaStorage(metadata)).getMetaDataList());
            });
        }
    });
}
 
Example #12
Source File: ArmorStandReplacement.java    From ViaRewind with MIT License 5 votes vote down vote up
public void updateMetadata(List<Metadata> metadataList) {
	for (Metadata metadata : metadataList) {
		datawatcher.removeIf(m -> m.getId() == metadata.getId());
		datawatcher.add(metadata);
	}
	updateState();
}
 
Example #13
Source File: MetaHandlerSettings.java    From ViaBackwards with MIT License 5 votes vote down vote up
public void handleIndexChange(final int newIndex) {
    handle(e -> {
        Metadata data = e.getData();
        data.setId(newIndex);
        return data;
    });
}
 
Example #14
Source File: MetadataListType.java    From ViaRewind with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf buffer, List<Metadata> metadata) throws Exception {
	for (Metadata meta : metadata) {
		Types1_7_6_10.METADATA.write(buffer, meta);
	}
	if (metadata.isEmpty()) {
		Types1_7_6_10.METADATA.write(buffer, new Metadata(0, MetaType1_7_6_10.Byte, (byte)0));
	}
	buffer.writeByte(127);
}
 
Example #15
Source File: MetaHandlerEvent.java    From ViaBackwards with MIT License 5 votes vote down vote up
public Metadata getMetaByIndex(int index) {
    for (Metadata meta : storage.getMetaDataList()) {
        if (index == meta.getId()) {
            return meta;
        }
    }
    return null;
}
 
Example #16
Source File: GuardianReplacement.java    From ViaRewind with MIT License 5 votes vote down vote up
public void updateMetadata(List<Metadata> metadataList) {
	for (Metadata metadata : metadataList) {
		datawatcher.removeIf(m -> m.getId()==metadata.getId());
		datawatcher.add(metadata);
	}
	updateMetadata();
}
 
Example #17
Source File: EndermiteReplacement.java    From ViaRewind with MIT License 5 votes vote down vote up
public void updateMetadata(List<Metadata> metadataList) {
	for (Metadata metadata : metadataList) {
		datawatcher.removeIf(m -> m.getId()==metadata.getId());
		datawatcher.add(metadata);
	}
	updateMetadata();
}
 
Example #18
Source File: ArmorStandReplacement.java    From ViaRewind with MIT License 5 votes vote down vote up
public void updateState() {
	byte flags = 0;
	byte armorStandFlags = 0;
	for (Metadata metadata : datawatcher) {
		if (metadata.getId() == 0 && metadata.getMetaType() == MetaType1_8.Byte) {
			flags = (byte) metadata.getValue();
		} else if (metadata.getId() == 2 && metadata.getMetaType() == MetaType1_8.String) {
			name = (String) metadata.getValue();
			if (name != null && name.equals("")) name = null;
		} else if (metadata.getId() == 10 && metadata.getMetaType() == MetaType1_8.Byte) {
			armorStandFlags = (byte) metadata.getValue();
		} else if (metadata.getId() == 3 && metadata.getMetaType() == MetaType1_8.Byte) {
			nameTagVisible = (byte) metadata.getId() != 0;
		}
	}
	invisible = (flags & 0x20) != 0;
	small = (armorStandFlags & 0x01) != 0;
	marker = (armorStandFlags & 0x10) != 0;

	State prevState = currentState;
	if (invisible && name != null) {
		currentState = State.HOLOGRAM;
	} else {
		currentState = State.ZOMBIE;
	}

	if (currentState != prevState) {
		despawn();
		spawn();
	} else {
		updateMetadata();
		updateLocation();
	}
}
 
Example #19
Source File: MetadataRewriter1_14_1To1_14.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
    if (type == null) return;

    if (type == Entity1_14Types.EntityType.VILLAGER || type == Entity1_14Types.EntityType.WANDERING_TRADER) {
        if (metadata.getId() >= 15) {
            metadata.setId(metadata.getId() + 1);
        }
    }
}
 
Example #20
Source File: MetadataRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType, EntityType entityType) {
    return wrapper -> {
        int entityId = wrapper.get(Type.VAR_INT, 0);
        // Register Type ID
        wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType);

        if (metaType != null) {
            handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
        }
    };
}
 
Example #21
Source File: MetadataRewriter1_12To1_11_1.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
    if (metadata.getValue() instanceof Item) {
        // Apply rewrite
        BedRewriter.toClientItem((Item) metadata.getValue());
    }

    if (type == null) return;
    // Evocation Illager aggressive property became 13
    if (type == Entity1_12Types.EntityType.EVOCATION_ILLAGER) {
        if (metadata.getId() == 12) {
            metadata.setId(13);
        }
    }
}
 
Example #22
Source File: Protocol1_10To1_9_3_4.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public List<Metadata> transform(PacketWrapper wrapper, List<Metadata> inputValue) throws Exception {
    List<Metadata> metaList = new CopyOnWriteArrayList<>(inputValue);
    for (Metadata m : metaList) {
        if (m.getId() >= 5)
            m.setId(m.getId() + 1);
    }
    return metaList;
}
 
Example #23
Source File: Metadata1_8Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public Metadata read(ByteBuf buffer) throws Exception {
    byte item = buffer.readByte();
    if (item == 127) return null; // end of metadata
    int typeID = (item & 0xE0) >> 5;
    MetaType1_8 type = MetaType1_8.byId(typeID);
    int id = item & 0x1F;
    return new Metadata(id, type, type.getType().read(buffer));
}
 
Example #24
Source File: AbstractMetaListType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public List<Metadata> read(final ByteBuf buffer) throws Exception {
    final Type<Metadata> type = this.getType();
    final List<Metadata> list = new ArrayList<>();
    Metadata meta;
    do {
        meta = type.read(buffer);
        if (meta != null) {
            list.add(meta);
        }
    } while (meta != null);
    return list;
}
 
Example #25
Source File: AbstractMetaListType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(final ByteBuf buffer, final List<Metadata> object) throws Exception {
    final Type<Metadata> type = this.getType();

    for (final Metadata metadata : object) {
        type.write(buffer, metadata);
    }

    this.writeEnd(type, buffer);
}
 
Example #26
Source File: ModernMetaType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public Metadata read(final ByteBuf buffer) throws Exception {
    final short index = buffer.readUnsignedByte();
    if (index == 0xff) return null; // End of metadata
    final MetaType type = this.getType(buffer.readByte());
    return new Metadata(index, type, type.getType().read(buffer));
}
 
Example #27
Source File: ModernMetaType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(final ByteBuf buffer, final Metadata object) throws Exception {
    if (object == null) {
        buffer.writeByte(0xff);
    } else {
        buffer.writeByte(object.getId());
        final MetaType type = object.getMetaType();
        buffer.writeByte(type.getTypeID());
        type.getType().write(buffer, object.getValue());
    }
}
 
Example #28
Source File: MetaStorage.java    From ViaBackwards with MIT License 5 votes vote down vote up
public Metadata getOrDefault(int index, boolean removeIfExists, Metadata data) {
    Metadata existingData = get(index);
    if (removeIfExists && existingData != null) {
        delete(existingData);
    }
    return existingData != null ? existingData : data;
}
 
Example #29
Source File: MetaStorage.java    From ViaBackwards with MIT License 5 votes vote down vote up
@Nullable
public Metadata get(int index) {
    for (Metadata meta : this.metaDataList) {
        if (index == meta.getId()) {
            return meta;
        }
    }
    return null;
}
 
Example #30
Source File: EntityTracker1_9.java    From ViaVersion with MIT License 5 votes vote down vote up
public void addMetadataToBuffer(int entityID, List<Metadata> metadataList) {
    final List<Metadata> metadata = metadataBuffer.get(entityID);
    if (metadata != null) {
        metadata.addAll(metadataList);
    } else {
        metadataBuffer.put(entityID, metadataList);
    }
}