fix loading of pre flattening mappings, entity id reading in early 1.7 versions, improve pre flattening mappings loading

This commit is contained in:
Bixilon 2021-01-07 17:58:04 +01:00
parent 26f96a3504
commit 16d66d2394
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 26 additions and 44 deletions

View File

@ -184,9 +184,20 @@ public class Version {
Log.verbose(String.format("Loading mappings for version %s...", this));
long startTime = System.currentTimeMillis();
if (this.mapping == null) {
this.mapping = new VersionMapping(this);
}
if (getVersionId() == ProtocolDefinition.PRE_FLATTENING_VERSION_ID && Versions.PRE_FLATTENING_MAPPING == null) {
Versions.PRE_FLATTENING_MAPPING = this.mapping;
} else {
this.mapping.setParentMapping(Versions.PRE_FLATTENING_MAPPING);
}
HashMap<String, JsonObject> files;
try {
files = Util.readJsonTarStream(AssetsManager.readAssetAsStreamByHash(this.assetsManager.getAssetVersion().getMinosoftMappings()));
files = Util.readJsonTarStream(AssetsManager.readAssetAsStreamByHash(Resources.getAssetVersionByVersion(this).getMinosoftMappings()));
} catch (Exception e) {
// should not happen, but if this version is not flattened, we can fallback to the flatten mappings. Some things might not work...
Log.printException(e, LogLevels.VERBOSE);
@ -222,14 +233,7 @@ public class Version {
}
public void loadVersionMappings(Mappings type, String mod, @Nullable JsonObject data) {
if (this.mapping == null) {
this.mapping = new VersionMapping(this);
}
this.mapping.load(type, mod, data, this);
if (getVersionId() == ProtocolDefinition.PRE_FLATTENING_VERSION_ID && Versions.PRE_FLATTENING_MAPPING == null) {
Versions.PRE_FLATTENING_MAPPING = this.mapping;
}
}
}

View File

@ -42,21 +42,21 @@ public class VersionMapping {
private final HashMap<EntityMetaDataFields, Integer> entityMetaIndexMap = new HashMap<>(100);
private final HashMap<String, Pair<String, Integer>> entityMetaIndexOffsetParentMapping = new HashMap<>(100);
private final HashBiMap<Integer, Class<? extends Entity>> entityIdClassMap = HashBiMap.create(100);
private final HashBiMap<String, Motive> motiveIdentifierMap = HashBiMap.create();
private final HashBiMap<String, Particle> particleIdentifierMap = HashBiMap.create();
private final HashBiMap<String, Statistic> statisticIdentifierMap = HashBiMap.create();
private final HashBiMap<Integer, Item> itemMap = HashBiMap.create();
private final HashBiMap<Integer, Motive> motiveIdMap = HashBiMap.create();
private final HashBiMap<Integer, MobEffect> mobEffectMap = HashBiMap.create();
private final HashBiMap<Integer, Block> blockMap = HashBiMap.create();
private final HashBiMap<Integer, BlockId> blockIdMap = HashBiMap.create();
private final HashBiMap<Integer, Enchantment> enchantmentMap = HashBiMap.create();
private final HashBiMap<Integer, Particle> particleIdMap = HashBiMap.create();
private final HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
private Version version;
private VersionMapping parentMapping;
private HashBiMap<String, Motive> motiveIdentifierMap = HashBiMap.create();
private HashBiMap<String, Particle> particleIdentifierMap = HashBiMap.create();
private HashBiMap<String, Statistic> statisticIdentifierMap = HashBiMap.create();
private HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
private HashBiMap<Integer, Item> itemMap = HashBiMap.create();
private HashBiMap<Integer, Motive> motiveIdMap = HashBiMap.create();
private HashBiMap<Integer, MobEffect> mobEffectMap = HashBiMap.create();
private HashBiMap<Integer, Dimension> dimensionMap = HashBiMap.create();
private HashBiMap<Integer, Block> blockMap = HashBiMap.create();
private HashBiMap<Integer, BlockId> blockIdMap = HashBiMap.create();
private HashBiMap<Integer, Enchantment> enchantmentMap = HashBiMap.create();
private HashBiMap<Integer, Particle> particleIdMap = HashBiMap.create();
private HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
public VersionMapping(Version version) {
this.version = version;
@ -301,22 +301,6 @@ public class VersionMapping {
public void load(Mappings type, String mod, @Nullable JsonObject data, Version version) {
switch (type) {
case REGISTRIES -> {
if (!version.isFlattened() && version.getVersionId() != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
// clone all values
this.itemMap = Versions.PRE_FLATTENING_MAPPING.itemMap;
this.enchantmentMap = Versions.PRE_FLATTENING_MAPPING.enchantmentMap;
this.statisticIdMap = Versions.PRE_FLATTENING_MAPPING.statisticIdMap;
this.statisticIdentifierMap = Versions.PRE_FLATTENING_MAPPING.statisticIdentifierMap;
this.blockIdMap = Versions.PRE_FLATTENING_MAPPING.blockIdMap;
this.motiveIdMap = Versions.PRE_FLATTENING_MAPPING.motiveIdMap;
this.motiveIdentifierMap = Versions.PRE_FLATTENING_MAPPING.motiveIdentifierMap;
this.particleIdMap = Versions.PRE_FLATTENING_MAPPING.particleIdMap;
this.particleIdentifierMap = Versions.PRE_FLATTENING_MAPPING.particleIdentifierMap;
this.mobEffectMap = Versions.PRE_FLATTENING_MAPPING.mobEffectMap;
this.dimensionMap = Versions.PRE_FLATTENING_MAPPING.dimensionMap;
break;
}
if (data == null) {
break;
}
@ -384,12 +368,6 @@ public class VersionMapping {
}
}
case BLOCKS -> {
if (!version.isFlattened() && version.getVersionId() != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
// clone all values
this.blockMap = Versions.PRE_FLATTENING_MAPPING.blockMap;
break;
}
if (data == null) {
break;
}

View File

@ -28,7 +28,7 @@ public class PacketSpawnExperienceOrb extends ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
int entityId = buffer.readVarInt();
int entityId = buffer.readEntityId();
Location location;
if (buffer.getVersionId() < V_16W06A) {
location = new Location(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());

View File

@ -37,7 +37,7 @@ public class PacketSpawnMob extends ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) throws Exception {
int entityId = buffer.readVarInt();
int entityId = buffer.readEntityId();
UUID uuid = null;
if (buffer.getVersionId() >= V_15W31A) {
uuid = buffer.readUUID();

View File

@ -37,7 +37,7 @@ public class PacketSpawnObject extends ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) throws Exception {
int entityId = buffer.readVarInt();
int entityId = buffer.readEntityId();
UUID uuid = null;
if (buffer.getVersionId() >= V_15W31A) {
uuid = buffer.readUUID();