Abstract mapping loading

This commit is contained in:
KennyTV 2020-08-16 16:24:06 +02:00 committed by Nassim
parent 074af0e282
commit d36def89e1
66 changed files with 1264 additions and 606 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -0,0 +1,128 @@
package us.myles.ViaVersion.api.data;
import com.google.gson.JsonObject;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.util.Int2IntBiMap;
public class MappingData {
protected final String oldVersion;
protected final String newVersion;
protected final boolean hasDiffFile;
protected Int2IntBiMap itemMappings;
protected Mappings blockMappings;
protected Mappings blockStateMappings;
protected Mappings soundMappings;
protected Mappings statisticsMappings;
protected boolean loadItems = true;
public MappingData(String oldVersion, String newVersion) {
this(oldVersion, newVersion, false);
}
public MappingData(String oldVersion, String newVersion, boolean hasDiffFile) {
this.oldVersion = oldVersion;
this.newVersion = newVersion;
this.hasDiffFile = hasDiffFile;
}
public void load() {
Via.getPlatform().getLogger().info("Loading " + oldVersion + " -> " + newVersion + " mappings...");
JsonObject diffmapping = hasDiffFile ? loadDiffFile() : null;
JsonObject oldMappings = MappingDataLoader.loadData("mapping-" + oldVersion + ".json", true);
JsonObject newMappings = MappingDataLoader.loadData("mapping-" + newVersion + ".json", true);
blockMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blocks");
blockStateMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blockstates");
soundMappings = loadFromArray(oldMappings, newMappings, diffmapping, "sounds");
statisticsMappings = loadFromArray(oldMappings, newMappings, diffmapping, "statistics");
if (loadItems && newMappings.has("items")) {
itemMappings = new Int2IntBiMap();
itemMappings.defaultReturnValue(-1);
MappingDataLoader.mapIdentifiers(itemMappings, oldMappings.getAsJsonObject("items"), newMappings.getAsJsonObject("items"),
diffmapping != null ? diffmapping.getAsJsonObject("items") : null);
}
loadExtras(oldMappings, newMappings, diffmapping);
}
public int getNewBlockStateId(int id) {
return checkValidity(blockStateMappings.getNewId(id), "blockstate");
}
public int getNewBlockId(int id) {
return checkValidity(blockMappings.getNewId(id), "block");
}
public int getNewItemId(int id) {
return checkValidity(itemMappings.get(id), "item");
}
public int getOldItemId(int id) {
int oldId = itemMappings.inverse().get(id);
return oldId != -1 ? oldId : 1;
}
@Nullable
public Int2IntBiMap getItemMappings() {
return itemMappings;
}
@Nullable
public Mappings getBlockMappings() {
return blockMappings;
}
@Nullable
public Mappings getBlockStateMappings() {
return blockStateMappings;
}
@Nullable
public Mappings getSoundMappings() {
return soundMappings;
}
@Nullable
public Mappings getStatisticsMappings() {
return statisticsMappings;
}
@Nullable
protected Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
return new Mappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff);
}
@Nullable
protected Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
return new Mappings(oldMappings.getAsJsonObject(key), newMappings.getAsJsonObject(key), diff);
}
protected JsonObject loadDiffFile() {
return MappingDataLoader.loadData("mappingdiff-" + oldVersion + "to" + newVersion + ".json");
}
protected int checkValidity(int id, String type) {
if (id == -1) {
Via.getPlatform().getLogger().warning(String.format("Missing %s %s for %s %s %d", newVersion, type, oldVersion, type, id));
return 0;
}
return id;
}
/**
* To be overridden.
*
* @param oldMappings old mappings
* @param newMappings new mappings
* @param diffMappings diff mappings if present
*/
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings) {
}
}

View File

@ -48,6 +48,7 @@ public class MappingDataLoader {
/**
* Loads the file from the plugin folder if present, else from the bundled resources.
*/
@Nullable
public static JsonObject loadFromDataDir(String name) {
File file = new File(Via.getPlatform().getDataFolder(), name);
if (!file.exists()) return loadData(name);
@ -68,6 +69,7 @@ public class MappingDataLoader {
/**
* Loads the file from the bundled resources. Uses the cache if enabled.
*/
@Nullable
public static JsonObject loadData(String name) {
return loadData(name, false);
}
@ -77,6 +79,7 @@ public class MappingDataLoader {
*
* @param cacheIfEnabled whether loaded files should be cached
*/
@Nullable
public static JsonObject loadData(String name, boolean cacheIfEnabled) {
if (cacheJsonMappings) {
JsonObject cached = MAPPINGS_CACHE.get(name);
@ -86,6 +89,8 @@ public class MappingDataLoader {
}
InputStream stream = getResource(name);
if (stream == null) return null;
InputStreamReader reader = new InputStreamReader(stream);
try {
JsonObject object = GsonUtil.getGson().fromJson(reader, JsonObject.class);
@ -106,9 +111,9 @@ public class MappingDataLoader {
mapIdentifiers(output, oldIdentifiers, newIdentifiers, null);
}
public static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers) {
public static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) {
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
Map.Entry<String, JsonElement> value = mapIdentifierEntry(entry, oldIdentifiers, newIdentifiers, diffIdentifiers);
Map.Entry<String, JsonElement> value = mapIdentifierEntry(entry, newIdentifiers, diffIdentifiers);
if (value != null) {
output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey()));
}
@ -119,9 +124,9 @@ public class MappingDataLoader {
MappingDataLoader.mapIdentifiers(output, oldIdentifiers, newIdentifiers, null);
}
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers) {
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) {
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
Map.Entry<String, JsonElement> value = mapIdentifierEntry(entry, oldIdentifiers, newIdentifiers, diffIdentifiers);
Map.Entry<String, JsonElement> value = mapIdentifierEntry(entry, newIdentifiers, diffIdentifiers);
if (value != null) {
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
@ -129,7 +134,7 @@ public class MappingDataLoader {
}
@Nullable
private static Map.Entry<String, JsonElement> mapIdentifierEntry(Map.Entry<String, JsonElement> entry, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers) {
private static Map.Entry<String, JsonElement> mapIdentifierEntry(Map.Entry<String, JsonElement> entry, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) {
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
if (value == null) {
// Search in diff mappings
@ -153,7 +158,7 @@ public class MappingDataLoader {
mapIdentifiers(output, oldIdentifiers, newIdentifiers, null, warnOnMissing);
}
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) {
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) {
for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement value = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, value.getAsString());
@ -208,6 +213,7 @@ public class MappingDataLoader {
return null;
}
@Nullable
public static InputStream getResource(String name) {
return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
}

View File

@ -2,13 +2,14 @@ package us.myles.ViaVersion.api.data;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
public class Mappings {
protected final short[] oldToNew;
protected Mappings(short[] oldToNew) {
public Mappings(short[] oldToNew) {
this.oldToNew = oldToNew;
}
@ -21,13 +22,13 @@ public class Mappings {
* @param newMapping mappings to map to
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
*/
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
oldToNew = new short[size];
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping);
}
public Mappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
public Mappings(JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
this(oldMapping.entrySet().size(), oldMapping, newMapping, diffMapping);
}
@ -86,4 +87,8 @@ public class Mappings {
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
public short[] getOldToNew() {
return oldToNew;
}
}

View File

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingData;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -36,14 +37,9 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
protected final Class<C2> newClientboundPacketEnum;
protected final Class<S1> oldServerboundPacketEnum;
protected final Class<S2> newServerboundPacketEnum;
protected final boolean hasMappingDataToLoad;
protected Protocol() {
this(null, null, null, null, false);
}
protected Protocol(boolean hasMappingDataToLoad) {
this(null, null, null, null, hasMappingDataToLoad);
this(null, null, null, null);
}
/**
@ -51,21 +47,10 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
*/
protected Protocol(@Nullable Class<C1> oldClientboundPacketEnum, @Nullable Class<C2> clientboundPacketEnum,
@Nullable Class<S1> oldServerboundPacketEnum, @Nullable Class<S2> serverboundPacketEnum) {
this(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, false);
}
/**
* Creates a protocol with automated id mapping if the respective enums are not null.
*
* @param hasMappingDataToLoad whether an async executor should call the {@Link #loadMappingData} method
*/
protected Protocol(@Nullable Class<C1> oldClientboundPacketEnum, @Nullable Class<C2> clientboundPacketEnum,
@Nullable Class<S1> oldServerboundPacketEnum, @Nullable Class<S2> serverboundPacketEnum, boolean hasMappingDataToLoad) {
this.oldClientboundPacketEnum = oldClientboundPacketEnum;
this.newClientboundPacketEnum = clientboundPacketEnum;
this.oldServerboundPacketEnum = oldServerboundPacketEnum;
this.newServerboundPacketEnum = serverboundPacketEnum;
this.hasMappingDataToLoad = hasMappingDataToLoad;
registerPackets();
// Register the rest of the ids with no handlers if necessary
@ -157,11 +142,19 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
}
/**
* Load mapping data for the protocol.
* Loads the mappingdata.
*/
protected final void loadMappingData() {
getMappingData().load();
onMappingDataLoaded();
}
/**
* Called after {@link #loadMappingData()} is called; load extra mapping data for the protocol.
* <p>
* To be overridden if needed.
*/
protected void loadMappingData() {
protected void onMappingDataLoaded() {
}
/**
@ -387,10 +380,6 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
return incoming.containsKey(packet);
}
public boolean hasMappingDataToLoad() {
return hasMappingDataToLoad;
}
/**
* Transform a packet using this protocol
*
@ -470,6 +459,16 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
storedObjects.put(object.getClass(), object);
}
public boolean hasMappingDataToLoad() {
return getMappingData() != null;
}
@Nullable
public MappingData getMappingData() {
//TODO Fully hold the instance here and get rid of all static usages (at some point:tm:)
return null; // Let the protocols hold the mappings to still have easy, static singleton access there
}
@Override
public String toString() {
return "Protocol:" + getClass().getSimpleName();

View File

@ -11,10 +11,6 @@ public abstract class SimpleProtocol extends Protocol<SimpleProtocol.DummyPacket
protected SimpleProtocol() {
}
protected SimpleProtocol(boolean hasMappingDataToLoad) {
super(hasMappingDataToLoad);
}
public enum DummyPacketTypes implements ClientboundPacketType, ServerboundPacketType {
}
}

View File

@ -12,15 +12,11 @@ import us.myles.ViaVersion.api.type.Type;
// If any of these methods become outdated, just create a new rewriter overriding the methods
public class BlockRewriter {
private final Protocol protocol;
private final IdRewriteFunction blockStateRewriter;
private final IdRewriteFunction blockRewriter;
private final Type<Position> positionType;
public BlockRewriter(Protocol protocol, Type<Position> positionType, IdRewriteFunction blockStateRewriter, IdRewriteFunction blockRewriter) {
public BlockRewriter(Protocol protocol, Type<Position> positionType) {
this.protocol = protocol;
this.positionType = positionType;
this.blockStateRewriter = blockStateRewriter;
this.blockRewriter = blockRewriter;
}
public void registerBlockAction(ClientboundPacketType packetType) {
@ -33,7 +29,7 @@ public class BlockRewriter {
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0);
int mappedId = blockRewriter.rewrite(id);
int mappedId = protocol.getMappingData().getNewBlockId(id);
if (mappedId == -1) {
// Block (action) has been removed
wrapper.cancel();
@ -52,7 +48,7 @@ public class BlockRewriter {
public void registerMap() {
map(positionType);
map(Type.VAR_INT);
handler(wrapper -> wrapper.set(Type.VAR_INT, 0, blockStateRewriter.rewrite(wrapper.get(Type.VAR_INT, 0))));
handler(wrapper -> wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.VAR_INT, 0))));
}
});
}
@ -65,7 +61,7 @@ public class BlockRewriter {
map(Type.INT); // 1 - Chunk Z
handler(wrapper -> {
for (BlockChangeRecord record : wrapper.passthrough(Type.BLOCK_CHANGE_RECORD_ARRAY)) {
record.setBlockId(blockStateRewriter.rewrite(record.getBlockId()));
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
}
});
}
@ -79,7 +75,7 @@ public class BlockRewriter {
map(Type.LONG); // Chunk position
handler(wrapper -> {
for (BlockChangeRecord record : wrapper.passthrough(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY)) {
record.setBlockId(blockStateRewriter.rewrite(record.getBlockId()));
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
}
});
}
@ -91,7 +87,7 @@ public class BlockRewriter {
registerBlockChange(packetType);
}
public void registerEffect(ClientboundPacketType packetType, int playRecordId, int blockBreakId, IdRewriteFunction itemIdRewriteFunction) {
public void registerEffect(ClientboundPacketType packetType, int playRecordId, int blockBreakId) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
@ -102,9 +98,9 @@ public class BlockRewriter {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == playRecordId) { // Play record
wrapper.set(Type.INT, 1, itemIdRewriteFunction.rewrite(data));
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
} else if (id == blockBreakId) { // Block break + block break sound
wrapper.set(Type.INT, 1, blockStateRewriter.rewrite(data));
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
}
});
}
@ -136,7 +132,7 @@ public class BlockRewriter {
if (id == -1) return;
if (id == blockId || id == fallingDustId) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, blockStateRewriter.rewrite(data));
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == itemId) {
// Has to be like this, until we make *everything* object oriented inside of each protocol :(
itemRewriteFunction.rewrite(wrapper.passthrough(itemType));

View File

@ -180,4 +180,8 @@ public class ComponentRewriter {
processText(jsonElement);
}
}
public <T extends Protocol> T getProtocol() {
return (T) protocol;
}
}

View File

@ -106,13 +106,13 @@ public class ItemRewriter {
});
}
public void registerSetCooldown(ClientboundPacketType packetType, IdRewriteFunction itemIDRewriteFunction) {
public void registerSetCooldown(ClientboundPacketType packetType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int itemId = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, itemIDRewriteFunction.rewrite(itemId));
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewItemId(itemId));
});
}
});

View File

@ -20,7 +20,7 @@ import java.util.logging.Logger;
public abstract class MetadataRewriter {
private final Class<? extends EntityTracker> entityTrackerClass;
private final Protocol protocol;
protected final Protocol protocol;
private Int2IntMap typeMapping;
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
@ -64,7 +64,7 @@ public abstract class MetadataRewriter {
});
}
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction itemRewriter) {
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
@ -82,7 +82,7 @@ public abstract class MetadataRewriter {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = wrapper.user().get(entityTrackerClass).getEntity(entityId);
if (entityType == fallingBlockType) {
wrapper.set(Type.INT, 0, itemRewriter.rewrite(wrapper.get(Type.INT, 0)));
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewItemId(wrapper.get(Type.INT, 0)));
}
});
}

View File

@ -7,9 +7,13 @@ import us.myles.ViaVersion.api.type.Type;
public class SoundRewriter {
protected final Protocol protocol;
// Can't hold the mappings instance here since it's loaded later
protected final IdRewriteFunction idRewriter;
public SoundRewriter(Protocol protocol) {
this.protocol = protocol;
this.idRewriter = id -> protocol.getMappingData().getSoundMappings().getNewId(id);
}
public SoundRewriter(Protocol protocol, IdRewriteFunction idRewriter) {
this.protocol = protocol;
this.idRewriter = idRewriter;

View File

@ -8,24 +8,12 @@ import us.myles.ViaVersion.api.type.Type;
public class StatisticsRewriter {
private final Protocol protocol;
private final IdRewriteFunction blockRewriter;
private final IdRewriteFunction itemRewriter;
private final IdRewriteFunction entityRewriter;
private final IdRewriteFunction statisticsIdRewriter;
private final int customStatsCategory = 8; // Make this changeable if it differs in a future version
public StatisticsRewriter(Protocol protocol,
@Nullable IdRewriteFunction blockRewriter, @Nullable IdRewriteFunction itemRewriter, @Nullable IdRewriteFunction entityRewriter,
@Nullable IdRewriteFunction statisticsIdRewriter) {
public StatisticsRewriter(Protocol protocol, @Nullable IdRewriteFunction entityRewriter) {
this.protocol = protocol;
this.blockRewriter = blockRewriter;
this.itemRewriter = itemRewriter;
this.entityRewriter = entityRewriter;
this.statisticsIdRewriter = statisticsIdRewriter;
}
public StatisticsRewriter(Protocol protocol, @Nullable IdRewriteFunction blockRewriter, @Nullable IdRewriteFunction itemRewriter, @Nullable IdRewriteFunction entityRewriter) {
this(protocol, blockRewriter, itemRewriter, entityRewriter, null);
}
public void register(ClientboundPacketType packetType) {
@ -39,9 +27,9 @@ public class StatisticsRewriter {
int categoryId = wrapper.read(Type.VAR_INT);
int statisticId = wrapper.read(Type.VAR_INT);
int value = wrapper.read(Type.VAR_INT);
if (categoryId == customStatsCategory && statisticsIdRewriter != null) {
if (categoryId == customStatsCategory && protocol.getMappingData().getStatisticsMappings() != null) {
// Rewrite custom statistics id
statisticId = statisticsIdRewriter.rewrite(statisticId);
statisticId = protocol.getMappingData().getStatisticsMappings().getNewId(statisticId);
if (statisticId == -1) {
// Remove entry
newSize--;
@ -73,9 +61,9 @@ public class StatisticsRewriter {
protected IdRewriteFunction getRewriter(RegistryType type) {
switch (type) {
case BLOCK:
return blockRewriter;
return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null;
case ITEM:
return itemRewriter;
return protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null;
case ENTITY:
return entityRewriter;
}

View File

@ -2,7 +2,9 @@ package us.myles.ViaVersion.api.rewriters;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.MappingData;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -14,18 +16,14 @@ import java.util.List;
public class TagRewriter {
private static final int[] EMPTY_ARRAY = {};
private final Protocol protocol;
private final IdRewriteFunction blockRewriter;
private final IdRewriteFunction itemRewriter;
private final IdRewriteFunction entityRewriter;
private final List<TagData> newBlockTags = new ArrayList<>();
private final List<TagData> newItemTags = new ArrayList<>();
private final List<TagData> newEntityTags = new ArrayList<>();
// add fluid tag list if needed at some point
public TagRewriter(Protocol protocol, IdRewriteFunction blockRewriter, IdRewriteFunction itemRewriter, IdRewriteFunction entityRewriter) {
public TagRewriter(Protocol protocol, @Nullable IdRewriteFunction entityRewriter) {
this.protocol = protocol;
this.blockRewriter = blockRewriter;
this.itemRewriter = itemRewriter;
this.entityRewriter = entityRewriter;
}
@ -58,8 +56,9 @@ public class TagRewriter {
@Override
public void registerMap() {
handler(wrapper -> {
handle(wrapper, blockRewriter, newBlockTags);
handle(wrapper, itemRewriter, newItemTags);
MappingData mappingData = protocol.getMappingData();
handle(wrapper, id -> mappingData != null ? mappingData.getNewBlockId(id) : null, newBlockTags);
handle(wrapper, id -> mappingData != null ? mappingData.getNewItemId(id) : null, newItemTags);
if (entityRewriter == null && newEntityTags.isEmpty()) return;
@ -122,12 +121,13 @@ public class TagRewriter {
}
}
@Nullable
private IdRewriteFunction getRewriter(RegistryType tagType) {
switch (tagType) {
case BLOCK:
return blockRewriter;
return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null;
case ITEM:
return itemRewriter;
return protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null;
case ENTITY:
return entityRewriter;
case FLUID:

View File

@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_9;
@ -39,7 +40,7 @@ public class Protocol1_11To1_10 extends Protocol<ClientboundPackets1_9_3, Client
@Override
protected void registerPackets() {
MetadataRewriter1_11To1_10 metadataRewriter = new MetadataRewriter1_11To1_10(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_11To1_10(this);
InventoryPackets.register(this);

View File

@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_12;
@ -34,7 +35,7 @@ public class Protocol1_12To1_11_1 extends Protocol<ClientboundPackets1_9_3, Clie
@Override
protected void registerPackets() {
MetadataRewriter1_12To1_11_1 metadataRewriter = new MetadataRewriter1_12To1_11_1(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_12To1_11_1(this);
InventoryPackets.register(this);

View File

@ -1,12 +1,14 @@
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.MappingData;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
@ -20,13 +22,15 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public static final MappingData MAPPINGS = new MappingData("1.13", "1.13.2", true);
public Protocol1_13_1To1_13() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
}
@Override
protected void registerPackets() {
new MetadataRewriter1_13_1To1_13(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_13_1To1_13(this);
EntityPackets.register(this);
InventoryPackets.register(this);
@ -130,7 +134,7 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
wrapper.passthrough(Type.STRING);
int[] blocks = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blocks.length; j++) {
blocks[j] = getNewBlockId(blocks[j]);
blocks[j] = getMappingData().getNewBlockId(blocks[j]);
}
}
int itemTagsSize = wrapper.passthrough(Type.VAR_INT); // item tags
@ -138,7 +142,7 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
wrapper.passthrough(Type.STRING);
int[] items = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < items.length; j++) {
items[j] = InventoryPackets.getNewItemId(items[j]);
items[j] = getMappingData().getNewItemId(items[j]);
}
}
}
@ -146,7 +150,7 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
}
});
new StatisticsRewriter(this, null, null, null, id -> {
new StatisticsRewriter(this, id -> {
int newId = id;
if (newId > 22) {
newId += 2;
@ -169,26 +173,8 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
}
}
public static int getNewBlockStateId(int blockId) {
if (blockId > 8573) {
blockId += 17;
} else if (blockId > 8463) {
blockId += 16;
} else if (blockId > 8458) {
blockId = 8470 + (blockId - 8459) * 2;
} else if (blockId > 1126) {
blockId += 1;
}
return blockId;
}
public static int getNewBlockId(final int oldBlockId) {
int blockId = oldBlockId;
if (oldBlockId >= 561) {
blockId += 5;
}
return blockId;
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -27,7 +27,7 @@ public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter {
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;
@ -35,7 +35,7 @@ public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter {
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
// New block format
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) {

View File

@ -40,7 +40,7 @@ public class EntityPackets {
if (entType != null) {
if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, Protocol1_13_1To1_13.getNewBlockStateId(data));
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
}
// Register Type ID
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);

View File

@ -2,26 +2,34 @@ package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.rewriters.RecipeRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
public class InventoryPackets {
public static void register(Protocol protocol) {
public static void register(Protocol1_13_1To1_13 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
itemRewriter.registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_ITEM);
protocol.registerOutgoing(ClientboundPackets1_13.COOLDOWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int itemId = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewItemId(itemId));
});
}
});
protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
@ -80,25 +88,11 @@ public class InventoryPackets {
public static void toClient(Item item) {
if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier()));
}
public static int getNewItemId(int itemId) {
if (itemId >= 443) {
return itemId + 5;
}
return itemId;
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getNewItemId(item.getIdentifier()));
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
}
public static int getOldItemId(int newId) {
if (newId >= 448) {
return newId - 5;
}
return newId;
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getOldItemId(item.getIdentifier()));
}
}

View File

@ -8,7 +8,6 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -16,7 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class WorldPackets {
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13_1To1_13::getNewBlockStateId, Protocol1_13_1To1_13::getNewBlockId);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override
@ -30,7 +29,7 @@ public class WorldPackets {
for (ChunkSection section : chunk.getSections()) {
if (section == null) continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, Protocol1_13_1To1_13.getNewBlockStateId(section.getPaletteEntry(i)));
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
}
}
}
@ -41,7 +40,7 @@ public class WorldPackets {
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001);
protocol.registerOutgoing(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
@Override

View File

@ -17,6 +17,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
@ -25,7 +26,11 @@ import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.*;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticMappings;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
@ -39,12 +44,18 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTra
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.GsonUtil;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, ClientboundPackets1_13, ServerboundPackets1_12_1, ServerboundPackets1_13> {
public static final MappingData MAPPINGS = new MappingData();
public Protocol1_13To1_12_2() {
super(ClientboundPackets1_12_1.class, ClientboundPackets1_13.class, ServerboundPackets1_12_1.class, ServerboundPackets1_13.class, true);
super(ClientboundPackets1_12_1.class, ClientboundPackets1_13.class, ServerboundPackets1_12_1.class, ServerboundPackets1_13.class);
}
public static final PacketHandler POS_TO_3_INT = wrapper -> {
@ -54,58 +65,55 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
wrapper.write(Type.INT, position.getZ());
};
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
new PacketHandler() { // *insert here a good name*
@Override
public void handle(PacketWrapper w) throws Exception {
// Send fake declare commands
w.create(0x11, new ValueCreator() {
@Override
public void write(PacketWrapper wrapper) {
wrapper.write(Type.VAR_INT, 2); // Size
// Write root node
wrapper.write(Type.VAR_INT, 0); // Mark as command
wrapper.write(Type.VAR_INT, 1); // 1 child
wrapper.write(Type.VAR_INT, 1); // Child is at 1
private static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
w -> {
// Send fake declare commands
w.create(0x11, new ValueCreator() {
@Override
public void write(PacketWrapper wrapper) {
wrapper.write(Type.VAR_INT, 2); // Size
// Write root node
wrapper.write(Type.VAR_INT, 0); // Mark as command
wrapper.write(Type.VAR_INT, 1); // 1 child
wrapper.write(Type.VAR_INT, 1); // Child is at 1
// Write arg node
wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command
wrapper.write(Type.VAR_INT, 0); // No children
// Extra data
wrapper.write(Type.STRING, "args"); // Arg name
wrapper.write(Type.STRING, "brigadier:string");
wrapper.write(Type.VAR_INT, 2); // Greedy
wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server
// Write arg node
wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command
wrapper.write(Type.VAR_INT, 0); // No children
// Extra data
wrapper.write(Type.STRING, "args"); // Arg name
wrapper.write(Type.STRING, "brigadier:string");
wrapper.write(Type.VAR_INT, 2); // Greedy
wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server
wrapper.write(Type.VAR_INT, 0); // Root node index
wrapper.write(Type.VAR_INT, 0); // Root node index
}
}).send(Protocol1_13To1_12_2.class);
// Send tags packet
w.create(0x55, new ValueCreator() {
@Override
public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, MAPPINGS.getBlockTags().size()); // block tags
for (Map.Entry<String, Integer[]> tag : MAPPINGS.getBlockTags().entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
}).send(Protocol1_13To1_12_2.class);
// Send tags packet
w.create(0x55, new ValueCreator() {
@Override
public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, MappingData.blockTags.size()); // block tags
for (Map.Entry<String, Integer[]> tag : MappingData.blockTags.entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
wrapper.write(Type.VAR_INT, MappingData.itemTags.size()); // item tags
for (Map.Entry<String, Integer[]> tag : MappingData.itemTags.entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
wrapper.write(Type.VAR_INT, MappingData.fluidTags.size()); // fluid tags
for (Map.Entry<String, Integer[]> tag : MappingData.fluidTags.entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
wrapper.write(Type.VAR_INT, MAPPINGS.getItemTags().size()); // item tags
for (Map.Entry<String, Integer[]> tag : MAPPINGS.getItemTags().entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
}).send(Protocol1_13To1_12_2.class);
}
wrapper.write(Type.VAR_INT, MAPPINGS.getFluidTags().size()); // fluid tags
for (Map.Entry<String, Integer[]> tag : MAPPINGS.getFluidTags().entrySet()) {
wrapper.write(Type.STRING, tag.getKey());
// Needs copy as other protocols may modify it
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, toPrimitive(tag.getValue()));
}
}
}).send(Protocol1_13To1_12_2.class);
};
// These are arbitrary rewrite values, it just needs an invalid color code character.
@ -140,7 +148,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
@Override
protected void registerPackets() {
new MetadataRewriter1_13To1_12_2(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_13To1_12_2(this);
// Register grouped packet changes
EntityPackets.register(this);
@ -330,7 +338,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
wrapper.cancel();
if (item == 383) { // Spawn egg
for (int i = 0; i < 44; i++) {
Integer newItem = MappingData.oldToNewItems.get(item << 16 | i);
Integer newItem = getMappingData().getItemMappings().get(item << 16 | i);
if (newItem != null) {
PacketWrapper packet = wrapper.create(0x18);
packet.write(Type.VAR_INT, newItem);
@ -342,7 +350,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
}
} else {
for (int i = 0; i < 16; i++) {
int newItem = MappingData.oldToNewItems.get(item << 4 | i);
int newItem = getMappingData().getItemMappings().get(item << 4 | i);
if (newItem != -1) {
PacketWrapper packet = wrapper.create(0x18);
packet.write(Type.VAR_INT, newItem);
@ -377,7 +385,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, MappingData.oldToNewItems.get(data << 4));
wrapper.set(Type.INT, 1, getMappingData().getItemMappings().get(data << 4));
} else if (id == 2001) { // Block break + block break sound
int blockId = data & 0xFFF;
int blockData = data >> 12;
@ -679,7 +687,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
});
// New 0x4C - Stop Sound
new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(ClientboundPackets1_12_1.SOUND);
new SoundRewriter(this).registerSound(ClientboundPackets1_12_1.SOUND);
registerOutgoing(ClientboundPackets1_12_1.TAB_LIST, new PacketRemapper() {
@Override
@ -1015,8 +1023,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
}
@Override
protected void loadMappingData() {
MappingData.init();
protected void onMappingDataLoaded() {
ConnectionData.init();
RecipeData.init();
BlockIdData.init();
@ -1086,4 +1093,9 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
}
return prim;
}
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -205,7 +205,7 @@ public class ConnectionData {
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
JsonObject blocks1_13 = mapping1_13.getAsJsonObject("blocks");
JsonObject blocks1_13 = mapping1_13.getAsJsonObject("blockstates");
for (Entry<String, JsonElement> blockState : blocks1_13.entrySet()) {
int id = Integer.parseInt(blockState.getKey());
String key = blockState.getValue().getAsString();

View File

@ -2,13 +2,13 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.prov
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
public class BlockConnectionProvider implements Provider {
public int getBlockData(UserConnection connection, int x, int y, int z) {
int oldId = getWorldBlockData(connection, x, y, z);
return MappingData.blockMappings.getNewId(oldId);
return Protocol1_13To1_12_2.MAPPINGS.getBlockMappings().getNewId(oldId);
}
public int getWorldBlockData(UserConnection connection, int x, int y, int z) {

View File

@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.nbt.BinaryTagIO;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import java.io.IOException;
@ -103,9 +104,10 @@ public class ComponentRewriter1_13 extends ComponentRewriter {
protected void handleTranslate(JsonObject object, String translate) {
super.handleTranslate(object, translate);
String newTranslate;
newTranslate = MappingData.translateMapping.get(translate);
Protocol1_13To1_12_2 protocol = getProtocol();
newTranslate = protocol.getMappingData().getTranslateMapping().get(translate);
if (newTranslate == null) {
newTranslate = MappingData.mojangTranslation.get(translate);
newTranslate = protocol.getMappingData().getMojangTranslation().get(translate);
}
if (newTranslate != null) {
object.addProperty("translate", newTranslate);

View File

@ -7,11 +7,11 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.ViaVersion.util.Int2IntBiMap;
import java.io.IOException;
import java.io.InputStreamReader;
@ -20,34 +20,44 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class MappingData {
public static final Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static final Map<String, Integer[]> blockTags = new HashMap<>();
public static final Map<String, Integer[]> itemTags = new HashMap<>();
public static final Map<String, Integer[]> fluidTags = new HashMap<>();
public static final BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
public static final Map<String, String> translateMapping = new HashMap<>();
public static final Map<String, String> mojangTranslation = new HashMap<>();
public static final BiMap<String, String> channelMappings = HashBiMap.create(); // 1.12->1.13
public static Mappings enchantmentMappings;
public static Mappings soundMappings;
public static Mappings blockMappings;
public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
private final Map<String, Integer[]> blockTags = new HashMap<>();
private final Map<String, Integer[]> itemTags = new HashMap<>();
private final Map<String, Integer[]> fluidTags = new HashMap<>();
private final BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
private final Map<String, String> translateMapping = new HashMap<>();
private final Map<String, String> mojangTranslation = new HashMap<>();
private final BiMap<String, String> channelMappings = HashBiMap.create(); // 1.12->1.13
private Mappings enchantmentMappings;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 mappings...");
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json", true);
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
public MappingData() {
super("1.12", "1.13");
}
oldToNewItems.defaultReturnValue(-1);
blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
@Override
public void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
loadTags(blockTags, newMappings.getAsJsonObject("block_tags"));
loadTags(itemTags, newMappings.getAsJsonObject("item_tags"));
loadTags(fluidTags, newMappings.getAsJsonObject("fluid_tags"));
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
enchantmentMappings = new Mappings(72, mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
loadEnchantments(oldEnchantmentsIds, oldMappings.getAsJsonObject("enchantments"));
enchantmentMappings = new Mappings(72, oldMappings.getAsJsonObject("enchantments"), newMappings.getAsJsonObject("enchantments"));
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
if (Via.getConfig().isSnowCollisionFix()) {
blockMappings.getOldToNew()[1248] = 3416;
}
// Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers
if (Via.getConfig().isInfestedBlocksFix()) {
short[] oldToNew = blockMappings.getOldToNew();
oldToNew[1552] = 1; // stone
oldToNew[1553] = 14; // cobblestone
oldToNew[1554] = 3983; // stone bricks
oldToNew[1555] = 3984; // mossy stone bricks
oldToNew[1556] = 3985; // cracked stone bricks
oldToNew[1557] = 3986; // chiseled stone bricks
}
JsonObject object = MappingDataLoader.loadFromDataDir("channelmappings-1.13.json");
if (object != null) {
@ -94,6 +104,16 @@ public class MappingData {
}
}
@Override
protected Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
if (key.equals("blocks")) {
// Need to use a custom size since there are larger gaps in ids
return new Mappings(4084, oldMappings.getAsJsonObject("blocks"), newMappings.getAsJsonObject("blockstates"));
} else {
return super.loadFromObject(oldMappings, newMappings, diffMappings, key);
}
}
public static String validateNewChannel(String newId) {
if (!isValid1_13Channel(newId)) {
return null; // Not valid
@ -110,7 +130,7 @@ public class MappingData {
return channelId.matches("([0-9a-z_.-]+):([0-9a-z_/.-]+)");
}
private static void loadTags(Map<String, Integer[]> output, JsonObject newTags) {
private void loadTags(Map<String, Integer[]> output, JsonObject newTags) {
for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) {
JsonArray ids = entry.getValue().getAsJsonArray();
Integer[] idsArray = new Integer[ids.size()];
@ -121,31 +141,41 @@ public class MappingData {
}
}
private static void loadEnchantments(Map<Short, String> output, JsonObject enchantments) {
private void loadEnchantments(Map<Short, String> output, JsonObject enchantments) {
for (Map.Entry<String, JsonElement> enchantment : enchantments.entrySet()) {
output.put(Short.parseShort(enchantment.getKey()), enchantment.getValue().getAsString());
}
}
private static class BlockMappingsShortArray extends Mappings {
public Map<String, Integer[]> getBlockTags() {
return blockTags;
}
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
super(4084, mapping1_12, mapping1_13);
public Map<String, Integer[]> getItemTags() {
return itemTags;
}
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
if (Via.getConfig().isSnowCollisionFix()) {
oldToNew[1248] = 3416;
}
public Map<String, Integer[]> getFluidTags() {
return fluidTags;
}
// Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers
if (Via.getConfig().isInfestedBlocksFix()) {
oldToNew[1552] = 1; // stone
oldToNew[1553] = 14; // cobblestone
oldToNew[1554] = 3983; // stone bricks
oldToNew[1555] = 3984; // mossy stone bricks
oldToNew[1556] = 3985; // cracked stone bricks
oldToNew[1557] = 3986; // chiseled stone bricks
}
}
public BiMap<Short, String> getOldEnchantmentsIds() {
return oldEnchantmentsIds;
}
public Map<String, String> getTranslateMapping() {
return translateMapping;
}
public Map<String, String> getMojangTranslation() {
return mojangTranslation;
}
public BiMap<String, String> getChannelMappings() {
return channelMappings;
}
public Mappings getEnchantmentMappings() {
return enchantmentMappings;
}
}

View File

@ -12,7 +12,6 @@ import com.google.common.primitives.Ints;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
@ -35,7 +34,7 @@ import java.util.Optional;
public class InventoryPackets {
private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_13To1_12_2.class.getSimpleName();
public static void register(Protocol protocol) {
public static void register(Protocol1_13To1_12_2 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
protocol.registerOutgoing(ClientboundPackets1_12_1.SET_SLOT, new PacketRemapper() {
@ -69,7 +68,7 @@ public class InventoryPackets {
public void handle(PacketWrapper wrapper) throws Exception {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) { // Enchantment id
wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewId(wrapper.get(Type.SHORT, 1)));
wrapper.set(Type.SHORT, 1, (short) protocol.getMappingData().getEnchantmentMappings().getNewId(wrapper.get(Type.SHORT, 1)));
}
}
});
@ -315,7 +314,7 @@ public class InventoryPackets {
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag("");
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
String newId = MappingData.oldEnchantmentsIds.get(oldId);
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
@ -334,7 +333,7 @@ public class InventoryPackets {
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag("");
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
String newId = MappingData.oldEnchantmentsIds.get(oldId);
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
@ -420,14 +419,14 @@ public class InventoryPackets {
}
}
if (!MappingData.oldToNewItems.containsKey(rawId)) {
if (!Protocol1_13To1_12_2.MAPPINGS.getItemMappings().containsKey(rawId)) {
if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map
if (tag == null) item.setTag(tag = new CompoundTag("tag"));
tag.put(new IntTag(NBT_TAG_NAME, originalId)); // Data will be lost, saving original id
}
if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed
rawId = 32 << 4; // Dead Bush
} else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) {
} else if (Protocol1_13To1_12_2.MAPPINGS.getItemMappings().containsKey(rawId & ~0xF)) {
rawId &= ~0xF; // Remove data
} else {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
@ -437,7 +436,7 @@ public class InventoryPackets {
}
}
item.setIdentifier(MappingData.oldToNewItems.get(rawId));
item.setIdentifier(Protocol1_13To1_12_2.MAPPINGS.getItemMappings().get(rawId));
item.setData((short) 0);
}
@ -463,7 +462,7 @@ public class InventoryPackets {
case "bungeecord:main":
return null;
default:
String mappedChannel = MappingData.channelMappings.get(old);
String mappedChannel = Protocol1_13To1_12_2.MAPPINGS.getChannelMappings().get(old);
if (mappedChannel != null) return mappedChannel;
return MappingData.isValid1_13Channel(old) ? old : null;
}
@ -489,7 +488,7 @@ public class InventoryPackets {
}
if (rawId == null) {
int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier());
int oldId = Protocol1_13To1_12_2.MAPPINGS.getItemMappings().inverse().get(item.getIdentifier());
if (oldId != -1) {
// Handle spawn eggs
Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);
@ -576,7 +575,7 @@ public class InventoryPackets {
if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
@ -602,7 +601,7 @@ public class InventoryPackets {
if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
@ -695,7 +694,7 @@ public class InventoryPackets {
case "bungeecord:main":
return "BungeeCord";
default:
String mappedChannel = MappingData.channelMappings.inverse().get(newId);
String mappedChannel = Protocol1_13To1_12_2.MAPPINGS.getChannelMappings().inverse().get(newId);
if (mappedChannel != null) return mappedChannel;
return newId.length() > 20 ? newId.substring(0, 20) : newId;
}

View File

@ -19,7 +19,6 @@ import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -535,11 +534,11 @@ public class WorldPackets {
if (oldId < 0) {
oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air.
}
int newId = MappingData.blockMappings.getNewId(oldId);
int newId = Protocol1_13To1_12_2.MAPPINGS.getBlockMappings().getNewId(oldId);
if (newId != -1) {
return newId;
}
newId = MappingData.blockMappings.getNewId(oldId & ~0xF); // Remove data
newId = Protocol1_13To1_12_2.MAPPINGS.getBlockMappings().getNewId(oldId & ~0xF); // Remove data
if (newId != -1) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Missing block " + oldId);

View File

@ -6,7 +6,7 @@ import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import java.lang.reflect.Constructor;
@ -30,7 +30,7 @@ public class BlockConnectionStorage extends StoredObject {
Arrays.fill(REVERSE_BLOCK_MAPPINGS, (short) -1);
for (int i = 0; i < 4096; i++) {
int newBlock = MappingData.blockMappings.getNewId(i);
int newBlock = Protocol1_13To1_12_2.MAPPINGS.getBlockMappings().getNewId(i);
if (newBlock != -1) {
REVERSE_BLOCK_MAPPINGS[newBlock] = (short) i;
}

View File

@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
@ -16,7 +17,7 @@ public class Protocol1_14_1To1_14 extends Protocol<ClientboundPackets1_14, Clien
@Override
protected void registerPackets() {
new MetadataRewriter1_14_1To1_14(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_14_1To1_14(this);
EntityPackets.register(this);
}

View File

@ -1,12 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
import us.myles.ViaVersion.api.type.Type;
@ -24,22 +24,23 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, ClientboundPackets1_14, ServerboundPackets1_13, ServerboundPackets1_14> {
public static final MappingData MAPPINGS = new MappingData();
public Protocol1_14To1_13_2() {
super(ClientboundPackets1_13.class, ClientboundPackets1_14.class, ServerboundPackets1_13.class, ServerboundPackets1_14.class, true);
super(ClientboundPackets1_13.class, ClientboundPackets1_14.class, ServerboundPackets1_13.class, ServerboundPackets1_14.class);
}
@Override
protected void registerPackets() {
MetadataRewriter1_14To1_13_2 metadataRewriter = new MetadataRewriter1_14To1_13_2(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_14To1_13_2(this);
InventoryPackets.register(this);
EntityPackets.register(this);
WorldPackets.register(this);
PlayerPackets.register(this);
new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter(this, Protocol1_14To1_13_2::getNewBlockId,
InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_13.STATISTICS);
new SoundRewriter(this).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_13.STATISTICS);
ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
componentRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE);
@ -56,21 +57,21 @@ public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, Clien
wrapper.passthrough(Type.STRING);
int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
blockIds[j] = getNewBlockId(blockIds[j]);
blockIds[j] = getMappingData().getNewBlockId(blockIds[j]);
}
}
// Minecraft crashes if we not send signs tags
wrapper.write(Type.STRING, "minecraft:signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{
getNewBlockId(150), getNewBlockId(155)
getMappingData().getNewBlockId(150), getMappingData().getNewBlockId(155)
});
wrapper.write(Type.STRING, "minecraft:wall_signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{
getNewBlockId(155)
getMappingData().getNewBlockId(155)
});
wrapper.write(Type.STRING, "minecraft:standing_signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{
getNewBlockId(150)
getMappingData().getNewBlockId(150)
});
// Fences and walls tags - used for block connections
wrapper.write(Type.STRING, "minecraft:fences");
@ -85,13 +86,13 @@ public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, Clien
wrapper.passthrough(Type.STRING);
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
itemIds[j] = InventoryPackets.getNewItemId(itemIds[j]);
itemIds[j] = getMappingData().getNewItemId(itemIds[j]);
}
}
// Should fix fuel shift clicking
wrapper.write(Type.STRING, "minecraft:signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{
InventoryPackets.getNewItemId(541)
getMappingData().getNewItemId(541)
});
// Arrows tag (used by bow)
wrapper.write(Type.STRING, "minecraft:arrows");
@ -116,29 +117,10 @@ public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, Clien
}
@Override
protected void loadMappingData() {
MappingData.init();
WorldPackets.air = MappingData.blockStateMappings.getNewId(0);
WorldPackets.voidAir = MappingData.blockStateMappings.getNewId(8591);
WorldPackets.caveAir = MappingData.blockStateMappings.getNewId(8592);
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.14 blockstate for 1.13.2 blockstate " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = MappingData.blockMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.14 block for 1.13.2 block " + id);
return 0;
}
return newId;
protected void onMappingDataLoaded() {
WorldPackets.air = getMappingData().getBlockStateMappings().getNewId(0);
WorldPackets.voidAir = getMappingData().getBlockStateMappings().getNewId(8591);
WorldPackets.caveAir = getMappingData().getBlockStateMappings().getNewId(8592);
}
@Override
@ -148,4 +130,9 @@ public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, Clien
userConnection.put(new ClientWorld(userConnection));
}
}
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -7,34 +7,21 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.Int2IntBiMap;
import java.util.HashMap;
import java.util.Map;
public class MappingData {
public static final Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public static IntSet motionBlocking;
public static IntSet nonFullBlocks;
public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
private IntSet motionBlocking;
private IntSet nonFullBlocks;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true);
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
public MappingData() {
super("1.13.2", "1.14");
}
oldToNewItems.defaultReturnValue(-1);
blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
statisticsMappings = new Mappings(mapping1_13_2.getAsJsonArray("statistics"), mapping1_14.getAsJsonArray("statistics"));
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
@Override
public void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
JsonObject blockStates = newMappings.getAsJsonObject("blockstates");
Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
@ -42,23 +29,24 @@ public class MappingData {
JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size(), 1F);
this.motionBlocking = new IntOpenHashSet(motionBlocking.size(), 1F);
for (JsonElement blockState : motionBlocking) {
String key = blockState.getAsString();
Integer id = blockStateMap.get(key);
if (id == null) {
Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
} else {
MappingData.motionBlocking.add(id.intValue());
this.motionBlocking.add(id.intValue());
}
}
if (Via.getConfig().isNonFullBlockLightFix()) {
nonFullBlocks = new IntOpenHashSet(1611, 1F);
for (Map.Entry<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
for (Map.Entry<String, JsonElement> blockstates : oldMappings.getAsJsonObject("blockstates").entrySet()) {
final String state = blockstates.getValue().getAsString();
if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall[")) {
nonFullBlocks.add(blockStateMappings.getNewId(Integer.parseInt(blockstates.getKey())));
}
}
nonFullBlocks.add(blockStateMappings.getNewId(8163)); // grass path
for (int i = 3060; i <= 3067; i++) { // farmland
@ -66,4 +54,12 @@ public class MappingData {
}
}
}
public IntSet getMotionBlocking() {
return motionBlocking;
}
public IntSet getNonFullBlocks() {
return nonFullBlocks;
}
}

View File

@ -38,7 +38,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;
@ -95,7 +95,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
if (metadata.getId() == 10) {
// New block format
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type.is(Entity1_14Types.EntityType.HORSE)) {
if (metadata.getId() == 18) {
@ -104,11 +104,11 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
int armorType = (int) metadata.getValue();
Item armorItem = null;
if (armorType == 1) { //iron armor
armorItem = new Item(InventoryPackets.getNewItemId(727), (byte) 1, (short) 0, null);
armorItem = new Item(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
} else if (armorType == 2) { //gold armor
armorItem = new Item(InventoryPackets.getNewItemId(728), (byte) 1, (short) 0, null);
armorItem = new Item(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
} else if (armorType == 3) { //diamond armor
armorItem = new Item(InventoryPackets.getNewItemId(729), (byte) 1, (short) 0, null);
armorItem = new Item(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
}
PacketWrapper equipmentPacket = new PacketWrapper(0x46, null, connection);

View File

@ -55,7 +55,7 @@ public class EntityPackets {
if (type1_14 != null) {
int data = wrapper.get(Type.INT, 0);
if (type1_14.is(Entity1_14Types.EntityType.FALLING_BLOCK)) {
wrapper.set(Type.INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data));
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (type1_14.is(Entity1_14Types.EntityType.MINECART)) {
// default is 0 = rideable minecart
switch (data) {

View File

@ -47,7 +47,7 @@ public class InventoryPackets {
public static void register(Protocol protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
itemRewriter.registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerOutgoing(ClientboundPackets1_13.OPEN_WINDOW, null, new PacketRemapper() {
@ -234,7 +234,7 @@ public class InventoryPackets {
public static void toClient(Item item) {
if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getNewItemId(item.getIdentifier()));
CompoundTag tag;
if ((tag = item.getTag()) != null) {
@ -256,18 +256,9 @@ public class InventoryPackets {
}
}
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.14 item for 1.13.2 item " + id);
return 1;
}
return newId;
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getOldItemId(item.getIdentifier()));
CompoundTag tag;
if ((tag = item.getTag()) != null) {
@ -297,9 +288,4 @@ public class InventoryPackets {
}
}
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
return oldId != -1 ? oldId : 1;
}
}

View File

@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
@ -18,7 +17,6 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
@ -38,8 +36,8 @@ public class WorldPackets {
Arrays.fill(FULL_LIGHT, (byte) 0xff);
}
public static void register(final Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, null, Protocol1_14To1_13_2::getNewBlockStateId, Protocol1_14To1_13_2::getNewBlockId);
public static void register(Protocol1_14To1_13_2 protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, null);
protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_BREAK_ANIMATION, new PacketRemapper() {
@Override
@ -65,7 +63,7 @@ public class WorldPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
@ -80,7 +78,7 @@ public class WorldPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(id));
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(id));
}
});
}
@ -144,7 +142,7 @@ public class WorldPackets {
boolean hasBlock = false;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
int newId = Protocol1_14To1_13_2.getNewBlockStateId(old);
int newId = protocol.getMappingData().getNewBlockStateId(old);
if (!hasBlock && newId != air && newId != voidAir && newId != caveAir) { // air, void_air, cave_air
hasBlock = true;
}
@ -164,12 +162,12 @@ public class WorldPackets {
nonAirBlockCount++;
worldSurface[x + z * 16] = y + s * 16 + 1; // +1 (top of the block)
}
if (MappingData.motionBlocking.contains(id)) {
if (protocol.getMappingData().getMotionBlocking().contains(id)) {
motionBlocking[x + z * 16] = y + s * 16 + 1; // +1 (top of the block)
}
// Manually update light for non full blocks (block light must not be sent)
if (Via.getConfig().isNonFullBlockLightFix() && MappingData.nonFullBlocks.contains(id)) {
if (Via.getConfig().isNonFullBlockLightFix() && protocol.getMappingData().getNonFullBlocks().contains(id)) {
setNonFullLight(chunk, section, s, x, y, z);
}
}
@ -265,9 +263,9 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, InventoryPackets.getNewItemId(data));
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
} else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, Protocol1_14To1_13_2.getNewBlockStateId(data));
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
}
}
});

View File

@ -1,9 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.RegistryType;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
@ -21,27 +21,27 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1
public class Protocol1_15To1_14_4 extends Protocol<ClientboundPackets1_14, ClientboundPackets1_15, ServerboundPackets1_14, ServerboundPackets1_14> {
public static final MappingData MAPPINGS = new MappingData();
private TagRewriter tagRewriter;
public Protocol1_15To1_14_4() {
super(ClientboundPackets1_14.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class, true);
super(ClientboundPackets1_14.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class);
}
@Override
protected void registerPackets() {
MetadataRewriter1_15To1_14_4 metadataRewriter = new MetadataRewriter1_15To1_14_4(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_15To1_14_4(this);
EntityPackets.register(this);
PlayerPackets.register(this);
WorldPackets.register(this);
InventoryPackets.register(this);
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND); // Entity Sound Effect (added somewhere in 1.14)
soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
new StatisticsRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId,
metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_14.STATISTICS);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_14.STATISTICS);
registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
@ -50,14 +50,12 @@ public class Protocol1_15To1_14_4 extends Protocol<ClientboundPackets1_14, Clien
}
});
tagRewriter = new TagRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId, EntityPackets::getNewEntityId);
tagRewriter = new TagRewriter(this, EntityPackets::getNewEntityId);
tagRewriter.register(ClientboundPackets1_14.TAGS);
}
@Override
protected void loadMappingData() {
MappingData.init();
protected void onMappingDataLoaded() {
int[] shulkerBoxes = new int[17];
int shulkerBoxOffset = 501;
for (int i = 0; i < 17; i++) {
@ -66,26 +64,13 @@ public class Protocol1_15To1_14_4 extends Protocol<ClientboundPackets1_14, Clien
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:shulker_boxes", shulkerBoxes);
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.15 blockstate for 1.14.4 blockstate " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = MappingData.blockMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.15 block for 1.14.4 block " + id);
return 0;
}
return newId;
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_15(userConnection));
}
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -1,29 +1,22 @@
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data;
import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.Int2IntBiMap;
public class MappingData {
public static Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 mappings...");
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.14to1.15.json");
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
public MappingData() {
super("1.14", "1.15", true);
}
oldToNewItems.defaultReturnValue(-1);
blockStateMappings = new Mappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
statisticsMappings = new Mappings(mapping1_14.getAsJsonArray("statistics"), mapping1_15.getAsJsonArray("statistics"));
@Override
protected Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
if (!key.equals("sounds")) {
return super.loadFromArray(oldMappings, newMappings, diffMappings, key);
}
// Ignore removed sounds
return new Mappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), false);
}
}

View File

@ -27,7 +27,7 @@ public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter {
} 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));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;

View File

@ -18,7 +18,7 @@ public class EntityPackets {
public static void register(Protocol1_15To1_14_4 protocol) {
MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_15To1_14_4::getNewBlockStateId);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK);
protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() {
@Override

View File

@ -1,21 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
public class InventoryPackets {
public static void register(Protocol protocol) {
public static void register(Protocol1_15To1_14_4 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerTradeList(ClientboundPackets1_14.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
@ -30,25 +28,11 @@ public class InventoryPackets {
public static void toClient(Item item) {
if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_15To1_14_4.MAPPINGS.getNewItemId(item.getIdentifier()));
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
}
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.15 item for 1.14 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
return oldId != -1 ? oldId : 1;
item.setIdentifier(Protocol1_15To1_14_4.MAPPINGS.getOldItemId(item.getIdentifier()));
}
}

View File

@ -3,7 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
@ -15,8 +14,8 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
public class WorldPackets {
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15To1_14_4::getNewBlockStateId, Protocol1_15To1_14_4::getNewBlockId);
public static void register(Protocol1_15To1_14_4 protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_14.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_14.BLOCK_CHANGE);
@ -59,7 +58,7 @@ public class WorldPackets {
if (section == null) continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
int newId = Protocol1_15To1_14_4.getNewBlockStateId(old);
int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(i, newId);
}
}
@ -68,7 +67,7 @@ public class WorldPackets {
}
});
blockRewriter.registerEffect(ClientboundPackets1_14.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerEffect(ClientboundPackets1_14.EFFECT, 1010, 2001);
protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
@ -88,7 +87,7 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 23) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_15To1_14_4.getNewBlockStateId(data));
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) {
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}

View File

@ -1,9 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.RegistryType;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
@ -20,27 +20,27 @@ import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16
public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, ClientboundPackets1_16_2, ServerboundPackets1_16, ServerboundPackets1_16_2> {
public static final MappingData MAPPINGS = new MappingData();
private TagRewriter tagRewriter;
public Protocol1_16_2To1_16_1() {
super(ClientboundPackets1_16.class, ClientboundPackets1_16_2.class, ServerboundPackets1_16.class, ServerboundPackets1_16_2.class, true);
super(ClientboundPackets1_16.class, ClientboundPackets1_16_2.class, ServerboundPackets1_16.class, ServerboundPackets1_16_2.class);
}
@Override
protected void registerPackets() {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
EntityPackets.register(this);
WorldPackets.register(this);
InventoryPackets.register(this);
tagRewriter = new TagRewriter(this, Protocol1_16_2To1_16_1::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
tagRewriter.register(ClientboundPackets1_16.TAGS);
new StatisticsRewriter(this, Protocol1_16_2To1_16_1::getNewBlockId, InventoryPackets::getNewItemId,
metadataRewriter::getNewEntityId).register(ClientboundPackets1_16.STATISTICS);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_16.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
@ -77,9 +77,7 @@ public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, Cli
}
@Override
protected void loadMappingData() {
MappingData.init();
protected void onMappingDataLoaded() {
tagRewriter.addTag(RegistryType.ITEM, "minecraft:stone_crafting_materials", 14, 962);
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:mushroom_grow_block");
@ -95,26 +93,13 @@ public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, Cli
"minecraft:base_stone_nether", "minecraft:base_stone_overworld");
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 blockstate for 1.16 blockstate " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = MappingData.blockMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 block for 1.16 block " + id);
return 0;
}
return newId;
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_16_2(userConnection));
}
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -7,28 +7,22 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.api.minecraft.nbt.BinaryTagIO;
import us.myles.ViaVersion.util.Int2IntBiMap;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class MappingData {
public static CompoundTag dimensionRegistry;
public static Map<String, CompoundTag> dimensionDataMap = new HashMap<>();
public static Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
private final Map<String, CompoundTag> dimensionDataMap = new HashMap<>();
private CompoundTag dimensionRegistry;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.16.1 -> 1.16.2 mappings...");
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.16.1to1.16.2.json");
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);
JsonObject mapping1_16_2 = MappingDataLoader.loadData("mapping-1.16.2.json", true);
public MappingData() {
super("1.16", "1.16.2", true);
}
@Override
public void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
try {
dimensionRegistry = BinaryTagIO.readCompressedInputStream(MappingDataLoader.getResource("dimension-registry-1.16.2.nbt"));
} catch (IOException e) {
@ -36,12 +30,6 @@ public class MappingData {
e.printStackTrace();
}
oldToNewItems.defaultReturnValue(-1);
blockStateMappings = new Mappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_16_2.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
blockMappings = new Mappings(mapping1_16.getAsJsonObject("blocks"), mapping1_16_2.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_16.getAsJsonObject("items"), mapping1_16_2.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_16.getAsJsonArray("sounds"), mapping1_16_2.getAsJsonArray("sounds"));
// Data of each dimension
ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value");
for (Tag dimension : dimensions) {
@ -51,4 +39,12 @@ public class MappingData {
dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData);
}
}
public Map<String, CompoundTag> getDimensionDataMap() {
return dimensionDataMap;
}
public CompoundTag getDimensionRegistry() {
return dimensionRegistry;
}
}

View File

@ -27,7 +27,7 @@ public class MetadataRewriter1_16_2To1_16_1 extends MetadataRewriter {
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_16_2To1_16_1.getNewBlockStateId(data));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;

View File

@ -7,7 +7,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
@ -16,8 +15,7 @@ public class EntityPackets {
public static void register(Protocol1_16_2To1_16_1 protocol) {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK, Protocol1_16_2To1_16_1::getNewBlockStateId);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16_2Types.EntityType.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST);
@ -39,7 +37,7 @@ public class EntityPackets {
handler(wrapper -> {
// Throw away the old dimension registry, extra conversion would be too hard of a hit
wrapper.read(Type.NBT);
wrapper.write(Type.NBT, MappingData.dimensionRegistry);
wrapper.write(Type.NBT, protocol.getMappingData().getDimensionRegistry());
// Instead of the dimension's resource key, it now just wants the data directly
String dimensionType = wrapper.read(Type.STRING);
@ -67,7 +65,7 @@ public class EntityPackets {
}
public static CompoundTag getDimensionData(String dimensionType) {
CompoundTag tag = MappingData.dimensionDataMap.get(dimensionType);
CompoundTag tag = Protocol1_16_2To1_16_1.MAPPINGS.getDimensionDataMap().get(dimensionType);
if (tag == null) {
Via.getPlatform().getLogger().severe("Could not get dimension data of " + dimensionType);
throw new NullPointerException("Dimension data for " + dimensionType + " is null!");

View File

@ -1,13 +1,11 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
@ -16,7 +14,7 @@ public class InventoryPackets {
public static void register(Protocol1_16_2To1_16_1 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
@ -55,25 +53,11 @@ public class InventoryPackets {
public static void toClient(Item item) {
if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_16_2To1_16_1.MAPPINGS.getNewItemId(item.getIdentifier()));
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
}
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 item for 1.16 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
return oldId != -1 ? oldId : 1;
item.setIdentifier(Protocol1_16_2To1_16_1.MAPPINGS.getOldItemId(item.getIdentifier()));
}
}

View File

@ -23,7 +23,7 @@ public class WorldPackets {
private static final BlockChangeRecord[] EMPTY_RECORDS = new BlockChangeRecord[0];
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16_2To1_16_1::getNewBlockStateId, Protocol1_16_2To1_16_1::getNewBlockId);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
@ -41,7 +41,7 @@ public class WorldPackets {
if (section == null) continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
section.setPaletteEntry(i, Protocol1_16_2To1_16_1.getNewBlockStateId(old));
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old));
}
}
});
@ -71,7 +71,7 @@ public class WorldPackets {
}
// Absolute y -> relative chunk section y
int blockId = Protocol1_16_2To1_16_1.getNewBlockStateId(record.getBlockId());
int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
list.add(new BlockChangeRecord1_16_2(record.getSectionX(), record.getSectionY(), record.getSectionZ(), blockId));
}
@ -90,7 +90,7 @@ public class WorldPackets {
}
});
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
blockRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, 3, 23, 34,
null, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}

View File

@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.rewriters.RegistryType;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
@ -35,25 +36,25 @@ import java.util.UUID;
public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, ClientboundPackets1_16, ServerboundPackets1_14, ServerboundPackets1_16> {
private static final UUID ZERO_UUID = new UUID(0, 0);
public static final MappingData MAPPINGS = new MappingData();
private TagRewriter tagRewriter;
public Protocol1_16To1_15_2() {
super(ClientboundPackets1_15.class, ClientboundPackets1_16.class, ServerboundPackets1_14.class, ServerboundPackets1_16.class, true);
super(ClientboundPackets1_15.class, ClientboundPackets1_16.class, ServerboundPackets1_14.class, ServerboundPackets1_16.class);
}
@Override
protected void registerPackets() {
MetadataRewriter1_16To1_15_2 metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
EntityPackets.register(this);
WorldPackets.register(this);
InventoryPackets.register(this);
tagRewriter = new TagRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
tagRewriter.register(ClientboundPackets1_15.TAGS);
new StatisticsRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId,
metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_15.STATISTICS);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_15.STATISTICS);
// Login Success
registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@ -124,7 +125,7 @@ public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, Clien
componentRewriter.registerTitle(ClientboundPackets1_15.TITLE);
componentRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
@ -206,9 +207,7 @@ public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, Clien
}
@Override
protected void loadMappingData() {
MappingData.init();
protected void onMappingDataLoaded() {
int[] wallPostOverrideTag = new int[47];
int arrayIndex = 0;
wallPostOverrideTag[arrayIndex++] = 140;
@ -253,27 +252,14 @@ public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, Clien
"minecraft:lectern_books", "minecraft:music_discs", "minecraft:small_flowers", "minecraft:tall_flowers", "minecraft:trapdoors", "minecraft:walls", "minecraft:wooden_fences");
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16 blockstate for 1.15.2 blockstate " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = MappingData.blockMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16 block for 1.15.2 block " + id);
return 0;
}
return newId;
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_16(userConnection));
userConnection.put(new InventoryTracker1_16(userConnection));
}
@Override
public MappingData getMappingData() {
return MAPPINGS;
}
}

View File

@ -3,32 +3,16 @@ package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.Int2IntBiMap;
public class MappingData {
public static Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static BiMap<String, String> attributeMappings = HashBiMap.create();
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
private final BiMap<String, String> attributeMappings = HashBiMap.create();
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 mappings...");
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.15to1.16.json");
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);
oldToNewItems.defaultReturnValue(-1);
blockStateMappings = new Mappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_15.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), diffmapping.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_15.getAsJsonArray("statistics"), mapping1_16.getAsJsonArray("statistics"));
public MappingData() {
super("1.15", "1.16", true);
}
@Override
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");
attributeMappings.put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements");
attributeMappings.put("horse.jumpStrength", "minecraft:horse.jump_strength");
@ -41,4 +25,8 @@ public class MappingData {
attributeMappings.put("generic.attackSpeed", "minecraft:generic.attack_speed");
attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness");
}
public BiMap<String, String> getAttributeMappings() {
return attributeMappings;
}
}

View File

@ -30,7 +30,7 @@ public class MetadataRewriter1_16To1_15_2 extends MetadataRewriter {
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));
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;

View File

@ -17,7 +17,6 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
@ -156,7 +155,7 @@ public class EntityPackets {
}
});
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_16To1_15_2::getNewBlockStateId);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.EntityType.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
@ -215,7 +214,7 @@ public class EntityPackets {
for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Type.STRING);
String attributeIdentifier = MappingData.attributeMappings.get(key);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = "minecraft:" + key;
if (!us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) {

View File

@ -6,24 +6,22 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.UUIDIntArrayType;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import java.util.UUID;
public class InventoryPackets {
public static void register(Protocol protocol) {
public static void register(Protocol1_16To1_15_2 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
protocol.registerOutgoing(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {
@ -76,7 +74,7 @@ public class InventoryPackets {
}
});
itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
@ -137,13 +135,13 @@ public class InventoryPackets {
}
oldToNewAttributes(item);
item.setIdentifier(getNewItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getNewItemId(item.getIdentifier()));
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.getIdentifier()));
if (item.getIdentifier() == 771 && item.getTag() != null) {
CompoundTag tag = item.getTag();
@ -200,7 +198,7 @@ public class InventoryPackets {
}
public static void rewriteAttributeName(CompoundTag compoundTag, String entryName, boolean inverse) {
StringTag attributeNameTag = compoundTag.get("AttributeName");
StringTag attributeNameTag = compoundTag.get(entryName);
if (attributeNameTag == null) return;
String attributeName = attributeNameTag.getValue();
@ -208,23 +206,10 @@ public class InventoryPackets {
attributeName = "minecraft:" + attributeName;
}
String mappedAttribute = (inverse ? MappingData.attributeMappings.inverse() : MappingData.attributeMappings).get(attributeName);
String mappedAttribute = (inverse ? Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings().inverse()
: Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings()).get(attributeName);
if (mappedAttribute == null) return;
attributeNameTag.setValue(mappedAttribute);
}
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16 item for 1.15.2 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
return oldId != -1 ? oldId : 1;
}
}

View File

@ -8,7 +8,6 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.type.Type;
@ -23,8 +22,8 @@ import java.util.UUID;
public class WorldPackets {
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16To1_15_2::getNewBlockStateId, Protocol1_16To1_15_2::getNewBlockId);
public static void register(Protocol1_16To1_15_2 protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
@ -54,7 +53,7 @@ public class WorldPackets {
if (section == null) continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
section.setPaletteEntry(i, Protocol1_16To1_15_2.getNewBlockStateId(old));
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old));
}
}
@ -86,7 +85,7 @@ public class WorldPackets {
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32,
WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}

View File

@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_8.ClientboundPackets1_8;
@ -94,7 +95,7 @@ public class Protocol1_9To1_8 extends Protocol<ClientboundPackets1_8, Clientboun
@Override
protected void registerPackets() {
new MetadataRewriter1_9To1_8(this);
MetadataRewriter metadataRewriter = new MetadataRewriter1_9To1_8(this);
// Disconnect workaround (JSON!)
registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {

View File

@ -1,5 +1,5 @@
{
"blocks": {
"blockstates": {
"0": "minecraft:air",
"1": "minecraft:stone",
"2": "minecraft:granite",
@ -9370,6 +9370,601 @@
"783": "minecraft:nautilus_shell",
"784": "minecraft:heart_of_the_sea"
},
"blocks": {
"0": "air",
"1": "stone",
"2": "granite",
"3": "polished_granite",
"4": "diorite",
"5": "polished_diorite",
"6": "andesite",
"7": "polished_andesite",
"8": "grass_block",
"9": "dirt",
"10": "coarse_dirt",
"11": "podzol",
"12": "cobblestone",
"13": "oak_planks",
"14": "spruce_planks",
"15": "birch_planks",
"16": "jungle_planks",
"17": "acacia_planks",
"18": "dark_oak_planks",
"19": "oak_sapling",
"20": "spruce_sapling",
"21": "birch_sapling",
"22": "jungle_sapling",
"23": "acacia_sapling",
"24": "dark_oak_sapling",
"25": "bedrock",
"26": "water",
"27": "lava",
"28": "sand",
"29": "red_sand",
"30": "gravel",
"31": "gold_ore",
"32": "iron_ore",
"33": "coal_ore",
"34": "oak_log",
"35": "spruce_log",
"36": "birch_log",
"37": "jungle_log",
"38": "acacia_log",
"39": "dark_oak_log",
"40": "stripped_spruce_log",
"41": "stripped_birch_log",
"42": "stripped_jungle_log",
"43": "stripped_acacia_log",
"44": "stripped_dark_oak_log",
"45": "stripped_oak_log",
"46": "oak_wood",
"47": "spruce_wood",
"48": "birch_wood",
"49": "jungle_wood",
"50": "acacia_wood",
"51": "dark_oak_wood",
"52": "stripped_oak_wood",
"53": "stripped_spruce_wood",
"54": "stripped_birch_wood",
"55": "stripped_jungle_wood",
"56": "stripped_acacia_wood",
"57": "stripped_dark_oak_wood",
"58": "oak_leaves",
"59": "spruce_leaves",
"60": "birch_leaves",
"61": "jungle_leaves",
"62": "acacia_leaves",
"63": "dark_oak_leaves",
"64": "sponge",
"65": "wet_sponge",
"66": "glass",
"67": "lapis_ore",
"68": "lapis_block",
"69": "dispenser",
"70": "sandstone",
"71": "chiseled_sandstone",
"72": "cut_sandstone",
"73": "note_block",
"74": "white_bed",
"75": "orange_bed",
"76": "magenta_bed",
"77": "light_blue_bed",
"78": "yellow_bed",
"79": "lime_bed",
"80": "pink_bed",
"81": "gray_bed",
"82": "light_gray_bed",
"83": "cyan_bed",
"84": "purple_bed",
"85": "blue_bed",
"86": "brown_bed",
"87": "green_bed",
"88": "red_bed",
"89": "black_bed",
"90": "powered_rail",
"91": "detector_rail",
"92": "sticky_piston",
"93": "cobweb",
"94": "grass",
"95": "fern",
"96": "dead_bush",
"97": "seagrass",
"98": "tall_seagrass",
"99": "piston",
"100": "piston_head",
"101": "white_wool",
"102": "orange_wool",
"103": "magenta_wool",
"104": "light_blue_wool",
"105": "yellow_wool",
"106": "lime_wool",
"107": "pink_wool",
"108": "gray_wool",
"109": "light_gray_wool",
"110": "cyan_wool",
"111": "purple_wool",
"112": "blue_wool",
"113": "brown_wool",
"114": "green_wool",
"115": "red_wool",
"116": "black_wool",
"117": "moving_piston",
"118": "dandelion",
"119": "poppy",
"120": "blue_orchid",
"121": "allium",
"122": "azure_bluet",
"123": "red_tulip",
"124": "orange_tulip",
"125": "white_tulip",
"126": "pink_tulip",
"127": "oxeye_daisy",
"128": "brown_mushroom",
"129": "red_mushroom",
"130": "gold_block",
"131": "iron_block",
"132": "bricks",
"133": "tnt",
"134": "bookshelf",
"135": "mossy_cobblestone",
"136": "obsidian",
"137": "torch",
"138": "wall_torch",
"139": "fire",
"140": "spawner",
"141": "oak_stairs",
"142": "chest",
"143": "redstone_wire",
"144": "diamond_ore",
"145": "diamond_block",
"146": "crafting_table",
"147": "wheat",
"148": "farmland",
"149": "furnace",
"150": "oak_sign",
"151": "oak_door",
"152": "ladder",
"153": "rail",
"154": "cobblestone_stairs",
"155": "oak_wall_sign",
"156": "lever",
"157": "stone_pressure_plate",
"158": "iron_door",
"159": "oak_pressure_plate",
"160": "spruce_pressure_plate",
"161": "birch_pressure_plate",
"162": "jungle_pressure_plate",
"163": "acacia_pressure_plate",
"164": "dark_oak_pressure_plate",
"165": "redstone_ore",
"166": "redstone_torch",
"167": "redstone_wall_torch",
"168": "stone_button",
"169": "snow",
"170": "ice",
"171": "snow_block",
"172": "cactus",
"173": "clay",
"174": "sugar_cane",
"175": "jukebox",
"176": "oak_fence",
"177": "pumpkin",
"178": "netherrack",
"179": "soul_sand",
"180": "glowstone",
"181": "nether_portal",
"182": "carved_pumpkin",
"183": "jack_o_lantern",
"184": "cake",
"185": "repeater",
"186": "white_stained_glass",
"187": "orange_stained_glass",
"188": "magenta_stained_glass",
"189": "light_blue_stained_glass",
"190": "yellow_stained_glass",
"191": "lime_stained_glass",
"192": "pink_stained_glass",
"193": "gray_stained_glass",
"194": "light_gray_stained_glass",
"195": "cyan_stained_glass",
"196": "purple_stained_glass",
"197": "blue_stained_glass",
"198": "brown_stained_glass",
"199": "green_stained_glass",
"200": "red_stained_glass",
"201": "black_stained_glass",
"202": "oak_trapdoor",
"203": "spruce_trapdoor",
"204": "birch_trapdoor",
"205": "jungle_trapdoor",
"206": "acacia_trapdoor",
"207": "dark_oak_trapdoor",
"208": "infested_stone",
"209": "infested_cobblestone",
"210": "infested_stone_bricks",
"211": "infested_mossy_stone_bricks",
"212": "infested_cracked_stone_bricks",
"213": "infested_chiseled_stone_bricks",
"214": "stone_bricks",
"215": "mossy_stone_bricks",
"216": "cracked_stone_bricks",
"217": "chiseled_stone_bricks",
"218": "brown_mushroom_block",
"219": "red_mushroom_block",
"220": "mushroom_stem",
"221": "iron_bars",
"222": "glass_pane",
"223": "melon",
"224": "attached_pumpkin_stem",
"225": "attached_melon_stem",
"226": "pumpkin_stem",
"227": "melon_stem",
"228": "vine",
"229": "oak_fence_gate",
"230": "brick_stairs",
"231": "stone_brick_stairs",
"232": "mycelium",
"233": "lily_pad",
"234": "nether_bricks",
"235": "nether_brick_fence",
"236": "nether_brick_stairs",
"237": "nether_wart",
"238": "enchanting_table",
"239": "brewing_stand",
"240": "cauldron",
"241": "end_portal",
"242": "end_portal_frame",
"243": "end_stone",
"244": "dragon_egg",
"245": "redstone_lamp",
"246": "cocoa",
"247": "sandstone_stairs",
"248": "emerald_ore",
"249": "ender_chest",
"250": "tripwire_hook",
"251": "tripwire",
"252": "emerald_block",
"253": "spruce_stairs",
"254": "birch_stairs",
"255": "jungle_stairs",
"256": "command_block",
"257": "beacon",
"258": "cobblestone_wall",
"259": "mossy_cobblestone_wall",
"260": "flower_pot",
"261": "potted_oak_sapling",
"262": "potted_spruce_sapling",
"263": "potted_birch_sapling",
"264": "potted_jungle_sapling",
"265": "potted_acacia_sapling",
"266": "potted_dark_oak_sapling",
"267": "potted_fern",
"268": "potted_dandelion",
"269": "potted_poppy",
"270": "potted_blue_orchid",
"271": "potted_allium",
"272": "potted_azure_bluet",
"273": "potted_red_tulip",
"274": "potted_orange_tulip",
"275": "potted_white_tulip",
"276": "potted_pink_tulip",
"277": "potted_oxeye_daisy",
"278": "potted_red_mushroom",
"279": "potted_brown_mushroom",
"280": "potted_dead_bush",
"281": "potted_cactus",
"282": "carrots",
"283": "potatoes",
"284": "oak_button",
"285": "spruce_button",
"286": "birch_button",
"287": "jungle_button",
"288": "acacia_button",
"289": "dark_oak_button",
"290": "skeleton_wall_skull",
"291": "skeleton_skull",
"292": "wither_skeleton_wall_skull",
"293": "wither_skeleton_skull",
"294": "zombie_wall_head",
"295": "zombie_head",
"296": "player_wall_head",
"297": "player_head",
"298": "creeper_wall_head",
"299": "creeper_head",
"300": "dragon_wall_head",
"301": "dragon_head",
"302": "anvil",
"303": "chipped_anvil",
"304": "damaged_anvil",
"305": "trapped_chest",
"306": "light_weighted_pressure_plate",
"307": "heavy_weighted_pressure_plate",
"308": "comparator",
"309": "daylight_detector",
"310": "redstone_block",
"311": "nether_quartz_ore",
"312": "hopper",
"313": "quartz_block",
"314": "chiseled_quartz_block",
"315": "quartz_pillar",
"316": "quartz_stairs",
"317": "activator_rail",
"318": "dropper",
"319": "white_terracotta",
"320": "orange_terracotta",
"321": "magenta_terracotta",
"322": "light_blue_terracotta",
"323": "yellow_terracotta",
"324": "lime_terracotta",
"325": "pink_terracotta",
"326": "gray_terracotta",
"327": "light_gray_terracotta",
"328": "cyan_terracotta",
"329": "purple_terracotta",
"330": "blue_terracotta",
"331": "brown_terracotta",
"332": "green_terracotta",
"333": "red_terracotta",
"334": "black_terracotta",
"335": "white_stained_glass_pane",
"336": "orange_stained_glass_pane",
"337": "magenta_stained_glass_pane",
"338": "light_blue_stained_glass_pane",
"339": "yellow_stained_glass_pane",
"340": "lime_stained_glass_pane",
"341": "pink_stained_glass_pane",
"342": "gray_stained_glass_pane",
"343": "light_gray_stained_glass_pane",
"344": "cyan_stained_glass_pane",
"345": "purple_stained_glass_pane",
"346": "blue_stained_glass_pane",
"347": "brown_stained_glass_pane",
"348": "green_stained_glass_pane",
"349": "red_stained_glass_pane",
"350": "black_stained_glass_pane",
"351": "acacia_stairs",
"352": "dark_oak_stairs",
"353": "slime_block",
"354": "barrier",
"355": "iron_trapdoor",
"356": "prismarine",
"357": "prismarine_bricks",
"358": "dark_prismarine",
"359": "prismarine_stairs",
"360": "prismarine_brick_stairs",
"361": "dark_prismarine_stairs",
"362": "prismarine_slab",
"363": "prismarine_brick_slab",
"364": "dark_prismarine_slab",
"365": "sea_lantern",
"366": "hay_block",
"367": "white_carpet",
"368": "orange_carpet",
"369": "magenta_carpet",
"370": "light_blue_carpet",
"371": "yellow_carpet",
"372": "lime_carpet",
"373": "pink_carpet",
"374": "gray_carpet",
"375": "light_gray_carpet",
"376": "cyan_carpet",
"377": "purple_carpet",
"378": "blue_carpet",
"379": "brown_carpet",
"380": "green_carpet",
"381": "red_carpet",
"382": "black_carpet",
"383": "terracotta",
"384": "coal_block",
"385": "packed_ice",
"386": "sunflower",
"387": "lilac",
"388": "rose_bush",
"389": "peony",
"390": "tall_grass",
"391": "large_fern",
"392": "white_banner",
"393": "orange_banner",
"394": "magenta_banner",
"395": "light_blue_banner",
"396": "yellow_banner",
"397": "lime_banner",
"398": "pink_banner",
"399": "gray_banner",
"400": "light_gray_banner",
"401": "cyan_banner",
"402": "purple_banner",
"403": "blue_banner",
"404": "brown_banner",
"405": "green_banner",
"406": "red_banner",
"407": "black_banner",
"408": "white_wall_banner",
"409": "orange_wall_banner",
"410": "magenta_wall_banner",
"411": "light_blue_wall_banner",
"412": "yellow_wall_banner",
"413": "lime_wall_banner",
"414": "pink_wall_banner",
"415": "gray_wall_banner",
"416": "light_gray_wall_banner",
"417": "cyan_wall_banner",
"418": "purple_wall_banner",
"419": "blue_wall_banner",
"420": "brown_wall_banner",
"421": "green_wall_banner",
"422": "red_wall_banner",
"423": "black_wall_banner",
"424": "red_sandstone",
"425": "chiseled_red_sandstone",
"426": "cut_red_sandstone",
"427": "red_sandstone_stairs",
"428": "oak_slab",
"429": "spruce_slab",
"430": "birch_slab",
"431": "jungle_slab",
"432": "acacia_slab",
"433": "dark_oak_slab",
"434": "smooth_stone_slab",
"435": "sandstone_slab",
"436": "petrified_oak_slab",
"437": "cobblestone_slab",
"438": "brick_slab",
"439": "stone_brick_slab",
"440": "nether_brick_slab",
"441": "quartz_slab",
"442": "red_sandstone_slab",
"443": "purpur_slab",
"444": "smooth_stone",
"445": "smooth_sandstone",
"446": "smooth_quartz",
"447": "smooth_red_sandstone",
"448": "spruce_fence_gate",
"449": "birch_fence_gate",
"450": "jungle_fence_gate",
"451": "acacia_fence_gate",
"452": "dark_oak_fence_gate",
"453": "spruce_fence",
"454": "birch_fence",
"455": "jungle_fence",
"456": "acacia_fence",
"457": "dark_oak_fence",
"458": "spruce_door",
"459": "birch_door",
"460": "jungle_door",
"461": "acacia_door",
"462": "dark_oak_door",
"463": "end_rod",
"464": "chorus_plant",
"465": "chorus_flower",
"466": "purpur_block",
"467": "purpur_pillar",
"468": "purpur_stairs",
"469": "end_stone_bricks",
"470": "beetroots",
"471": "grass_path",
"472": "end_gateway",
"473": "repeating_command_block",
"474": "chain_command_block",
"475": "frosted_ice",
"476": "magma_block",
"477": "nether_wart_block",
"478": "red_nether_bricks",
"479": "bone_block",
"480": "structure_void",
"481": "observer",
"482": "shulker_box",
"483": "white_shulker_box",
"484": "orange_shulker_box",
"485": "magenta_shulker_box",
"486": "light_blue_shulker_box",
"487": "yellow_shulker_box",
"488": "lime_shulker_box",
"489": "pink_shulker_box",
"490": "gray_shulker_box",
"491": "light_gray_shulker_box",
"492": "cyan_shulker_box",
"493": "purple_shulker_box",
"494": "blue_shulker_box",
"495": "brown_shulker_box",
"496": "green_shulker_box",
"497": "red_shulker_box",
"498": "black_shulker_box",
"499": "white_glazed_terracotta",
"500": "orange_glazed_terracotta",
"501": "magenta_glazed_terracotta",
"502": "light_blue_glazed_terracotta",
"503": "yellow_glazed_terracotta",
"504": "lime_glazed_terracotta",
"505": "pink_glazed_terracotta",
"506": "gray_glazed_terracotta",
"507": "light_gray_glazed_terracotta",
"508": "cyan_glazed_terracotta",
"509": "purple_glazed_terracotta",
"510": "blue_glazed_terracotta",
"511": "brown_glazed_terracotta",
"512": "green_glazed_terracotta",
"513": "red_glazed_terracotta",
"514": "black_glazed_terracotta",
"515": "white_concrete",
"516": "orange_concrete",
"517": "magenta_concrete",
"518": "light_blue_concrete",
"519": "yellow_concrete",
"520": "lime_concrete",
"521": "pink_concrete",
"522": "gray_concrete",
"523": "light_gray_concrete",
"524": "cyan_concrete",
"525": "purple_concrete",
"526": "blue_concrete",
"527": "brown_concrete",
"528": "green_concrete",
"529": "red_concrete",
"530": "black_concrete",
"531": "white_concrete_powder",
"532": "orange_concrete_powder",
"533": "magenta_concrete_powder",
"534": "light_blue_concrete_powder",
"535": "yellow_concrete_powder",
"536": "lime_concrete_powder",
"537": "pink_concrete_powder",
"538": "gray_concrete_powder",
"539": "light_gray_concrete_powder",
"540": "cyan_concrete_powder",
"541": "purple_concrete_powder",
"542": "blue_concrete_powder",
"543": "brown_concrete_powder",
"544": "green_concrete_powder",
"545": "red_concrete_powder",
"546": "black_concrete_powder",
"547": "kelp",
"548": "kelp_plant",
"549": "dried_kelp_block",
"550": "turtle_egg",
"551": "dead_tube_coral_block",
"552": "dead_brain_coral_block",
"553": "dead_bubble_coral_block",
"554": "dead_fire_coral_block",
"555": "dead_horn_coral_block",
"556": "tube_coral_block",
"557": "brain_coral_block",
"558": "bubble_coral_block",
"559": "fire_coral_block",
"560": "horn_coral_block",
"561": "tube_coral",
"562": "brain_coral",
"563": "bubble_coral",
"564": "fire_coral",
"565": "horn_coral",
"566": "dead_tube_coral_wall_fan",
"567": "dead_brain_coral_wall_fan",
"568": "dead_bubble_coral_wall_fan",
"569": "dead_fire_coral_wall_fan",
"570": "dead_horn_coral_wall_fan",
"571": "tube_coral_wall_fan",
"572": "brain_coral_wall_fan",
"573": "bubble_coral_wall_fan",
"574": "fire_coral_wall_fan",
"575": "horn_coral_wall_fan",
"576": "dead_tube_coral_fan",
"577": "dead_brain_coral_fan",
"578": "dead_bubble_coral_fan",
"579": "dead_fire_coral_fan",
"580": "dead_horn_coral_fan",
"581": "tube_coral_fan",
"582": "brain_coral_fan",
"583": "bubble_coral_fan",
"584": "fire_coral_fan",
"585": "horn_coral_fan",
"586": "sea_pickle",
"587": "blue_ice",
"588": "conduit",
"589": "void_air",
"590": "cave_air",
"591": "bubble_column",
"592": "structure_block"
},
"block_tags": {
"minecraft:impermeable": [
66,

View File

@ -0,0 +1,64 @@
{
"blockstates": {
"1126": "minecraft:tnt[unstable=false]",
"3075": "minecraft:oak_sign[rotation=0,waterlogged=true]",
"3076": "minecraft:oak_sign[rotation=0,waterlogged=false]",
"3077": "minecraft:oak_sign[rotation=1,waterlogged=true]",
"3078": "minecraft:oak_sign[rotation=1,waterlogged=false]",
"3079": "minecraft:oak_sign[rotation=2,waterlogged=true]",
"3080": "minecraft:oak_sign[rotation=2,waterlogged=false]",
"3081": "minecraft:oak_sign[rotation=3,waterlogged=true]",
"3082": "minecraft:oak_sign[rotation=3,waterlogged=false]",
"3083": "minecraft:oak_sign[rotation=4,waterlogged=true]",
"3084": "minecraft:oak_sign[rotation=4,waterlogged=false]",
"3085": "minecraft:oak_sign[rotation=5,waterlogged=true]",
"3086": "minecraft:oak_sign[rotation=5,waterlogged=false]",
"3087": "minecraft:oak_sign[rotation=6,waterlogged=true]",
"3088": "minecraft:oak_sign[rotation=6,waterlogged=false]",
"3089": "minecraft:oak_sign[rotation=7,waterlogged=true]",
"3090": "minecraft:oak_sign[rotation=7,waterlogged=false]",
"3091": "minecraft:oak_sign[rotation=8,waterlogged=true]",
"3092": "minecraft:oak_sign[rotation=8,waterlogged=false]",
"3093": "minecraft:oak_sign[rotation=9,waterlogged=true]",
"3094": "minecraft:oak_sign[rotation=9,waterlogged=false]",
"3095": "minecraft:oak_sign[rotation=10,waterlogged=true]",
"3096": "minecraft:oak_sign[rotation=10,waterlogged=false]",
"3097": "minecraft:oak_sign[rotation=11,waterlogged=true]",
"3098": "minecraft:oak_sign[rotation=11,waterlogged=false]",
"3099": "minecraft:oak_sign[rotation=12,waterlogged=true]",
"3100": "minecraft:oak_sign[rotation=12,waterlogged=false]",
"3101": "minecraft:oak_sign[rotation=13,waterlogged=true]",
"3102": "minecraft:oak_sign[rotation=13,waterlogged=false]",
"3103": "minecraft:oak_sign[rotation=14,waterlogged=true]",
"3104": "minecraft:oak_sign[rotation=14,waterlogged=false]",
"3105": "minecraft:oak_sign[rotation=15,waterlogged=true]",
"3106": "minecraft:oak_sign[rotation=15,waterlogged=false]",
"3269": "minecraft:oak_wall_sign[facing=north,waterlogged=true]",
"3270": "minecraft:oak_wall_sign[facing=north,waterlogged=false]",
"3271": "minecraft:oak_wall_sign[facing=south,waterlogged=true]",
"3272": "minecraft:oak_wall_sign[facing=south,waterlogged=false]",
"3273": "minecraft:oak_wall_sign[facing=west,waterlogged=true]",
"3274": "minecraft:oak_wall_sign[facing=west,waterlogged=false]",
"3275": "minecraft:oak_wall_sign[facing=east,waterlogged=true]",
"3276": "minecraft:oak_wall_sign[facing=east,waterlogged=false]",
"7293": "minecraft:smooth_stone_slab[type=top,waterlogged=true]",
"7294": "minecraft:smooth_stone_slab[type=top,waterlogged=false]",
"7295": "minecraft:smooth_stone_slab[type=bottom,waterlogged=true]",
"7296": "minecraft:smooth_stone_slab[type=bottom,waterlogged=false]",
"7297": "minecraft:smooth_stone_slab[type=double,waterlogged=true]",
"7298": "minecraft:smooth_stone_slab[type=double,waterlogged=false]",
"8459": "minecraft:tube_coral[waterlogged=true]",
"8460": "minecraft:brain_coral[waterlogged=true]",
"8461": "minecraft:bubble_coral[waterlogged=true]",
"8462": "minecraft:fire_coral[waterlogged=true]",
"8463": "minecraft:horn_coral[waterlogged=true]",
"8573": "minecraft:conduit[waterlogged=true]"
},
"items": {
"118": "minecraft:smooth_stone_slab",
"536": "minecraft:oak_sign",
"573": "minecraft:red_dye",
"574": "minecraft:green_dye",
"583": "minecraft:yellow_dye"
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

View File

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.1.1-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>