From 963630db7e7a90d8cb77e0f647a2dcf25e4eefeb Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 16 Dec 2020 20:32:16 +0100 Subject: [PATCH] 20w51a --- .../Protocol1_16_4To1_17.java | 70 +++++++++++++++++-- .../packets/EntityPackets1_17.java | 16 ++++- .../data/mapping-1.16.2to1.17.json | 19 ++++- pom.xml | 2 +- 4 files changed, 98 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/Protocol1_16_4To1_17.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/Protocol1_16_4To1_17.java index 6d002a21..9a294915 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/Protocol1_16_4To1_17.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/Protocol1_16_4To1_17.java @@ -1,5 +1,7 @@ package nl.matsv.viabackwards.protocol.protocol1_16_4to1_17; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.data.BackwardsMappings; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; @@ -8,6 +10,7 @@ import nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPack import nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.api.rewriters.RegistryType; import us.myles.ViaVersion.api.rewriters.StatisticsRewriter; import us.myles.ViaVersion.api.rewriters.TagRewriter; @@ -17,9 +20,15 @@ import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_ import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class Protocol1_16_4To1_17 extends BackwardsProtocol { public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.17", "1.16.2", Protocol1_17To1_16_4.class, true); + private static final int[] EMPTY_ARRAY = {}; private BlockItemPackets1_17 blockItemPackets; public Protocol1_16_4To1_17() { @@ -45,13 +54,55 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol { - // Goodbye Game Event tags + Map> tags = new HashMap<>(); + int length = wrapper.read(Type.VAR_INT); for (int i = 0; i < length; i++) { - wrapper.read(Type.STRING); - wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE); + String resourceKey = wrapper.read(Type.STRING); + if (resourceKey.startsWith("minecraft:")) { + resourceKey = resourceKey.substring(10); + } + + List tagList = new ArrayList<>(); + tags.put(resourceKey, tagList); + + int tagLength = wrapper.read(Type.VAR_INT); + for (int j = 0; j < tagLength; j++) { + String identifier = wrapper.read(Type.STRING); + int[] entries = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE); + tagList.add(new TagRewriter.TagData(identifier, entries)); + } + } + + // Put them into the hardcoded order of Vanilla tags (and only those) + for (RegistryType type : RegistryType.getValues()) { + List tagList = tags.get(type.getResourceLocation()); + IdRewriteFunction rewriter = tagRewriter.getRewriter(type); + + wrapper.write(Type.VAR_INT, tagList.size()); + for (TagRewriter.TagData tagData : tagList) { + int[] entries = tagData.getEntries(); + if (rewriter != null) { + // Handle id rewriting now + IntList idList = new IntArrayList(entries.length); + for (int id : entries) { + int mappedId = rewriter.rewrite(id); + if (mappedId != -1) { + idList.add(mappedId); + } + } + entries = idList.toArray(EMPTY_ARRAY); + } + + wrapper.write(Type.STRING, tagData.getIdentifier()); + wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, entries); + } + + // Stop after the entityt types + if (type == RegistryType.ENTITY) { + break; + } } }); } @@ -106,4 +157,15 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol { protected void registerRewrites() { registerMetaHandler().handle(e -> { Metadata meta = e.getData(); + meta.setMetaType(MetaType1_14.byId(meta.getMetaType().getTypeID())); + MetaType type = meta.getMetaType(); - meta.setMetaType(MetaType1_14.byId(type.getTypeID())); if (type == MetaType1_14.Slot) { meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue())); } else if (type == MetaType1_14.BlockID) { @@ -106,6 +108,13 @@ public class EntityPackets1_17 extends EntityRewriter { return meta; }); + mapTypes(Entity1_17Types.EntityType.values(), Entity1_16_2Types.EntityType.class); + registerMetaHandler().filter(Entity1_17Types.EntityType.AXOLOTL, 17).removed(); + registerMetaHandler().filter(Entity1_17Types.EntityType.AXOLOTL, 18).removed(); + registerMetaHandler().filter(Entity1_17Types.EntityType.AXOLOTL, 19).removed(); + + mapEntity(Entity1_17Types.EntityType.AXOLOTL, Entity1_17Types.EntityType.TROPICAL_FISH).jsonName("Axolotl"); + registerMetaHandler().filter(7).removed(); // Ticks frozen registerMetaHandler().handle(meta -> { if (meta.getIndex() > 7) { @@ -117,14 +126,15 @@ public class EntityPackets1_17 extends EntityRewriter { @Override protected EntityType getTypeFromId(int typeId) { - return Entity1_16_2Types.getTypeFromId(typeId); + return Entity1_17Types.getTypeFromId(typeId); } private void warnForExtendedHeight(CompoundTag tag) { IntTag minY = tag.get("min_y"); - IntTag height = tag.get("min_y"); + IntTag height = tag.get("height"); if (minY.getValue() != 0 || height.getValue() != 256) { ViaBackwards.getPlatform().getLogger().severe("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!"); + ViaBackwards.getPlatform().getLogger().severe("You have min/max set to " + minY.getValue() + "/" + height.getValue()); } } } diff --git a/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json b/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json index 8bcb4486..c6b0d160 100644 --- a/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json +++ b/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json @@ -928,6 +928,14 @@ "minecraft:sculk_sensor": { "id": "minecraft:dark_prismarine_slab", "name": "1.17 Sculk Sensor" + }, + "minecraft:axolotl_bucket": { + "id": "minecraft:tropical_fish_bucket", + "name": "1.17 Bucket of Axolotl" + }, + "minecraft:axolotl_spawn_egg": { + "id": "minecraft:shulker_spawn_egg", + "name": "1.17 Axolotl Spawn Egg" } }, "sounds": { @@ -1003,7 +1011,16 @@ "block.sculk_sensor.fall": "", "block.sculk_sensor.hit": "", "block.sculk_sensor.place": "", - "block.sculk_sensor.step": "" + "block.sculk_sensor.step": "", + "entity.axolotl.attack": "", + "entity.axolotl.death": "", + "entity.axolotl.hurt": "", + "entity.axolotl.idle_air": "", + "entity.axolotl.idle_water": "", + "entity.axolotl.splash": "", + "entity.axolotl.swim": "", + "item.bucket.empty_axolotl": "", + "item.bucket.fill_axolotl": "" }, "particles": { "small_flame": "flame", diff --git a/pom.xml b/pom.xml index f523b79b..39e8a39f 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ us.myles viaversion - 3.3.0-20w49a + 3.3.0-20w51a provided