Verified Commit 25df5b07 authored by Bixilon's avatar Bixilon
Browse files

introduce versionIds (replace protocolIds for must stuff) to handle recent...

introduce versionIds (replace protocolIds for must stuff) to handle recent changes in protocol versioning
parent 40e3c9f4
Pipeline #178 passed with stage
in 1 minute and 19 seconds
# Minecraft Versions
Once mojang releases a new minecraft version, you need to add the version to the [versions.json](/src/main/resources/assets/mapping/versions.json).
The file is a huge json object, see below:
```json
{
"<Version ID>": {
"name": "<Version Name>",
"mapping": <Id>,
"protocolId": <Protocol Id>,
}
}
```
The json key is custom one, normally the same as the protocol id (if so, you can omit the versionId field).
Because Mojang needed to change the versionIds in 1.16.4-pre1 (["New network protocol scheme, with a high bit (bit 30) set for snapshots. The protocol version will increase by 1 for each snapshot, but full releases may keep the same protocol version as the previous full release in cases where the network protocols are compatible"](https://www.minecraft.net/en-us/article/minecraft-1-16-4-pre-release-1)),
I needed to change the version Ids. The version id will now increment for each version/snapshot, but only if the protocol id changes too.
Used for sorting and even more important: Multi protocol support. The number simply is bigger if the version is newer.
## Example
```json
{
"753": {
"name": "1.16.3",
"mapping": 740
}
}
```
## Mapping
Mapping can be an int, if so the version mapping of the corresponding version will be used. If one packet is added, removed, shifted, or simply it's id changes,
you need to provide the full packet mapping. The id depends on the order.
---
Note: Do not check for protocolIds (especially in EntityMetaData or Packets), this data is not reliable! Use version Ids.
\ No newline at end of file
......@@ -22,12 +22,12 @@ public class ChangeableIdentifier extends VersionValueMap<String> {
String mod = "minecraft";
public ChangeableIdentifier(String legacy, String water) {
values.put(Versions.getLowestVersionSupported().getProtocolVersion(), legacy);
values.put(Versions.getLowestVersionSupported().getVersionId(), legacy);
values.put(ProtocolDefinition.FLATTING_VERSION_ID, water);
}
public ChangeableIdentifier(String legacy, String water, String mod) {
values.put(Versions.getLowestVersionSupported().getProtocolVersion(), legacy);
values.put(Versions.getLowestVersionSupported().getVersionId(), legacy);
values.put(ProtocolDefinition.FLATTING_VERSION_ID, water);
this.mod = mod;
}
......@@ -44,7 +44,7 @@ public class ChangeableIdentifier extends VersionValueMap<String> {
super(name);
}
public boolean isValidName(String name, int protocolId) {
public boolean isValidName(String name, int versionId) {
name = name.toLowerCase();
if (name.indexOf(":") != 0) {
String[] splittedName = name.split(":", 2);
......@@ -56,6 +56,6 @@ public class ChangeableIdentifier extends VersionValueMap<String> {
// split and check mod
}
return get(protocolId).equals(name);
return get(versionId).equals(name);
}
}
......@@ -158,16 +158,16 @@ public class Player {
return inventories.get(id);
}
public Slot getSlot(int windowId, InventorySlots.InventoryInterface slot, int protocolId) {
return getSlot(windowId, slot.getId(protocolId));
public Slot getSlot(int windowId, InventorySlots.InventoryInterface slot, int versionId) {
return getSlot(windowId, slot.getId(versionId));
}
public Slot getSlot(int windowId, int slot) {
return inventories.get(windowId).getSlot(slot);
}
public void setSlot(int windowId, InventorySlots.InventoryInterface slot, int protocolId, Slot data) {
setSlot(windowId, slot.getId(protocolId), data);
public void setSlot(int windowId, InventorySlots.InventoryInterface slot, int versionId, Slot data) {
setSlot(windowId, slot.getId(versionId), data);
}
public void createInventory(InventoryProperties properties) {
......
......@@ -31,11 +31,11 @@ public class VersionValueMap<V> {
}
public VersionValueMap(V value) {
values.put(Versions.getLowestVersionSupported().getProtocolVersion(), value);
values.put(Versions.getLowestVersionSupported().getVersionId(), value);
}
public V get(int protocolId) {
Map.Entry<Integer, V> value = values.lowerEntry(protocolId);
public V get(int versionId) {
Map.Entry<Integer, V> value = values.lowerEntry(versionId);
if (value == null) {
return null;
}
......
......@@ -21,9 +21,9 @@ public class VillagerData {
final VillagerProfessions profession;
final VillagerLevels level;
public VillagerData(int type, int profession, int level, int protocolId) {
public VillagerData(int type, int profession, int level, int versionId) {
this.type = VillagerTypes.byId(type);
this.profession = VillagerProfessions.byId(profession, protocolId);
this.profession = VillagerProfessions.byId(profession, versionId);
this.level = VillagerLevels.byId(level);
}
......@@ -61,17 +61,17 @@ public class VillagerData {
valueMap = new VersionValueMap<>(values, true);
}
public static VillagerProfessions byId(int id, int protocolId) {
public static VillagerProfessions byId(int id, int versionId) {
for (VillagerProfessions profession : values()) {
if (profession.getId(protocolId) == id) {
if (profession.getId(versionId) == id) {
return profession;
}
}
return null;
}
public int getId(int protocolId) {
return valueMap.get(protocolId);
public int getId(int versionId) {
return valueMap.get(versionId);
}
}
......
......@@ -17,13 +17,13 @@ import java.util.UUID;
public abstract class AbstractArrowMetaData extends EntityMetaData {
public AbstractArrowMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractArrowMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean isCritical() {
final boolean defaultValue = false;
if (protocolId < 57) {
if (versionId < 57) {
return sets.getBoolean(16, defaultValue);
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x01, defaultValue);
......@@ -37,10 +37,10 @@ public abstract class AbstractArrowMetaData extends EntityMetaData {
@Nullable
public UUID getShooterUUID() {
final UUID defaultValue = null;
if (protocolId < 394) {
if (versionId < 394) {
return defaultValue;
}
if (protocolId >= 743) { //ToDo
if (versionId >= 743) { //ToDo
return defaultValue;
}
return sets.getUUID(super.getLastDataIndex() + 2, defaultValue);
......@@ -48,7 +48,7 @@ public abstract class AbstractArrowMetaData extends EntityMetaData {
public byte getPeircingLevel() {
final byte defaultValue = 0;
if (protocolId < 440) {
if (versionId < 440) {
return defaultValue;
}
return sets.getByte(super.getLastDataIndex() + 3, defaultValue);
......@@ -56,15 +56,15 @@ public abstract class AbstractArrowMetaData extends EntityMetaData {
@Override
protected int getLastDataIndex() {
if (protocolId < 450) {
if (versionId < 450) {
return super.getLastDataIndex() + 1;
}
// ToDo
/*if ( protocolId == 401) { // ToDo (440?)
/*if ( versionId == 401) { // ToDo (440?)
return super.getLastDataIndex() + 2;
}
*/
if (protocolId < 743) { //ToDo
if (versionId < 743) { //ToDo
return super.getLastDataIndex() + 3;
}
return super.getLastDataIndex() + 2;
......
......@@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AbstractFireballMetaData extends EntityMetaData {
public AbstractFireballMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractFireballMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
}
......@@ -14,13 +14,13 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AbstractFishMetaData extends WaterMobMetaData {
public AbstractFishMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractFishMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean fromBucket() {
final boolean defaultValue = false;
if (protocolId < 362) {
if (versionId < 362) {
return defaultValue;
}
return sets.getBoolean(super.getLastDataIndex() + 1, defaultValue);
......
......@@ -17,8 +17,8 @@ import java.util.UUID;
public abstract class AbstractHorseMetaData extends AnimalMetaData {
public AbstractHorseMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractHorseMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean isTame() {
......@@ -26,10 +26,10 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
}
private boolean isOptionBitMask(int bitMask, boolean defaultValue) {
if (protocolId < 335) { //ToDo
if (versionId < 335) { //ToDo
bitMask *= 2;
}
if (protocolId < 57) {
if (versionId < 57) {
return sets.getBitMask(16, bitMask, defaultValue);
}
return sets.getBitMask(super.getLastDataIndex() + 1, bitMask, defaultValue);
......@@ -57,10 +57,10 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
public HorseTypes getType() {
final int defaultValue = HorseTypes.HORSE.ordinal();
if (protocolId < 57) {
if (versionId < 57) {
return HorseTypes.byId(sets.getInt(19, defaultValue));
}
if (protocolId < 204) {
if (versionId < 204) {
return HorseTypes.byId(sets.getInt(super.getLastDataIndex() + 1, defaultValue));
}
return HorseTypes.byId(defaultValue);
......@@ -68,7 +68,7 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
@Nullable
public String getOwnerName() {
if (protocolId < 57) { //ToDo
if (versionId < 57) { //ToDo
return sets.getString(21, null);
}
return null;
......@@ -77,13 +77,13 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
@Nullable
public UUID getOwnerUUID() {
final UUID defaultValue = null;
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return null;
}
if (protocolId == 110) { //ToDo
if (versionId == 110) { //ToDo
return sets.getUUID(15, defaultValue);
}
if (protocolId == 204) { //ToDo
if (versionId == 204) { //ToDo
return sets.getUUID(16, defaultValue);
}
return sets.getUUID(super.getLastDataIndex() + 1, defaultValue);
......
......@@ -14,13 +14,13 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AbstractIllagerMetaData extends RaidParticipantMetaData {
public AbstractIllagerMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractIllagerMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean hasTarget() {
final boolean defaultValue = false;
if (protocolId < 335) { //ToDo
if (versionId < 335) { //ToDo
return defaultValue;
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x01, defaultValue);
......@@ -28,7 +28,7 @@ public abstract class AbstractIllagerMetaData extends RaidParticipantMetaData {
@Override
protected int getLastDataIndex() {
if (protocolId < 335) { //ToDo
if (versionId < 335) { //ToDo
return super.getLastDataIndex();
}
return super.getLastDataIndex() + 1;
......
......@@ -14,13 +14,13 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AbstractMerchantMetaData extends AgeableMetaData {
public AbstractMerchantMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AbstractMerchantMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public int getShakeTimer() {
final int defaultValue = 0;
if (protocolId < 477) { // ToDo
if (versionId < 477) { // ToDo
return defaultValue;
}
return sets.getInt(super.getLastDataIndex() + 1, defaultValue);
......@@ -28,7 +28,7 @@ public abstract class AbstractMerchantMetaData extends AgeableMetaData {
@Override
protected int getLastDataIndex() {
if (protocolId < 477) { // ToDo
if (versionId < 477) { // ToDo
return super.getLastDataIndex();
}
return super.getLastDataIndex() + 1;
......
......@@ -14,13 +14,13 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AgeableMetaData extends CreatureMetaData {
public AgeableMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AgeableMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean isAdult() {
final boolean defaultValue = false;
if (protocolId < 57) {
if (versionId < 57) {
return getAge() >= 0;
}
return !sets.getBoolean(super.getLastDataIndex() + 1, defaultValue);
......@@ -28,7 +28,7 @@ public abstract class AgeableMetaData extends CreatureMetaData {
public int getAge() {
final int defaultValue = 0;
if (protocolId < 57) {
if (versionId < 57) {
return sets.getInt(12, defaultValue);
}
return defaultValue;
......
......@@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AmbientMetaData extends InsentientMetaData {
public AmbientMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AmbientMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
}
......@@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.entities.meta;
public abstract class AnimalMetaData extends AgeableMetaData {
public AnimalMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AnimalMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
}
......@@ -16,13 +16,13 @@ import de.bixilon.minosoft.data.mappings.particle.data.ParticleData;
public class AreaEffectCloudMetaData extends EntityMetaData {
public AreaEffectCloudMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public AreaEffectCloudMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public float getRadius() {
final float defaultValue = 0.5F;
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return defaultValue;
}
return sets.getFloat(super.getLastDataIndex() + 1, defaultValue);
......@@ -30,7 +30,7 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
public int getColor() {
final int defaultValue = 0;
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return defaultValue;
}
return sets.getInt(super.getLastDataIndex() + 2, defaultValue);
......@@ -38,7 +38,7 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
public boolean ignoreRadius() {
final boolean defaultValue = false;
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return defaultValue;
}
return sets.getBoolean(super.getLastDataIndex() + 3, defaultValue);
......@@ -47,10 +47,10 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
public ParticleData getParticle() {
// ToDo: final ParticleData defaultValue = new ParticleData(Particles.byIdentifier("minecraft:effect"));
final ParticleData defaultValue = null;
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return defaultValue;
}
if (protocolId <= 335) { //ToDo
if (versionId <= 335) { //ToDo
//ToDo return new ParticleData(Particles.byId(sets.getInt(super.getLastDataIndex() + 4, 0), version));
return null;
}
......@@ -59,10 +59,10 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
public int getParticleParameter1() {
final int defaultValue = 0;
if (protocolId < 204) { //ToDo
if (versionId < 204) { //ToDo
return defaultValue;
}
if (protocolId <= 335) { //ToDo
if (versionId <= 335) { //ToDo
return sets.getInt(super.getLastDataIndex() + 5, defaultValue);
}
return defaultValue;
......@@ -70,10 +70,10 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
public int getParticleParameter2() {
final int defaultValue = 0;
if (protocolId < 204) { //ToDo
if (versionId < 204) { //ToDo
return defaultValue;
}
if (protocolId <= 335) { //ToDo
if (versionId <= 335) { //ToDo
return sets.getInt(super.getLastDataIndex() + 6, defaultValue);
}
return defaultValue;
......@@ -81,10 +81,10 @@ public class AreaEffectCloudMetaData extends EntityMetaData {
@Override
protected int getLastDataIndex() {
if (protocolId < 110) { //ToDo
if (versionId < 110) { //ToDo
return super.getLastDataIndex();
}
if (protocolId <= 335) { //ToDo
if (versionId <= 335) { //ToDo
return super.getLastDataIndex() + 6;
}
return super.getLastDataIndex() + 4;
......
......@@ -16,20 +16,20 @@ import de.bixilon.minosoft.data.EntityRotation;
public class ArmorStandMetaData extends LivingMetaData {
public ArmorStandMetaData(MetaDataHashMap sets, int protocolId) {
super(sets, protocolId);
public ArmorStandMetaData(MetaDataHashMap sets, int versionId) {
super(sets, versionId);
}
public boolean isSmall() {
final boolean defaultValue = false;
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x01, defaultValue);
}
public boolean hasGravity() {
if (protocolId < 204) { //ToDo
if (versionId < 204) { //ToDo
return sets.getBitMask(super.getLastDataIndex() + 1, 0x02, super.hasGravity());
}
return super.hasGravity();
......@@ -37,7 +37,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public boolean hasArms() {
final boolean defaultValue = false;
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x04, defaultValue);
......@@ -45,7 +45,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public boolean removeBasePlate() {
final boolean defaultValue = false;
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x08, defaultValue);
......@@ -53,7 +53,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public boolean hasMarker() {
final boolean defaultValue = false;
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getBitMask(super.getLastDataIndex() + 1, 0x10, defaultValue);
......@@ -61,7 +61,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getHeadRotation() {
final EntityRotation defaultValue = new EntityRotation(0, 0, 0);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 2, defaultValue);
......@@ -69,7 +69,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getBodyRotation() {
final EntityRotation defaultValue = new EntityRotation(0, 0, 0);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 3, defaultValue);
......@@ -77,7 +77,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getLeftArmRotation() {
final EntityRotation defaultValue = new EntityRotation(-10, 0, -10);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 4, defaultValue);
......@@ -85,7 +85,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getRightArmRotation() {
final EntityRotation defaultValue = new EntityRotation(-15, 0, 10);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 5, defaultValue);
......@@ -93,7 +93,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getLeftLegRotation() {
final EntityRotation defaultValue = new EntityRotation(-1, 0, -1);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 6, defaultValue);
......@@ -101,7 +101,7 @@ public class ArmorStandMetaData extends LivingMetaData {
public EntityRotation getRightLegRotation() {
final EntityRotation defaultValue = new EntityRotation(1, 0, 1);
if (protocolId < 33) {
if (versionId < 33) {
return defaultValue;
}
return sets.getRotation(super.getLastDataIndex() + 7, defaultValue);
......