Java Code Examples for us.myles.ViaVersion.api.minecraft.metadata.Metadata#getValue()

The following examples show how to use us.myles.ViaVersion.api.minecraft.metadata.Metadata#getValue() . 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: MetadataRewriter1_16To1_15_2.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
    if (metadata.getMetaType() == MetaType1_14.Slot) {
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
        int data = (int) metadata.getValue();
        metadata.setValue(Protocol1_16To1_15_2.getNewBlockStateId(data));
    }

    if (type == null) return;

    if (type == Entity1_16Types.EntityType.AREA_EFFECT_CLOUD) {
        if (metadata.getId() == 10) {
            Particle particle = (Particle) metadata.getValue();
            particle.setId(WorldPackets.getNewParticleId(particle.getId()));
        }
    } else if (type.isOrHasParent(Entity1_16Types.EntityType.ABSTRACT_ARROW)) {
        if (metadata.getId() == 8) {
            metadatas.remove(metadata);
        } else if (metadata.getId() > 8) {
            metadata.setId(metadata.getId() - 1);
        }
    }
}
 
Example 2
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 3
Source File: MetadataRewriter1_15To1_14_4.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) throws Exception {
    if (metadata.getMetaType() == MetaType1_14.Slot) {
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
        // Convert to new block id
        int data = (int) metadata.getValue();
        metadata.setValue(Protocol1_15To1_14_4.getNewBlockStateId(data));
    }

    if (type == null) return;

    // Metadata 12 added to abstract_living
    if (metadata.getId() > 11 && type.isOrHasParent(Entity1_15Types.EntityType.LIVINGENTITY)) {
        metadata.setId(metadata.getId() + 1); //TODO is it 11 or 12? what is it for?
    }

    //NOTES:
    //new boolean with id 11 for trident, default = false, added in 19w45a
    //new boolean with id 17 for enderman

    if (type.isOrHasParent(Entity1_15Types.EntityType.WOLF)) {
        if (metadata.getId() == 18) {
            metadatas.remove(metadata);
        } else if (metadata.getId() > 18) {
            metadata.setId(metadata.getId() - 1);
        }
    }
}
 
Example 4
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 5
Source File: MetadataRewriter.java    From ViaRewind with MIT License 4 votes vote down vote up
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
	for (Metadata entry : new ArrayList<>(list)) {
		MetaIndex1_8to1_7_6_10 metaIndex = MetaIndex1_7_6_10to1_8.searchIndex(type, entry.getId());
		try {
			if (metaIndex == null) throw new Exception("Could not find valid metadata");
			if (metaIndex.getOldType() == MetaType1_7_6_10.NonExistent) {
				list.remove(entry);
				continue;
			}
			Object value = entry.getValue();
			if (!value.getClass().isAssignableFrom(metaIndex.getNewType().getType().getOutputClass())) {
				list.remove(entry);
				continue;
			}
			entry.setMetaType(metaIndex.getOldType());
			entry.setId(metaIndex.getIndex());
			switch (metaIndex.getOldType()) {
				case Int:
					if (metaIndex.getNewType() == MetaType1_8.Byte) {
						entry.setValue(((Byte) value).intValue());
						if (metaIndex==MetaIndex1_8to1_7_6_10.ENTITY_AGEABLE_AGE) {
							if ((Integer) entry.getValue() < 0) {
								entry.setValue(-25000);
							}
						}
					}
					if (metaIndex.getNewType() == MetaType1_8.Short) {
						entry.setValue(((Short) value).intValue());
					}
					if (metaIndex.getNewType() == MetaType1_8.Int) {
						entry.setValue(value);
					}
					break;
				case Byte:
					if (metaIndex.getNewType() == MetaType1_8.Int) {
						entry.setValue(((Integer) value).byteValue());
					}
					if (metaIndex.getNewType() == MetaType1_8.Byte) {
						if (metaIndex==MetaIndex1_8to1_7_6_10.ITEM_FRAME_ROTATION) {
							value = (Byte)((Integer)((Byte)value / 2)).byteValue();
						}
						entry.setValue(value);
					}
					if (metaIndex==MetaIndex1_8to1_7_6_10.HUMAN_SKIN_FLAGS) {
						byte flags = (byte) value;
						boolean cape = (flags & 0x01) != 0;
						flags = (byte) (cape ? 0x00 : 0x02);
						entry.setValue(flags);
					}
					break;
				case Slot:
					entry.setValue(ItemRewriter.toClient((Item) value));
					break;
				case Float:
					entry.setValue(value);
					break;
				case Short:
					entry.setValue(value);
					break;
				case String:
					entry.setValue(value);
					break;
				case Position:
					entry.setValue(value);
					break;
				default:
					ViaRewind.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
					list.remove(entry);
					break;
			}
		} catch (Exception e) {
			list.remove(entry);
		}
	}
}
 
Example 6
Source File: MetadataRewriter.java    From ViaRewind with MIT License 4 votes vote down vote up
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
	for (Metadata entry : new ArrayList<>(list)) {
		MetaIndex metaIndex = MetaIndex1_8to1_9.searchIndex(type, entry.getId());
		try {
			if (metaIndex != null) {
				if (metaIndex.getOldType() == MetaType1_8.NonExistent || metaIndex.getNewType()==MetaType1_9.Discontinued) {
					list.remove(entry);
					continue;
				}
				Object value = entry.getValue();
				entry.setMetaType(metaIndex.getOldType());
				entry.setId(metaIndex.getIndex());
				switch (metaIndex.getNewType()) {
					case Byte:
						if (metaIndex.getOldType() == MetaType1_8.Byte) {
							entry.setValue(value);
						}
						if (metaIndex.getOldType() == MetaType1_8.Int) {
							entry.setValue(((Byte) value).intValue());
						}
						break;
					case OptUUID:
						if (metaIndex.getOldType()!=MetaType1_8.String) {
							list.remove(entry);
							break;
						}
						UUID owner = (UUID) value;
						if (owner == null) entry.setValue("");
						else entry.setValue(owner.toString());
						break;
					case BlockID:
						int combined = (Integer) value;
						int id = combined >> 4;
						int data = combined & 0xF;
						list.remove(entry);
						list.add(new Metadata(metaIndex.getIndex(), MetaType1_8.Short, (short)id));
						list.add(new Metadata(metaIndex.getIndex(), MetaType1_8.Byte, (byte)data));
						break;
					case VarInt:
						if (metaIndex.getOldType() == MetaType1_8.Byte) {
							entry.setValue(((Integer) value).byteValue());
						}
						if (metaIndex.getOldType() == MetaType1_8.Short) {
							entry.setValue(((Integer) value).shortValue());
						}
						if (metaIndex.getOldType() == MetaType1_8.Int) {
							entry.setValue(value);
						}
						break;
					case Float:
						entry.setValue(value);
						break;
					case String:
						entry.setValue(value);
						break;
					case Boolean:
						if (metaIndex == MetaIndex.AGEABLE_AGE) entry.setValue((byte)((Boolean) value ? -1 : 0));
						else entry.setValue((byte)((Boolean) value ? 1 : 0));
						break;
					case Slot:
						entry.setValue(ItemRewriter.toClient((Item) value));
						break;
					case Position:
						Vector vector = (Vector) value;
						entry.setValue(vector);
						break;
					case Vector3F:
						EulerAngle angle = (EulerAngle) value;
						entry.setValue(angle);
						break;
					case Chat:
						entry.setValue(value);
						break;
					default:
						ViaRewind.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
						list.remove(entry);
						break;
				}

				if (!metaIndex.getOldType().getType().getOutputClass().isAssignableFrom(entry.getValue().getClass())) {
					list.remove(entry);
				}

			} else {
				throw new Exception("Could not find valid metadata");
			}
		} catch (Exception e) {
			list.remove(entry);
		}
	}
}
 
Example 7
Source File: MetadataRewriter1_13To1_12_2.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
    // Handle new MetaTypes
    if (metadata.getMetaType().getTypeID() > 4) {
        metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
    } else {
        metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID()));
    }

    // Handle String -> Chat DisplayName
    if (metadata.getId() == 2) {
        metadata.setMetaType(MetaType1_13.OptChat);
        if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
            metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
        } else {
            metadata.setValue(null);
        }
    }

    // 1.13 changed item to flat item (no data)
    if (metadata.getMetaType() == MetaType1_13.Slot) {
        metadata.setMetaType(MetaType1_13.Slot);
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_13.BlockID) {
        // Convert to new block id
        metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
    }

    // Skip type related changes when the type is null
    if (type == null) return;

    // Handle new colors
    if (type == Entity1_13Types.EntityType.WOLF && metadata.getId() == 17) {
        metadata.setValue(15 - (int) metadata.getValue());
    }

    // Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
    if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) {
        if (metadata.getId() > 14)
            metadata.setId(metadata.getId() + 1);
    }

    // Handle Minecart inner block
    if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
        // New block format
        int oldId = (int) metadata.getValue();
        int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
        int newId = WorldPackets.toNewId(combined);
        metadata.setValue(newId);
    }

    // Handle other changes
    if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) {
        if (metadata.getId() == 9) {
            int particleId = (int) metadata.getValue();
            int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
            int parameter2 = metadataMap.containsKey(11) ? (int) metadataMap.get(11).getValue() : 0;

            Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
            if (particle != null && particle.getId() != -1) {
                metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
            }
        }

        if (metadata.getId() >= 9)
            metadatas.remove(metadata); // Remove
    }

    if (metadata.getId() == 0) {
        metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
    }

    // TODO: Boat has changed
}