3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-25 15:50:12 +01:00

Abstract mapping data loading

Dieser Commit ist enthalten in:
KennyTV 2020-08-16 20:17:04 +02:00
Ursprung ececd96718
Commit 947e5c3e07
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
52 geänderte Dateien mit 429 neuen und 671 gelöschten Zeilen

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-all</artifactId> <artifactId>viabackwards-all</artifactId>

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-bukkit</artifactId> <artifactId>viabackwards-bukkit</artifactId>

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-bungee</artifactId> <artifactId>viabackwards-bungee</artifactId>

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-core</artifactId> <artifactId>viabackwards-core</artifactId>

Datei anzeigen

@ -1,5 +1,6 @@
package nl.matsv.viabackwards.api; package nl.matsv.viabackwards.api;
import nl.matsv.viabackwards.api.data.BackwardsMappings;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -12,18 +13,9 @@ public abstract class BackwardsProtocol<C1 extends ClientboundPacketType, C2 ext
protected BackwardsProtocol() { protected BackwardsProtocol() {
} }
protected BackwardsProtocol(boolean hasMappingDataToLoad) {
super(hasMappingDataToLoad);
}
protected BackwardsProtocol(@Nullable Class<C1> oldClientboundPacketEnum, @Nullable Class<C2> clientboundPacketEnum, protected BackwardsProtocol(@Nullable Class<C1> oldClientboundPacketEnum, @Nullable Class<C2> clientboundPacketEnum,
@Nullable Class<S1> oldServerboundPacketEnum, @Nullable Class<S2> serverboundPacketEnum) { @Nullable Class<S1> oldServerboundPacketEnum, @Nullable Class<S2> serverboundPacketEnum) {
super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, false); super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum);
}
protected BackwardsProtocol(@Nullable Class<C1> oldClientboundPacketEnum, @Nullable Class<C2> clientboundPacketEnum,
@Nullable Class<S1> oldServerboundPacketEnum, @Nullable Class<S2> serverboundPacketEnum, boolean hasMappingDatatToLoad) {
super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, hasMappingDatatToLoad);
} }
/** /**
@ -32,4 +24,9 @@ public abstract class BackwardsProtocol<C1 extends ClientboundPacketType, C2 ext
protected void executeAsyncAfterLoaded(Class<? extends Protocol> protocolClass, Runnable runnable) { protected void executeAsyncAfterLoaded(Class<? extends Protocol> protocolClass, Runnable runnable) {
ProtocolRegistry.addMappingLoaderFuture(getClass(), protocolClass, runnable); ProtocolRegistry.addMappingLoaderFuture(getClass(), protocolClass, runnable);
} }
@Override
public BackwardsMappings getMappingData() {
return null;
}
} }

Datei anzeigen

@ -0,0 +1,118 @@
package nl.matsv.viabackwards.api.data;
import com.google.common.base.Preconditions;
import nl.matsv.viabackwards.api.BackwardsProtocol;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.data.MappingData;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.gson.JsonObject;
import java.util.Map;
public class BackwardsMappings extends MappingData {
private final Class<? extends Protocol> vvProtocolClass;
private Int2ObjectMap<MappedItem> backwardsItemMappings;
private Map<String, String> backwardsSoundMappings;
public BackwardsMappings(String oldVersion, String newVersion, @Nullable Class<? extends Protocol> vvProtocolClass) {
this(oldVersion, newVersion, vvProtocolClass, false);
}
public BackwardsMappings(String oldVersion, String newVersion, @Nullable Class<? extends Protocol> vvProtocolClass, boolean hasDiffFile) {
super(oldVersion, newVersion, hasDiffFile);
Preconditions.checkArgument(!vvProtocolClass.isAssignableFrom(BackwardsProtocol.class));
this.vvProtocolClass = vvProtocolClass;
// Just re-use ViaVersion's item id map
loadItems = false;
}
@Override
public void load() {
// Load them later
}
public void loadVBMappings() {
super.load();
}
@Override
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings) {
if (diffMappings != null) {
JsonObject diffItems = diffMappings.getAsJsonObject("items");
if (diffItems != null) {
backwardsItemMappings = VBMappingDataLoader.loadItemMappings(oldMappings.getAsJsonObject("items"), newMappings.getAsJsonObject("items"), diffItems);
}
JsonObject diffSounds = diffMappings.getAsJsonObject("sounds");
if (diffSounds != null) {
backwardsSoundMappings = VBMappingDataLoader.objectToMap(diffSounds);
}
}
// Just re-use ViaVersion's item id map
if (vvProtocolClass != null) {
itemMappings = ProtocolRegistry.getProtocol(vvProtocolClass).getMappingData().getItemMappings().inverse();
}
loadVBExtras(oldMappings, newMappings);
}
@Override
@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 VBMappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff, shouldWarnOnMissing(key));
}
@Override
@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 VBMappings(oldMappings.getAsJsonObject(key), newMappings.getAsJsonObject(key), diff, shouldWarnOnMissing(key));
}
@Override
protected JsonObject loadDiffFile() {
return VBMappingDataLoader.loadFromDataDir("mapping-" + newVersion + "to" + oldVersion + ".json");
}
protected boolean shouldWarnOnMissing(String key) {
return !key.equals("blocks") && !key.equals("statistics");
}
protected void loadVBExtras(JsonObject oldMappings, JsonObject newMappings) {
}
@Nullable
public MappedItem getMappedItem(int id) {
return backwardsItemMappings != null ? backwardsItemMappings.get(id) : null;
}
@Nullable
public String getMappedNamedSound(String id) {
return backwardsSoundMappings != null ? backwardsSoundMappings.get(id) : null;
}
@Override
protected int checkValidity(int id, String type) {
return id;
}
@Nullable
public Int2ObjectMap<MappedItem> getBackwardsItemMappings() {
return backwardsItemMappings;
}
@Nullable
public Map<String, String> getBackwardsSoundMappings() {
return backwardsSoundMappings;
}
}

Datei anzeigen

@ -1,56 +0,0 @@
package nl.matsv.viabackwards.api.data;
import nl.matsv.viabackwards.ViaBackwards;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import java.util.HashMap;
import java.util.Map;
/**
* Backwards mappings for newly (!) added items.
*/
public class VBItemMappings {
private final Int2ObjectMap<MappedItem> itemMapping;
public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
Map<Integer, MappedItem> itemMapping = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
JsonObject object = entry.getValue().getAsJsonObject();
String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newMapping, mappedIdName);
if (value == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( ");
}
continue;
}
Map.Entry<String, JsonElement> oldEntry = MappingDataLoader.findValue(oldMapping, entry.getKey());
if (oldEntry == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( ");
}
continue;
}
int id = Integer.parseInt(oldEntry.getKey());
int mappedId = Integer.parseInt(value.getKey());
String name = object.getAsJsonPrimitive("name").getAsString();
itemMapping.put(id, new MappedItem(mappedId, name));
}
this.itemMapping = new Int2ObjectOpenHashMap<>(itemMapping, 1F);
}
@Nullable
public MappedItem getMappedItem(int id) {
return itemMapping.get(id);
}
}

Datei anzeigen

@ -4,6 +4,8 @@ import nl.matsv.viabackwards.ViaBackwards;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import us.myles.viaversion.libs.gson.JsonArray; import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonIOException; import us.myles.viaversion.libs.gson.JsonIOException;
@ -16,6 +18,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class VBMappingDataLoader { public class VBMappingDataLoader {
@ -43,6 +46,7 @@ public class VBMappingDataLoader {
try (InputStreamReader reader = new InputStreamReader(stream)) { try (InputStreamReader reader = new InputStreamReader(stream)) {
return GsonUtil.getGson().fromJson(reader, JsonObject.class); return GsonUtil.getGson().fromJson(reader, JsonObject.class);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
return null; return null;
} }
} }
@ -122,4 +126,50 @@ public class VBMappingDataLoader {
output[i] = index.shortValue(); output[i] = index.shortValue();
} }
} }
public static Map<String, String> objectToMap(JsonObject object) {
Map<String, String> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
String key = entry.getKey();
if (key.indexOf(':') == -1) {
key = "minecraft:" + key;
}
String value = entry.getValue().getAsString();
if (value.indexOf(':') == -1) {
value = "minecraft:" + value;
}
mappings.put(key, value);
}
return mappings;
}
public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
Map<Integer, MappedItem> itemMapping = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
JsonObject object = entry.getValue().getAsJsonObject();
String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newMapping, mappedIdName);
if (value == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( ");
}
continue;
}
Map.Entry<String, JsonElement> oldEntry = MappingDataLoader.findValue(oldMapping, entry.getKey());
if (oldEntry == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( ");
}
continue;
}
int id = Integer.parseInt(oldEntry.getKey());
int mappedId = Integer.parseInt(value.getKey());
String name = object.getAsJsonPrimitive("name").getAsString();
itemMapping.put(id, new MappedItem(mappedId, name));
}
return new Int2ObjectOpenHashMap<>(itemMapping, 1F);
}
} }

Datei anzeigen

@ -32,6 +32,10 @@ public class VBMappings extends Mappings {
super(create(oldMapping, newMapping, diffMapping, true)); super(create(oldMapping, newMapping, diffMapping, true));
} }
public VBMappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
super(create(oldMapping, newMapping, diffMapping, warnOnMissing));
}
private static short[] create(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) { private static short[] create(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
short[] oldToNew = new short[size]; short[] oldToNew = new short[size];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, (short) -1);

Datei anzeigen

@ -1,43 +0,0 @@
package nl.matsv.viabackwards.api.data;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import java.util.HashMap;
import java.util.Map;
/**
* Backwards mappings for sound ids and names.
*/
public class VBSoundMappings {
private final Map<String, String> namedSoundMappings = new HashMap<>();
private final Mappings idMappings;
public VBSoundMappings(JsonArray oldSounds, JsonArray newSounds, JsonObject diffMapping) {
idMappings = new VBMappings(oldSounds, newSounds, diffMapping);
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
String key = entry.getKey();
if (key.indexOf(':') == -1) {
key = "minecraft:" + key;
}
String value = entry.getValue().getAsString();
if (value.indexOf(':') == -1) {
value = "minecraft:" + value;
}
namedSoundMappings.put(key, value);
}
}
@Nullable
public String getNewId(String oldId) {
return namedSoundMappings.get(oldId);
}
public int getNewId(int oldId) {
return idMappings.getNewId(oldId);
}
}

Datei anzeigen

@ -10,7 +10,6 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.util.List; import java.util.List;
@ -25,7 +24,7 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
super(protocol, displayType, 2); super(protocol, displayType, 2);
} }
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction blockStateRewriter) { public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
protocol.registerOutgoing(packetType, new PacketRemapper() { protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
@ -42,7 +41,7 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
EntityType entityType = setOldEntityId(wrapper); EntityType entityType = setOldEntityId(wrapper);
if (entityType == fallingBlockType) { if (entityType == fallingBlockType) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, blockStateRewriter.rewrite(blockState)); wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(blockState));
} }
}); });
} }

Datei anzeigen

@ -4,29 +4,20 @@ import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.MappedItem; import nl.matsv.viabackwards.api.data.MappedItem;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> { public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> {
private final MappedItemFunction mappedItemFunction;
private final TranslatableRewriter translatableRewriter; private final TranslatableRewriter translatableRewriter;
protected ItemRewriter(T protocol, @Nullable TranslatableRewriter translatableRewriter, protected ItemRewriter(T protocol, @Nullable TranslatableRewriter translatableRewriter) {
@Nullable IdRewriteFunction oldRewriter, @Nullable IdRewriteFunction newRewriter, MappedItemFunction mappedItemFunction) {
super(protocol, oldRewriter, newRewriter, true);
this.translatableRewriter = translatableRewriter;
this.mappedItemFunction = mappedItemFunction;
}
protected ItemRewriter(T protocol, @Nullable TranslatableRewriter translatableRewriter, MappedItemFunction mappedItemFunction) {
super(protocol, true); super(protocol, true);
this.translatableRewriter = translatableRewriter; this.translatableRewriter = translatableRewriter;
this.mappedItemFunction = mappedItemFunction;
} }
@Override @Override
@ -71,19 +62,21 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
} }
} }
MappedItem data = mappedItemFunction.get(item.getIdentifier()); MappedItem data = protocol.getMappingData().getMappedItem(item.getIdentifier());
if (data == null) { if (data == null) {
// Just rewrite the id // Just rewrite the id
return super.handleItemToClient(item); return super.handleItemToClient(item);
} }
// Set remapped id
item.setIdentifier(data.getId());
// Set custom name - only done if there is no original one
if (item.getTag() == null) { if (item.getTag() == null) {
item.setTag(new CompoundTag("")); item.setTag(new CompoundTag(""));
} }
// Save original id, set remapped id
item.getTag().put(new IntTag(nbtTagName + "|id", item.getIdentifier()));
item.setIdentifier(data.getId());
// Set custom name - only done if there is no original one
if (display == null) { if (display == null) {
item.getTag().put(display = new CompoundTag("display")); item.getTag().put(display = new CompoundTag("display"));
} }
@ -94,10 +87,18 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
return item; return item;
} }
@FunctionalInterface @Override
public interface MappedItemFunction {
@Nullable @Nullable
MappedItem get(int id); public Item handleItemToServer(Item item) {
if (item == null) return null;
super.handleItemToServer(item);
if (item.getTag() != null) {
IntTag originalId = item.getTag().remove(nbtTagName + "|id");
if (originalId != null) {
item.setIdentifier(originalId.getValue());
}
}
return item;
} }
} }

Datei anzeigen

@ -3,7 +3,6 @@ package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter; import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
@ -13,28 +12,20 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> { public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
protected static final CompoundTagConverter CONVERTER = new CompoundTagConverter(); protected static final CompoundTagConverter CONVERTER = new CompoundTagConverter();
protected final IdRewriteFunction toClientRewriter;
protected final IdRewriteFunction toServerRewriter;
protected final String nbtTagName; protected final String nbtTagName;
protected final boolean jsonNameFormat; protected final boolean jsonNameFormat;
protected ItemRewriterBase(T protocol, @Nullable IdRewriteFunction toClientRewriter, @Nullable IdRewriteFunction toServerRewriter, boolean jsonNameFormat) { protected ItemRewriterBase(T protocol, boolean jsonNameFormat) {
super(protocol); super(protocol);
this.toClientRewriter = toClientRewriter;
this.toServerRewriter = toServerRewriter;
this.jsonNameFormat = jsonNameFormat; this.jsonNameFormat = jsonNameFormat;
nbtTagName = "VB|" + protocol.getClass().getSimpleName(); nbtTagName = "VB|" + protocol.getClass().getSimpleName();
} }
protected ItemRewriterBase(T protocol, boolean jsonNameFormat) {
this(protocol, null, null, jsonNameFormat);
}
@Nullable @Nullable
public Item handleItemToClient(Item item) { public Item handleItemToClient(Item item) {
if (item == null) return null; if (item == null) return null;
if (toClientRewriter != null) { if (protocol.getMappingData() != null) {
item.setIdentifier(toClientRewriter.rewrite(item.getIdentifier())); item.setIdentifier(protocol.getMappingData().getNewItemId(item.getIdentifier()));
} }
return item; return item;
} }
@ -42,8 +33,8 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
@Nullable @Nullable
public Item handleItemToServer(Item item) { public Item handleItemToServer(Item item) {
if (item == null) return null; if (item == null) return null;
if (toServerRewriter != null) { if (protocol.getMappingData() != null) {
item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier())); item.setIdentifier(protocol.getMappingData().getOldItemId(item.getIdentifier()));
} }
restoreDisplayTag(item); restoreDisplayTag(item);
return item; return item;

Datei anzeigen

@ -20,7 +20,6 @@ import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
@ -79,13 +78,9 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
} }
} }
protected LegacyBlockItemRewriter(T protocol, @Nullable IdRewriteFunction oldRewriter, @Nullable IdRewriteFunction newRewriter) {
super(protocol, oldRewriter, newRewriter, false);
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
}
protected LegacyBlockItemRewriter(T protocol) { protected LegacyBlockItemRewriter(T protocol) {
this(protocol, null, null); super(protocol, false);
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
} }
@Override @Override

Datei anzeigen

@ -3,22 +3,15 @@ package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.util.function.Function;
public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewriter { public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewriter {
private final Function<String, String> stringIdRewriter; private final BackwardsProtocol protocol;
public SoundRewriter(BackwardsProtocol protocol, IdRewriteFunction idRewriter, Function<String, String> stringIdRewriter) { public SoundRewriter(BackwardsProtocol protocol) {
super(protocol, idRewriter); super(protocol);
this.stringIdRewriter = stringIdRewriter; this.protocol = protocol;
}
public SoundRewriter(BackwardsProtocol protocol, IdRewriteFunction idRewriter) {
this(protocol, idRewriter, null);
} }
public void registerNamedSound(ClientboundPacketType packetType) { public void registerNamedSound(ClientboundPacketType packetType) {
@ -28,7 +21,7 @@ public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewrit
map(Type.STRING); // Sound identifier map(Type.STRING); // Sound identifier
handler(wrapper -> { handler(wrapper -> {
String soundId = wrapper.get(Type.STRING, 0); String soundId = wrapper.get(Type.STRING, 0);
String mappedId = stringIdRewriter.apply(soundId); String mappedId = protocol.getMappingData().getMappedNamedSound(soundId);
if (mappedId == null) return; if (mappedId == null) return;
if (!mappedId.isEmpty()) { if (!mappedId.isEmpty()) {
wrapper.set(Type.STRING, 0, mappedId); wrapper.set(Type.STRING, 0, mappedId);
@ -53,7 +46,7 @@ public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewrit
} }
String soundId = wrapper.read(Type.STRING); String soundId = wrapper.read(Type.STRING);
String mappedId = stringIdRewriter.apply(soundId); String mappedId = protocol.getMappingData().getMappedNamedSound(soundId);
if (mappedId == null) { if (mappedId == null) {
// No mapping found // No mapping found
wrapper.write(Type.STRING, soundId); wrapper.write(Type.STRING, soundId);

Datei anzeigen

@ -36,6 +36,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> { public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
private BlockItemPackets1_13 blockItemPackets; private BlockItemPackets1_13 blockItemPackets;
public Protocol1_12_2To1_13() { public Protocol1_12_2To1_13() {
@ -45,7 +46,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_13To1_12_2.class, () -> { executeAsyncAfterLoaded(Protocol1_13To1_12_2.class, () -> {
BackwardsMappings.init(); MAPPINGS.loadVBMappings();
PaintingMapping.init(); PaintingMapping.init();
Via.getManager().getProviders().register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider()); Via.getManager().getProviders().register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider());
}); });
@ -54,7 +55,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
protected void handleTranslate(JsonObject root, String translate) { protected void handleTranslate(JsonObject root, String translate) {
String newTranslate = newTranslatables.get(translate); String newTranslate = newTranslatables.get(translate);
if (newTranslate != null || (newTranslate = BackwardsMappings.translateMappings.get(translate)) != null) { if (newTranslate != null || (newTranslate = getMappingData().getTranslateMappings().get(translate)) != null) {
root.addProperty("translate", newTranslate); root.addProperty("translate", newTranslate);
} }
} }
@ -117,4 +118,9 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
public BlockItemPackets1_13 getBlockItemPackets() { public BlockItemPackets1_13 getBlockItemPackets() {
return blockItemPackets; return blockItemPackets;
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
} }

Datei anzeigen

@ -1,6 +1,6 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
@ -52,7 +52,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
// There doesn't seem to be a nicer way around it :( // There doesn't seem to be a nicer way around it :(
private void addEntries(String data, int id) { private void addEntries(String data, int id) {
id = BackwardsMappings.blockMappings.getNewId(id); id = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(id);
pistonIds.put(data, id); pistonIds.put(data, id);
String substring = data.substring(10); String substring = data.substring(10);

Datei anzeigen

@ -11,14 +11,12 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings; import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
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.data.StatisticMappings; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticMappings;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
@ -30,29 +28,22 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class BackwardsMappings { public class BackwardsMappings extends nl.matsv.viabackwards.api.data.BackwardsMappings {
public static final Int2ObjectMap<String> statisticMappings = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<String> statisticMappings = new Int2ObjectOpenHashMap<>();
public static final Map<String, String> translateMappings = new HashMap<>(); private final Map<String, String> translateMappings = new HashMap<>();
public static BlockMappingsShortArray blockMappings; private Mappings enchantmentMappings;
public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings;
public static Mappings enchantmentMappings;
public static void init() { public BackwardsMappings() {
ViaBackwards.getPlatform().getLogger().info("Loading 1.13 -> 1.12.2 mappings..."); super("1.13", "1.12", Protocol1_13To1_12_2.class, true);
JsonObject mapping1_12 = MappingDataLoader.getMappingsCache().get("mapping-1.12.json"); }
JsonObject mapping1_13 = MappingDataLoader.getMappingsCache().get("mapping-1.13.json");
JsonObject mapping1_12_2to1_13 = VBMappingDataLoader.loadFromDataDir("mapping-1.12.2to1.13.json");
blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates"));
itemMappings = new VBItemMappings(mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items"), mapping1_12_2to1_13.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"), mapping1_12_2to1_13.getAsJsonObject("sounds"));
enchantmentMappings = new VBMappings(mapping1_13.getAsJsonObject("enchantments"), mapping1_12.getAsJsonObject("enchantments"), false);
@Override
public void loadVBExtras(JsonObject oldMappings, JsonObject newMappings) {
enchantmentMappings = new VBMappings(oldMappings.getAsJsonObject("enchantments"), newMappings.getAsJsonObject("enchantments"), false);
for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) { for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) {
statisticMappings.put(entry.getValue().intValue(), entry.getKey()); statisticMappings.put(entry.getValue().intValue(), entry.getKey());
} }
for (Map.Entry<String, String> entry : MappingData.translateMapping.entrySet()) { for (Map.Entry<String, String> entry : Protocol1_13To1_12_2.MAPPINGS.getTranslateMapping().entrySet()) {
translateMappings.put(entry.getValue(), entry.getKey()); translateMappings.put(entry.getValue(), entry.getKey());
} }
} }
@ -93,16 +84,28 @@ public class BackwardsMappings {
} }
} }
public static class BlockMappingsShortArray { @Override
private final short[] oldToNew = new short[8582]; @Nullable
protected Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
private BlockMappingsShortArray(JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) { if (key.equals("blockstates")) {
short[] oldToNew = new short[8582];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, (short) -1);
mapIdentifiers(oldToNew, newIdentifiers, oldIdentifiers, mapping); mapIdentifiers(oldToNew, oldMappings.getAsJsonObject("blockstates"), newMappings.getAsJsonObject("blocks"), diffMappings.getAsJsonObject("blockstates"));
return new Mappings(oldToNew);
} else {
return super.loadFromObject(oldMappings, newMappings, diffMappings, key);
}
} }
public int getNewId(int old) { public Int2ObjectMap<String> getStatisticMappings() {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; return statisticMappings;
} }
public Map<String, String> getTranslateMappings() {
return translateMappings;
}
public Mappings getEnchantmentMappings() {
return enchantmentMappings;
} }
} }

Datei anzeigen

@ -11,7 +11,6 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -35,7 +34,7 @@ public class ParticleMapping {
} }
private int[] rewrite(int newType) { private int[] rewrite(int newType) {
int blockType = BlockItemPackets1_13.toOldId(newType); int blockType = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(newType);
int type = blockType >> 4; int type = blockType >> 4;
int meta = blockType & 15; int meta = blockType & 15;

Datei anzeigen

@ -15,7 +15,6 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
@ -33,8 +32,8 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData; 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.SpawnEggRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
@ -61,23 +60,10 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
private final String extraNbtTag; private final String extraNbtTag;
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) { public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
super(protocol, null, id -> BackwardsMappings.itemMappings.getMappedItem(id)); super(protocol, null);
extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2"; extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2";
} }
public static int toOldId(int oldId) {
if (oldId < 0) {
oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air.
}
int newId = BackwardsMappings.blockMappings.getNewId(oldId);
if (newId != -1)
return newId;
ViaBackwards.getPlatform().getLogger().warning("Missing block completely " + oldId);
// Default stone
return 1 << 4;
}
public static boolean isDamageable(int id) { public static boolean isDamageable(int id) {
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|| id == 261 // bow || id == 261 // bow
@ -101,7 +87,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int itemId = wrapper.read(Type.VAR_INT); int itemId = wrapper.read(Type.VAR_INT);
int oldId = MappingData.oldToNewItems.inverse().get(itemId); int oldId = protocol.getMappingData().getItemMappings().get(itemId);
if (oldId != -1) { if (oldId != -1) {
Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId); Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);
if (eggEntityId.isPresent()) { if (eggEntityId.isPresent()) {
@ -220,7 +206,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
storage.checkAndStore(position, blockState); storage.checkAndStore(position, blockState);
wrapper.write(Type.VAR_INT, toOldId(blockState)); wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockState));
// Flower pot special treatment // Flower pot special treatment
flowerPotSpecialTreatment(wrapper.user(), blockState, position); flowerPotSpecialTreatment(wrapper.user(), blockState, position);
@ -257,7 +243,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
flowerPotSpecialTreatment(wrapper.user(), block, position); flowerPotSpecialTreatment(wrapper.user(), block, position);
// Change to old id // Change to old id
record.setBlockId(toOldId(block)); record.setBlockId(protocol.getMappingData().getNewBlockStateId(block));
} }
} }
}); });
@ -357,7 +343,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
for (int p = 0; p < section.getPaletteSize(); p++) { for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p); int old = section.getPaletteEntry(p);
if (old != 0) { if (old != 0) {
int oldId = toOldId(old); int oldId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(p, oldId); section.setPaletteEntry(p, oldId);
} }
} }
@ -413,9 +399,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, MappingData.oldToNewItems.inverse().get(data) >> 4); wrapper.set(Type.INT, 1, protocol.getMappingData().getItemMappings().get(data) >> 4);
} else if (id == 2001) { // Block break + block break sound } else if (id == 2001) { // Block break + block break sound
data = toOldId(data); data = protocol.getMappingData().getNewBlockStateId(data);
int blockId = data >> 4; int blockId = data >> 4;
int blockData = data & 0xF; int blockData = data & 0xF;
wrapper.set(Type.INT, 1, (blockId & 0xFFF) | (blockData << 12)); wrapper.set(Type.INT, 1, (blockId & 0xFFF) | (blockData << 12));
@ -478,7 +464,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// Enchantment table // Enchantment table
if (property >= 4 && property <= 6) { if (property >= 4 && property <= 6) {
short oldId = wrapper.get(Type.SHORT, 1); short oldId = wrapper.get(Type.SHORT, 1);
wrapper.set(Type.SHORT, 1, (short) BackwardsMappings.enchantmentMappings.getNewId(oldId)); wrapper.set(Type.SHORT, 1, (short) protocol.getMappingData().getEnchantmentMappings().getNewId(oldId));
} }
}); });
} }
@ -543,7 +529,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// No custom mapping found, look at VV mappings // No custom mapping found, look at VV mappings
if (item.getIdentifier() == originalId) { if (item.getIdentifier() == originalId) {
int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); int oldId = protocol.getMappingData().getItemMappings().get(item.getIdentifier());
if (oldId != -1) { if (oldId != -1) {
rawId = itemIdToRaw(oldId, item, tag); rawId = itemIdToRaw(oldId, item, tag);
} else if (item.getIdentifier() == 362) { // base/colorless shulker box } else if (item.getIdentifier() == 362) { // base/colorless shulker box
@ -668,7 +654,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
lore.add(new StringTag("", mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); lore.add(new StringTag("", mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level)));
noMapped.add(enchantmentEntry); noMapped.add(enchantmentEntry);
} else if (!newId.isEmpty()) { } else if (!newId.isEmpty()) {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null) { if (oldId == null) {
if (!newId.startsWith("viaversion:legacy/")) { if (!newId.startsWith("viaversion:legacy/")) {
// Custom enchant (?) // Custom enchant (?)
@ -837,7 +823,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
item.setIdentifier(identifier); item.setIdentifier(identifier);
int newId = -1; int newId = -1;
if (!MappingData.oldToNewItems.containsKey(rawId)) { if (!protocol.getMappingData().getItemMappings().inverse().containsKey(rawId)) {
if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map
if (tag == null) item.setTag(tag = new CompoundTag("tag")); if (tag == null) item.setTag(tag = new CompoundTag("tag"));
tag.put(new IntTag(extraNbtTag, originalId)); // Data will be lost, saving original id tag.put(new IntTag(extraNbtTag, originalId)); // Data will be lost, saving original id
@ -847,7 +833,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
newId = 362; // directly set the new id -> base/colorless shulker box newId = 362; // directly set the new id -> base/colorless shulker box
} else if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed } else if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed
rawId = 32 << 4; // Dead Bush rawId = 32 << 4; // Dead Bush
} else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { } else if (protocol.getMappingData().getItemMappings().inverse().containsKey(rawId & ~0xF)) {
rawId &= ~0xF; // Remove data rawId &= ~0xF; // Remove data
} else { } else {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
@ -858,7 +844,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
} }
if (newId == -1) { if (newId == -1) {
newId = MappingData.oldToNewItems.get(rawId); newId = protocol.getMappingData().getItemMappings().inverse().get(rawId);
} }
item.setIdentifier(newId); item.setIdentifier(newId);
@ -920,7 +906,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (dummyEnchant && oldId == 0 && level == 0) { if (dummyEnchant && oldId == 0 && level == 0) {
continue; //Skip dummy enchatment continue; //Skip dummy enchatment
} }
String newId = MappingData.oldEnchantmentsIds.get(oldId); String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) { if (newId == null) {
newId = "viaversion:legacy/" + oldId; newId = "viaversion:legacy/" + oldId;
} }
@ -1004,7 +990,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// Create the flowerpot // Create the flowerpot
PacketWrapper blockCreate = new PacketWrapper(0x0B, null, user); PacketWrapper blockCreate = new PacketWrapper(0x0B, null, user);
blockCreate.write(Type.POSITION, position); blockCreate.write(Type.POSITION, position);
blockCreate.write(Type.VAR_INT, toOldId(blockState)); blockCreate.write(Type.VAR_INT, Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState));
blockCreate.send(Protocol1_12_2To1_13.class, true); blockCreate.send(Protocol1_12_2To1_13.class, true);
// Send a block entity update // Send a block entity update

Datei anzeigen

@ -89,7 +89,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
Entity1_13Types.ObjectType type = optionalType.get(); Entity1_13Types.ObjectType type = optionalType.get();
if (type == Entity1_13Types.ObjectType.FALLING_BLOCK) { if (type == Entity1_13Types.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Type.INT, 0);
int combined = BlockItemPackets1_13.toOldId(blockState); int combined = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState);
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12); combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
wrapper.set(Type.INT, 0, combined); wrapper.set(Type.INT, 0, combined);
} else if (type == Entity1_13Types.ObjectType.ITEM_FRAME) { } else if (type == Entity1_13Types.ObjectType.ITEM_FRAME) {

Datei anzeigen

@ -4,7 +4,6 @@ import com.google.common.base.Joiner;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
import nl.matsv.viabackwards.utils.ChatUtil; import nl.matsv.viabackwards.utils.ChatUtil;
@ -542,7 +541,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
newSize--; newSize--;
continue; continue;
case 8: case 8:
name = BackwardsMappings.statisticMappings.get(statisticId); name = protocol.getMappingData().getStatisticMappings().get(statisticId);
if (name == null) { if (name == null) {
wrapper.read(Type.VAR_INT); wrapper.read(Type.VAR_INT);
newSize--; newSize--;

Datei anzeigen

@ -3,7 +3,6 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -27,7 +26,7 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
handler(wrapper -> { handler(wrapper -> {
String newSound = wrapper.get(Type.STRING, 0); String newSound = wrapper.get(Type.STRING, 0);
String oldSound = NamedSoundMapping.getOldId(newSound); String oldSound = NamedSoundMapping.getOldId(newSound);
if (oldSound != null || (oldSound = BackwardsMappings.soundMappings.getNewId(newSound)) != null) { if (oldSound != null || (oldSound = protocol.getMappingData().getMappedNamedSound(newSound)) != null) {
wrapper.set(Type.STRING, 0, oldSound); wrapper.set(Type.STRING, 0, oldSound);
} else if (!Via.getConfig().isSuppressConversionWarnings()) { } else if (!Via.getConfig().isSuppressConversionWarnings()) {
ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound); ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound);
@ -52,7 +51,7 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
String sound; String sound;
if ((flags & 0x02) != 0) { if ((flags & 0x02) != 0) {
sound = BackwardsMappings.soundMappings.getNewId(wrapper.read(Type.STRING)); sound = protocol.getMappingData().getMappedNamedSound(wrapper.read(Type.STRING));
if (sound == null) { if (sound == null) {
sound = ""; sound = "";
} }
@ -72,7 +71,7 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
map(Type.VAR_INT); map(Type.VAR_INT);
handler(wrapper -> { handler(wrapper -> {
int newSound = wrapper.get(Type.VAR_INT, 0); int newSound = wrapper.get(Type.VAR_INT, 0);
int oldSound = BackwardsMappings.soundMappings.getNewId(newSound); int oldSound = protocol.getMappingData().getSoundMappings().getNewId(newSound);
if (oldSound == -1) { if (oldSound == -1) {
wrapper.cancel(); wrapper.cancel();
} else { } else {

Datei anzeigen

@ -74,7 +74,7 @@ public class Protocol1_13_1To1_13_2 extends BackwardsProtocol<ClientboundPackets
} }
}); });
new StatisticsRewriter(this, null, null, null, id -> { new StatisticsRewriter(this, id -> {
int newId = id; int newId = id;
if (newId > 40) { if (newId > 40) {
if (id == 41) return -1; if (id == 41) return -1;

Datei anzeigen

@ -1,10 +1,9 @@
package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14; package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.BackwardsMappings;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.BlockItemPackets1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.BlockItemPackets1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.EntityPackets1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.EntityPackets1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.PlayerPackets1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets.PlayerPackets1_14;
@ -21,11 +20,11 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_14, ClientboundPackets1_13, ServerboundPackets1_14, ServerboundPackets1_13> { public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_14, ClientboundPackets1_13, ServerboundPackets1_14, ServerboundPackets1_13> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.14", "1.13.2", Protocol1_14To1_13_2.class, true);
private BlockItemPackets1_14 blockItemPackets; private BlockItemPackets1_14 blockItemPackets;
private EntityPackets1_14 entityPackets; private EntityPackets1_14 entityPackets;
@ -35,7 +34,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, BackwardsMappings::init); executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::loadVBMappings);
TranslatableRewriter translatableRewriter = new TranslatableRewriter(this); TranslatableRewriter translatableRewriter = new TranslatableRewriter(this);
translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR); translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR);
@ -53,8 +52,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
new PlayerPackets1_14(this).register(); new PlayerPackets1_14(this).register();
new SoundPackets1_14(this).register(); new SoundPackets1_14(this).register();
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id), new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_14.STATISTICS);
entityPackets::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_14.STATISTICS);
cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_POSITION); cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE); cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
@ -73,7 +71,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
for (int j = 0; j < blockIds.length; j++) { for (int j = 0; j < blockIds.length; j++) {
int id = blockIds[j]; int id = blockIds[j];
// Ignore new blocktags // Ignore new blocktags
int blockId = BackwardsMappings.blockMappings.getNewId(id); int blockId = getMappingData().getNewBlockId(id);
blockIds[j] = blockId; blockIds[j] = blockId;
} }
} }
@ -85,7 +83,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
for (int j = 0; j < itemIds.length; j++) { for (int j = 0; j < itemIds.length; j++) {
int itemId = itemIds[j]; int itemId = itemIds[j];
// Ignore new itemtags // Ignore new itemtags
int oldId = MappingData.oldToNewItems.inverse().get(itemId); int oldId = getMappingData().getItemMappings().get(itemId);
itemIds[j] = oldId; itemIds[j] = oldId;
} }
} }
@ -163,27 +161,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
}); });
} }
public static int getNewBlockStateId(int id) {
int newId = BackwardsMappings.blockStateMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.13.2 blockstate id for 1.14 block " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
if (id == 669) return -1; // Bell
int newId = BackwardsMappings.blockMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.13.2 block id for 1.14 block " + id);
return -1;
}
return newId;
}
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
// Register ClientWorld // Register ClientWorld
@ -211,4 +188,9 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
public EntityPackets1_14 getEntityPackets() { public EntityPackets1_14 getEntityPackets() {
return entityPackets; return entityPackets;
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
} }

Datei anzeigen

@ -1,31 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings {
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings;
public static void init() {
ViaBackwards.getPlatform().getLogger().info("Loading 1.14 -> 1.13.2 mappings...");
JsonObject mapping1_13_2 = MappingDataLoader.getMappingsCache().get("mapping-1.13.2.json");
JsonObject mapping1_14 = MappingDataLoader.getMappingsCache().get("mapping-1.14.json");
JsonObject mapping1_13_2to1_14 = VBMappingDataLoader.loadFromDataDir("mapping-1.13.2to1.14.json");
blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_14.getAsJsonArray("statistics"), mapping1_13_2.getAsJsonArray("statistics"), false);
}
}

Datei anzeigen

@ -6,7 +6,6 @@ import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -31,7 +30,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
@ -51,7 +50,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
private EnchantmentRewriter enchantmentRewriter; private EnchantmentRewriter enchantmentRewriter;
public BlockItemPackets1_14(Protocol1_13_2To1_14 protocol, TranslatableRewriter translatableRewriter) { public BlockItemPackets1_14(Protocol1_13_2To1_14 protocol, TranslatableRewriter translatableRewriter) {
super(protocol, translatableRewriter, BlockItemPackets1_14::getOldItemId, BlockItemPackets1_14::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id)); super(protocol, translatableRewriter);
} }
@Override @Override
@ -176,9 +175,9 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
}); });
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13_2To1_14::getNewBlockStateId, Protocol1_13_2To1_14::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN, BlockItemPackets1_14::getOldItemId); itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
@ -358,7 +357,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
map(Type.UNSIGNED_BYTE); // Action param map(Type.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
handler(wrapper -> { handler(wrapper -> {
int mappedId = Protocol1_13_2To1_14.getNewBlockId(wrapper.get(Type.VAR_INT, 0)); int mappedId = protocol.getMappingData().getNewBlockId(wrapper.get(Type.VAR_INT, 0));
if (mappedId == -1) { if (mappedId == -1) {
wrapper.cancel(); wrapper.cancel();
return; return;
@ -378,7 +377,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0); int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, Protocol1_13_2To1_14.getNewBlockStateId(id)); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(id));
} }
}); });
} }
@ -443,7 +442,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
int id = section.getFlatBlock(x, y, z); int id = section.getFlatBlock(x, y, z);
if (MappingData.nonFullBlocks.contains(id)) { if (Protocol1_14To1_13_2.MAPPINGS.getNonFullBlocks().contains(id)) {
section.getBlockLightNibbleArray().set(x, y, z, 0); section.getBlockLightNibbleArray().set(x, y, z, 0);
} }
} }
@ -453,7 +452,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
for (int j = 0; j < section.getPaletteSize(); j++) { for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j); int old = section.getPaletteEntry(j);
int newId = Protocol1_13_2To1_14.getNewBlockStateId(old); int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId); section.setPaletteEntry(j, newId);
} }
} }
@ -488,9 +487,9 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, data = BlockItemPackets1_14.getOldItemId(data)); wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
} else if (id == 2001) { // Block break + block break sound } else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, data = Protocol1_13_2To1_14.getNewBlockStateId(data)); wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
} }
} }
}); });
@ -584,23 +583,4 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
} }
return item; return item;
} }
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.14 item for 1.13.2 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
if (oldId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.13.2 item for 1.14 item " + id);
return 1;
}
return oldId;
}
} }

Datei anzeigen

@ -172,7 +172,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 0);
if (objectType == Entity1_13Types.ObjectType.FALLING_BLOCK) { if (objectType == Entity1_13Types.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Type.INT, 0);
int combined = Protocol1_13_2To1_14.getNewBlockStateId(blockState); int combined = protocol.getMappingData().getNewBlockStateId(blockState);
wrapper.set(Type.INT, 0, combined); wrapper.set(Type.INT, 0, combined);
} else if (entityType.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW)) { } else if (entityType.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW)) {
wrapper.set(Type.INT, 0, data + 1); wrapper.set(Type.INT, 0, data + 1);
@ -351,7 +351,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item)); meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item));
} else if (type == MetaType1_13_2.BlockID) { } else if (type == MetaType1_13_2.BlockID) {
int blockstate = (Integer) meta.getValue(); int blockstate = (Integer) meta.getValue();
meta.setValue(Protocol1_13_2To1_14.getNewBlockStateId(blockstate)); meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
} }
return meta; return meta;

Datei anzeigen

@ -5,7 +5,6 @@ import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -20,8 +19,7 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
SoundRewriter soundRewriter = new SoundRewriter(protocol, SoundRewriter soundRewriter = new SoundRewriter(protocol);
id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId));
soundRewriter.registerSound(ClientboundPackets1_14.SOUND); soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_14.NAMED_SOUND); soundRewriter.registerNamedSound(ClientboundPackets1_14.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_14.STOP_SOUND); soundRewriter.registerStopSound(ClientboundPackets1_14.STOP_SOUND);
@ -34,7 +32,7 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
wrapper.cancel(); wrapper.cancel();
int soundId = wrapper.read(Type.VAR_INT); int soundId = wrapper.read(Type.VAR_INT);
int newId = BackwardsMappings.soundMappings.getNewId(soundId); int newId = protocol.getMappingData().getSoundMappings().getNewId(soundId);
if (newId == -1) return; if (newId == -1) return;
int category = wrapper.read(Type.VAR_INT); int category = wrapper.read(Type.VAR_INT);

Datei anzeigen

@ -1,6 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.BackwardsMappings;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1;
@ -14,18 +15,23 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.TagRewriter; import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.type.Type; 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.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> { public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.13.2", "1.13", Protocol1_13_1To1_13.class, true);
public Protocol1_13To1_13_1() { public Protocol1_13To1_13_1() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_13_1To1_13.class, MAPPINGS::loadVBMappings);
new EntityPackets1_13_1(this).register(); new EntityPackets1_13_1(this).register();
InventoryPackets1_13_1.register(this); InventoryPackets1_13_1.register(this);
WorldPackets1_13_1.register(this); WorldPackets1_13_1.register(this);
@ -161,42 +167,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
new TagRewriter(this, Protocol1_13To1_13_1::getNewBlockId, new TagRewriter(this, null).register(ClientboundPackets1_13.TAGS);
InventoryPackets1_13_1::getOldItemId, null).register(ClientboundPackets1_13.TAGS);
}
public static int getNewBlockStateId(int blockId) {
if (blockId > 8590) {
blockId -= 17;
} else if (blockId > 8588) {
blockId = 8573;
} else if (blockId > 8479) {
blockId -= 16;
} else if (blockId > 8469 && blockId % 2 == 0) {
if (blockId % 2 == 0) {
blockId = 8459 + (blockId - 8470) / 2;
} else {
blockId = 0; //TODO replace new blocks
}
} else if (blockId > 8463) {
blockId = 0; //TODO replace new blocks
} else if (blockId > 1127) {
blockId -= 1;
} else if (blockId == 1127) {
blockId = 1126;
}
return blockId;
}
public static int getNewBlockId(int blockId) {
if (blockId > 565) {
blockId -= 5;
} else if (blockId > 561) {
blockId = 0; // Replacements not needed
}
return blockId;
} }
@Override @Override
@ -208,7 +179,13 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
// Init protocol in EntityTracker // Init protocol in EntityTracker
user.get(EntityTracker.class).initProtocol(this); user.get(EntityTracker.class).initProtocol(this);
if (!user.has(ClientWorld.class)) if (!user.has(ClientWorld.class)) {
user.put(new ClientWorld(user)); user.put(new ClientWorld(user));
} }
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
}

Datei anzeigen

@ -51,7 +51,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
// Rewrite falling block // Rewrite falling block
if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) { if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} }
// Track Entity // Track Entity
@ -134,7 +134,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
} else if (meta.getMetaType() == MetaType1_13.BlockID) { } else if (meta.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id // Convert to new block id
int data = (int) meta.getValue(); int data = (int) meta.getValue();
meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
return meta; return meta;
@ -160,7 +160,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
Metadata meta = e.getData(); Metadata meta = e.getData();
int data = (int) meta.getValue(); int data = (int) meta.getValue();
meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
return meta; return meta;
}); });

Datei anzeigen

@ -1,5 +1,6 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets; package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -15,7 +16,7 @@ public class InventoryPackets1_13_1 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets1_13_1::toClient, InventoryPackets1_13_1::toServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets1_13_1::toClient, InventoryPackets1_13_1::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets1_13_1::getOldItemId); itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY); itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM); itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
@ -62,27 +63,11 @@ public class InventoryPackets1_13_1 {
public static void toClient(Item item) { public static void toClient(Item item) {
if (item == null) return; if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier())); item.setIdentifier(Protocol1_13To1_13_1.MAPPINGS.getNewItemId(item.getIdentifier()));
}
// 1.13.1 Item Id
public static int getNewItemId(int itemId) {
if (itemId >= 443) {
return itemId + 5;
}
return itemId;
} }
public static void toServer(Item item) { public static void toServer(Item item) {
if (item == null) return; if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier())); item.setIdentifier(Protocol1_13To1_13_1.MAPPINGS.getOldItemId(item.getIdentifier()));
}
// 1.13 Item Id
public static int getOldItemId(int newId) {
if (newId >= 448) {
return newId - 5;
}
return newId;
} }
} }

Datei anzeigen

@ -1,6 +1,5 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets; package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
@ -16,7 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class WorldPackets1_13_1 { public class WorldPackets1_13_1 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13To1_13_1::getNewBlockStateId, Protocol1_13To1_13_1::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() { protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override @Override
@ -30,7 +29,7 @@ public class WorldPackets1_13_1 {
for (ChunkSection section : chunk.getSections()) { for (ChunkSection section : chunk.getSections()) {
if (section != null) { if (section != null) {
for (int i = 0; i < section.getPaletteSize(); i++) { for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, Protocol1_13To1_13_1.getNewBlockStateId(section.getPaletteEntry(i))); section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
} }
} }
} }
@ -42,7 +41,7 @@ public class WorldPackets1_13_1 {
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION); blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE); blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets1_13_1::getOldItemId); blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001);
blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets1_13_1::toClient, Type.FLAT_ITEM, Type.FLOAT); blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets1_13_1::toClient, Type.FLAT_ITEM, Type.FLOAT);
} }
} }

Datei anzeigen

@ -1,11 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15; package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.BackwardsMappings;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPackets1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPackets1_15;
@ -20,10 +19,10 @@ 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.ServerboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_15, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> { public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_15, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.15", "1.14", Protocol1_15To1_14_4.class, true);
private BlockItemPackets1_15 blockItemPackets; private BlockItemPackets1_15 blockItemPackets;
public Protocol1_14_4To1_15() { public Protocol1_14_4To1_15() {
@ -32,7 +31,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, BackwardsMappings::init); executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, MAPPINGS::loadVBMappings);
TranslatableRewriter translatableRewriter = new TranslatableRewriter(this); TranslatableRewriter translatableRewriter = new TranslatableRewriter(this);
translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR); translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
@ -47,8 +46,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
(blockItemPackets = new BlockItemPackets1_15(this, translatableRewriter)).register(); (blockItemPackets = new BlockItemPackets1_15(this, translatableRewriter)).register();
new EntityPackets1_15(this).register(); new EntityPackets1_15(this).register();
SoundRewriter soundRewriter = new SoundRewriter(this, SoundRewriter soundRewriter = new SoundRewriter(this);
id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId));
soundRewriter.registerSound(ClientboundPackets1_15.SOUND); soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND); soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND); soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND);
@ -79,29 +77,9 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), new TagRewriter(this, EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS);
id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS);
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id), new StatisticsRewriter(this, EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.STATISTICS);
EntityTypeMapping::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_15.STATISTICS);
}
public static int getNewBlockStateId(int id) {
int newId = BackwardsMappings.blockStateMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 blockstate id for 1.14.4 block " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = BackwardsMappings.blockMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 block id for 1.14.4 block " + id);
return id;
}
return newId;
} }
@Override @Override
@ -118,4 +96,9 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
public BlockItemPackets1_15 getBlockItemPackets() { public BlockItemPackets1_15 getBlockItemPackets() {
return blockItemPackets; return blockItemPackets;
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
} }

Datei anzeigen

@ -1,31 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings {
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings;
public static void init() {
ViaBackwards.getPlatform().getLogger().info("Loading 1.15 -> 1.14.4 mappings...");
JsonObject mapping1_14 = MappingDataLoader.getMappingsCache().get("mapping-1.14.json");
JsonObject mapping1_15 = MappingDataLoader.getMappingsCache().get("mapping-1.15.json");
JsonObject mapping1_14to1_15 = VBMappingDataLoader.loadFromDataDir("mapping-1.14.4to1.15.json");
blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_15.getAsJsonArray("statistics"), mapping1_14.getAsJsonArray("statistics"), false);
}
}

Datei anzeigen

@ -1,9 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets; package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -18,19 +16,18 @@ 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_14to1_13_2.data.RecipeRewriter1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_14_4To1_15> { public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_14_4To1_15> {
public BlockItemPackets1_15(Protocol1_14_4To1_15 protocol, TranslatableRewriter translatableRewriter) { public BlockItemPackets1_15(Protocol1_14_4To1_15 protocol, TranslatableRewriter translatableRewriter) {
super(protocol, translatableRewriter, BlockItemPackets1_15::getOldItemId, BlockItemPackets1_15::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id)); super(protocol, translatableRewriter);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_14(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES); new RecipeRewriter1_14(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
@ -41,7 +38,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
} }
}); });
itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, BlockItemPackets1_15::getOldItemId); itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
@ -92,7 +89,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
if (section == null) continue; if (section == null) continue;
for (int j = 0; j < section.getPaletteSize(); j++) { for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j); int old = section.getPaletteEntry(j);
int newId = Protocol1_14_4To1_15.getNewBlockStateId(old); int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId); section.setPaletteEntry(j, newId);
} }
} }
@ -101,7 +98,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
} }
}); });
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, BlockItemPackets1_15::getOldItemId); blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() { protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {
@Override @Override
@ -127,7 +124,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
if (id == 3 || id == 23) { if (id == 3 || id == 23) {
int data = wrapper.passthrough(Type.VAR_INT); int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_14_4To1_15.getNewBlockStateId(data)); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) { } else if (id == 32) {
Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM)); Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
wrapper.write(Type.FLAT_VAR_INT_ITEM, item); wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
@ -137,23 +134,4 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
} }
}); });
} }
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 item for 1.14.4 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
if (oldId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.14.4 item for 1.15 item " + id);
return 1;
}
return oldId;
}
} }

Datei anzeigen

@ -58,7 +58,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
} }
}); });
registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_14_4To1_15::getNewBlockStateId); registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK);
protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_MOB, new PacketRemapper() { protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_MOB, new PacketRemapper() {
@Override @Override
@ -191,7 +191,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item)); meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
} else if (type == MetaType1_14.BlockID) { } else if (type == MetaType1_14.BlockID) {
int blockstate = (int) meta.getValue(); int blockstate = (int) meta.getValue();
meta.setValue(Protocol1_14_4To1_15.getNewBlockStateId(blockstate)); meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
} else if (type == MetaType1_14.PARTICLE) { } else if (type == MetaType1_14.PARTICLE) {
Particle particle = (Particle) meta.getValue(); Particle particle = (Particle) meta.getValue();
particle.setId(ParticleMapping.getOldId(particle.getId())); particle.setId(ParticleMapping.getOldId(particle.getId()));

Datei anzeigen

@ -1,6 +1,5 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16; package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
@ -21,7 +20,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.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; 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.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
@ -31,6 +29,7 @@ import java.util.UUID;
public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_16, ClientboundPackets1_15, ServerboundPackets1_16, ServerboundPackets1_14> { public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_16, ClientboundPackets1_15, ServerboundPackets1_16, ServerboundPackets1_14> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
private BlockItemPackets1_16 blockItemPackets; private BlockItemPackets1_16 blockItemPackets;
private TranslatableRewriter translatableRewriter; private TranslatableRewriter translatableRewriter;
@ -40,7 +39,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, BackwardsMappings::init); executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, MAPPINGS::loadVBMappings);
translatableRewriter = new TranslatableRewriter1_16(this); translatableRewriter = new TranslatableRewriter1_16(this);
translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR); translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR);
@ -95,8 +94,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
SoundRewriter soundRewriter = new SoundRewriter(this, SoundRewriter soundRewriter = new SoundRewriter(this);
id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId));
soundRewriter.registerSound(ClientboundPackets1_16.SOUND); soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND); soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND); soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
@ -114,11 +112,9 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new TagRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS);
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS);
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id), new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16.STATISTICS);
entityPackets::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_16.STATISTICS);
registerIncoming(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() { registerIncoming(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {
@Override @Override
@ -175,24 +171,6 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK); cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
} }
public static int getNewBlockStateId(int id) {
int newId = BackwardsMappings.blockStateMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 blockstate id for 1.15 block " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = BackwardsMappings.blockMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 block id for 1.15 block " + id);
return id;
}
return newId;
}
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
if (!user.has(ClientWorld.class)) { if (!user.has(ClientWorld.class)) {
@ -212,4 +190,9 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
public TranslatableRewriter getTranslatableRewriter() { public TranslatableRewriter getTranslatableRewriter() {
return translatableRewriter; return translatableRewriter;
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
} }

Datei anzeigen

@ -1,40 +1,26 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data; package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data;
import nl.matsv.viabackwards.ViaBackwards; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class BackwardsMappings { public class BackwardsMappings extends nl.matsv.viabackwards.api.data.BackwardsMappings {
public static Mappings blockStateMappings; private final Map<String, String> attributeMappings = new HashMap<>();
public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings;
public static Map<String, String> attributeMappings = new HashMap<>();
public static void init() { public BackwardsMappings() {
ViaBackwards.getPlatform().getLogger().info("Loading 1.16 -> 1.15.2 mappings..."); super("1.16", "1.15", Protocol1_16To1_15_2.class, true);
JsonObject mapping1_15 = MappingDataLoader.getMappingsCache().get("mapping-1.15.json"); }
JsonObject mapping1_16 = MappingDataLoader.getMappingsCache().get("mapping-1.16.json");
JsonObject mapping1_15to1_16 = VBMappingDataLoader.loadFromDataDir("mapping-1.15to1.16.json");
blockStateMappings = new VBMappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), mapping1_15to1_16.getAsJsonObject("blockstates")); @Override
blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false); protected void loadVBExtras(JsonObject oldMappings, JsonObject newMappings) {
itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items")); for (Map.Entry<String, String> entry : Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings().entrySet()) {
soundMappings = new VBSoundMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_16.getAsJsonArray("statistics"), mapping1_15.getAsJsonArray("statistics"), false);
for (Map.Entry<String, String> entry : MappingData.attributeMappings.entrySet()) {
attributeMappings.put(entry.getValue(), entry.getKey()); attributeMappings.put(entry.getValue(), entry.getKey());
} }
} }
public Map<String, String> getAttributeMappings() {
return attributeMappings;
}
} }

Datei anzeigen

@ -1,10 +1,8 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets; package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewriter; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewriter;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
@ -21,7 +19,6 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_1
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
import us.myles.ViaVersion.util.CompactArrayUtil; import us.myles.ViaVersion.util.CompactArrayUtil;
@ -40,14 +37,13 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
private EnchantmentRewriter enchantmentRewriter; private EnchantmentRewriter enchantmentRewriter;
public BlockItemPackets1_16(Protocol1_15_2To1_16 protocol, TranslatableRewriter translatableRewriter) { public BlockItemPackets1_16(Protocol1_15_2To1_16 protocol, TranslatableRewriter translatableRewriter) {
super(protocol, translatableRewriter, super(protocol, translatableRewriter);
BlockItemPackets1_16::getOldItemId, BlockItemPackets1_16::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id));
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol, this::handleItemToClient); RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol, this::handleItemToClient);
// Remove new smithing type, only in this handler // Remove new smithing type, only in this handler
@ -80,7 +76,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
} }
}); });
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16::getOldItemId); itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
@ -145,7 +141,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
if (section == null) continue; if (section == null) continue;
for (int j = 0; j < section.getPaletteSize(); j++) { for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j); int old = section.getPaletteEntry(j);
section.setPaletteEntry(j, Protocol1_15_2To1_16.getNewBlockStateId(old)); section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
} }
} }
@ -179,7 +175,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
} }
}); });
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001, BlockItemPackets1_16::getOldItemId); blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
blockRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, 3, 23, 34, blockRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, 3, 23, 34,
BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
@ -375,24 +371,6 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
return item; return item;
} }
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 item for 1.15 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
if (oldId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 item for 1.16 item " + id);
return 1;
}
return oldId;
}
private static final class EquipmentData { private static final class EquipmentData {
private final int slot; private final int slot;
private final Item item; private final Item item;

Datei anzeigen

@ -3,7 +3,6 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.entities.Entity1_16Types;
@ -45,7 +44,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_15_2To1_16::getNewBlockStateId); registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK);
registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB); registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB);
protocol.registerOutgoing(ClientboundPackets1_16.RESPAWN, new PacketRemapper() { protocol.registerOutgoing(ClientboundPackets1_16.RESPAWN, new PacketRemapper() {
@ -128,7 +127,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
int size = wrapper.passthrough(Type.INT); int size = wrapper.passthrough(Type.INT);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
String attributeIdentifier = wrapper.read(Type.STRING); String attributeIdentifier = wrapper.read(Type.STRING);
String oldKey = BackwardsMappings.attributeMappings.get(attributeIdentifier); String oldKey = protocol.getMappingData().getAttributeMappings().get(attributeIdentifier);
wrapper.write(Type.STRING, oldKey != null ? oldKey : attributeIdentifier.replace("minecraft:", "")); wrapper.write(Type.STRING, oldKey != null ? oldKey : attributeIdentifier.replace("minecraft:", ""));
wrapper.passthrough(Type.DOUBLE); wrapper.passthrough(Type.DOUBLE);
@ -191,7 +190,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
if (type == MetaType1_14.Slot) { if (type == MetaType1_14.Slot) {
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue())); meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
} else if (type == MetaType1_14.BlockID) { } else if (type == MetaType1_14.BlockID) {
meta.setValue(Protocol1_15_2To1_16.getNewBlockStateId((int) meta.getValue())); meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
} else if (type == MetaType1_14.PARTICLE) { } else if (type == MetaType1_14.PARTICLE) {
Particle particle = (Particle) meta.getValue(); Particle particle = (Particle) meta.getValue();
particle.setId(ParticleMapping.getOldId(particle.getId())); particle.setId(ParticleMapping.getOldId(particle.getId()));

Datei anzeigen

@ -1,11 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2; package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.BackwardsMappings;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
@ -18,12 +17,12 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
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.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.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.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> { public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.16.2", "1.16", Protocol1_16_2To1_16_1.class, true);
private BlockItemPackets1_16_2 blockItemPackets; private BlockItemPackets1_16_2 blockItemPackets;
private TranslatableRewriter translatableRewriter; private TranslatableRewriter translatableRewriter;
@ -33,7 +32,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_16_2To1_16_1.class, BackwardsMappings::init); executeAsyncAfterLoaded(Protocol1_16_2To1_16_1.class, MAPPINGS::loadVBMappings);
translatableRewriter = new TranslatableRewriter(this); translatableRewriter = new TranslatableRewriter(this);
translatableRewriter.registerBossBar(ClientboundPackets1_16_2.BOSSBAR); translatableRewriter.registerBossBar(ClientboundPackets1_16_2.BOSSBAR);
@ -49,8 +48,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
EntityPackets1_16_2 entityPackets = new EntityPackets1_16_2(this); EntityPackets1_16_2 entityPackets = new EntityPackets1_16_2(this);
entityPackets.register(); entityPackets.register();
SoundRewriter soundRewriter = new SoundRewriter(this, SoundRewriter soundRewriter = new SoundRewriter(this);
id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId));
soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND); soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND); soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND); soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
@ -92,29 +90,9 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
} }
}); });
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new TagRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.TAGS);
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.TAGS);
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.STATISTICS);
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.STATISTICS);
}
public static int getNewBlockStateId(int id) {
int newId = BackwardsMappings.blockStateMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 blockstate id for 1.16.2 block " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = BackwardsMappings.blockMappings.getNewId(id);
if (newId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 block id for 1.16.2 block " + id);
return id;
}
return newId;
} }
@Override @Override
@ -132,4 +110,9 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
public TranslatableRewriter getTranslatableRewriter() { public TranslatableRewriter getTranslatableRewriter() {
return translatableRewriter; return translatableRewriter;
} }
@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}
} }

Datei anzeigen

@ -1,29 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings {
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings;
public static void init() {
ViaBackwards.getPlatform().getLogger().info("Loading 1.16.2 -> 1.16.1 mappings...");
JsonObject mapping1_16 = MappingDataLoader.getMappingsCache().get("mapping-1.16.json");
JsonObject mapping1_16_2 = MappingDataLoader.getMappingsCache().get("mapping-1.16.2.json");
JsonObject mapping1_16to1_16_2 = VBMappingDataLoader.loadFromDataDir("mapping-1.16to1.16.2.json");
blockStateMappings = new VBMappings(mapping1_16_2.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), mapping1_16to1_16_2.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_16_2.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"), mapping1_16to1_16_2.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_16_2.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), mapping1_16to1_16_2.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_16_2.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), mapping1_16to1_16_2.getAsJsonObject("sounds"));
}
}

Datei anzeigen

@ -1,9 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets; package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord1_8; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord1_8;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
@ -14,7 +12,6 @@ import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
@ -29,18 +26,17 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> { public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> {
public BlockItemPackets1_16_2(Protocol1_16_1To1_16_2 protocol, TranslatableRewriter translatableRewriter) { public BlockItemPackets1_16_2(Protocol1_16_1To1_16_2 protocol, TranslatableRewriter translatableRewriter) {
super(protocol, translatableRewriter, super(protocol, translatableRewriter);
BlockItemPackets1_16_2::getOldItemId, BlockItemPackets1_16_2::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id));
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16_1To1_16_2::getNewBlockStateId, Protocol1_16_1To1_16_2::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES); new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
itemRewriter.registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN, BlockItemPackets1_16_2::getOldItemId); itemRewriter.registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
itemRewriter.registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
@ -82,7 +78,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
if (section == null) continue; if (section == null) continue;
for (int j = 0; j < section.getPaletteSize(); j++) { for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j); int old = section.getPaletteEntry(j);
section.setPaletteEntry(j, Protocol1_16_1To1_16_2.getNewBlockStateId(old)); section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
} }
} }
@ -92,7 +88,6 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
IntTag x = blockEntity.get("x"); IntTag x = blockEntity.get("x");
IntTag y = blockEntity.get("y"); IntTag y = blockEntity.get("y");
IntTag z = blockEntity.get("z"); IntTag z = blockEntity.get("z");
if (x != null && y != null && z != null) { if (x != null && y != null && z != null) {
handleBlockEntity(blockEntity, new Position(x.getValue(), y.getValue().shortValue(), z.getValue())); handleBlockEntity(blockEntity, new Position(x.getValue(), y.getValue().shortValue(), z.getValue()));
} }
@ -129,7 +124,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord); wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord);
for (int i = 0; i < blockChangeRecord.length; i++) { for (int i = 0; i < blockChangeRecord.length; i++) {
BlockChangeRecord record = blockChangeRecord[i]; BlockChangeRecord record = blockChangeRecord[i];
int blockId = Protocol1_16_1To1_16_2.getNewBlockStateId(record.getBlockId()); int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
// Relative y -> absolute y // Relative y -> absolute y
blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId); blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId);
} }
@ -137,7 +132,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
} }
}); });
blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001, BlockItemPackets1_16_2::getOldItemId); blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
blockRewriter.registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, 3, 23, 34, blockRewriter.registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, 3, 23, 34,
null, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); null, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
@ -177,22 +172,4 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
skullOwnerCompoundTag.put(new IntArrayTag("Id", uuidIntArray)); skullOwnerCompoundTag.put(new IntArrayTag("Id", uuidIntArray));
} }
} }
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
ViaBackwards.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);
if (oldId == -1) {
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 item for 1.16.2 item " + id);
return 1;
}
return oldId;
}
} }

Datei anzeigen

@ -31,7 +31,7 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerSpawnTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK, Protocol1_16_1To1_16_2::getNewBlockStateId); registerSpawnTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK);
registerSpawnTracker(ClientboundPackets1_16_2.SPAWN_MOB); registerSpawnTracker(ClientboundPackets1_16_2.SPAWN_MOB);
registerExtraTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EntityType.EXPERIENCE_ORB); registerExtraTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EntityType.EXPERIENCE_ORB);
registerExtraTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.EntityType.PAINTING); registerExtraTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.EntityType.PAINTING);
@ -97,7 +97,7 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
if (type == MetaType1_14.Slot) { if (type == MetaType1_14.Slot) {
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue())); meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
} else if (type == MetaType1_14.BlockID) { } else if (type == MetaType1_14.BlockID) {
meta.setValue(Protocol1_16_1To1_16_2.getNewBlockStateId((int) meta.getValue())); meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
} else if (type == MetaType1_14.OptChat) { } else if (type == MetaType1_14.OptChat) {
JsonElement text = meta.getCastedValue(); JsonElement text = meta.getCastedValue();
if (text != null) { if (text != null) {

Datei anzeigen

@ -0,0 +1,20 @@
{
"blockstates": {
"minecraft:tnt[unstable=false]": "minecraft:tnt",
"minecraft:tnt[unstable=true]": "minecraft:tnt",
"minecraft:oak_sign": "minecraft:sign[",
"minecraft:oak_wall_sign": "minecraft:wall_sign[",
"minecraft:smooth_stone_slab": "minecraft:stone_slab[",
"minecraft:dead_tube_coral": "minecraft:tube_coral",
"minecraft:dead_brain_coral": "minecraft:brain_coral",
"minecraft:dead_bubble_coral": "minecraft:bubble_coral",
"minecraft:dead_fire_coral": "minecraft:fire_coral",
"minecraft:dead_horn_coral": "minecraft:horn_coral",
"minecraft:tube_coral": "minecraft:tube_coral",
"minecraft:brain_coral": "minecraft:brain_coral",
"minecraft:bubble_coral": "minecraft:bubble_coral",
"minecraft:fire_coral": "minecraft:fire_coral",
"minecraft:horn_coral": "minecraft:horn_coral",
"minecraft:conduit": "minecraft:conduit"
}
}

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-fabric</artifactId> <artifactId>viabackwards-fabric</artifactId>

Datei anzeigen

@ -16,7 +16,7 @@
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<description>Allow older clients to join newer server versions.</description> <description>Allow older clients to join newer server versions.</description>
@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion</artifactId> <artifactId>viaversion</artifactId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-sponge</artifactId> <artifactId>viabackwards-sponge</artifactId>

Datei anzeigen

@ -16,7 +16,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>3.1.1-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>viabackwards-velocity</artifactId> <artifactId>viabackwards-velocity</artifactId>