This commit is contained in:
KennyTV 2020-12-16 20:32:16 +01:00
parent 54dcb32232
commit 963630db7e
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 98 additions and 9 deletions

View File

@ -1,5 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_16_4to1_17; 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.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.BackwardsMappings; import nl.matsv.viabackwards.api.data.BackwardsMappings;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; 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 nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
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.rewriters.RegistryType; import us.myles.ViaVersion.api.rewriters.RegistryType;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter; import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
import us.myles.ViaVersion.api.rewriters.TagRewriter; 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.ClientboundPackets1_17;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; 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<ClientboundPackets1_17, ClientboundPackets1_16_2, ServerboundPackets1_16_2, ServerboundPackets1_16_2> { public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_17, ClientboundPackets1_16_2, ServerboundPackets1_16_2, ServerboundPackets1_16_2> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.17", "1.16.2", Protocol1_17To1_16_4.class, true); 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; private BlockItemPackets1_17 blockItemPackets;
public Protocol1_16_4To1_17() { public Protocol1_16_4To1_17() {
@ -45,13 +54,55 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
registerOutgoing(ClientboundPackets1_17.TAGS, new PacketRemapper() { registerOutgoing(ClientboundPackets1_17.TAGS, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(tagRewriter.getHandler(RegistryType.ENTITY));
handler(wrapper -> { handler(wrapper -> {
// Goodbye Game Event tags Map<String, List<TagRewriter.TagData>> tags = new HashMap<>();
int length = wrapper.read(Type.VAR_INT); int length = wrapper.read(Type.VAR_INT);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
wrapper.read(Type.STRING); String resourceKey = wrapper.read(Type.STRING);
wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE); if (resourceKey.startsWith("minecraft:")) {
resourceKey = resourceKey.substring(10);
}
List<TagRewriter.TagData> 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<TagRewriter.TagData> 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<ClientboundPackets1_
public BackwardsMappings getMappingData() { public BackwardsMappings getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
private static final class Tag {
private final String key;
private final int[] values;
private Tag(String key, int[] values) {
this.key = key;
this.values = values;
}
}
} }

View File

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17; import nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types; import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.entities.Entity1_17Types;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
@ -69,8 +70,9 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
protected void registerRewrites() { protected void registerRewrites() {
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
meta.setMetaType(MetaType1_14.byId(meta.getMetaType().getTypeID()));
MetaType type = meta.getMetaType(); MetaType type = meta.getMetaType();
meta.setMetaType(MetaType1_14.byId(type.getTypeID()));
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) {
@ -106,6 +108,13 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
return meta; 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().filter(7).removed(); // Ticks frozen
registerMetaHandler().handle(meta -> { registerMetaHandler().handle(meta -> {
if (meta.getIndex() > 7) { if (meta.getIndex() > 7) {
@ -117,14 +126,15 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
@Override @Override
protected EntityType getTypeFromId(int typeId) { protected EntityType getTypeFromId(int typeId) {
return Entity1_16_2Types.getTypeFromId(typeId); return Entity1_17Types.getTypeFromId(typeId);
} }
private void warnForExtendedHeight(CompoundTag tag) { private void warnForExtendedHeight(CompoundTag tag) {
IntTag minY = tag.get("min_y"); IntTag minY = tag.get("min_y");
IntTag height = tag.get("min_y"); IntTag height = tag.get("height");
if (minY.getValue() != 0 || height.getValue() != 256) { 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("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());
} }
} }
} }

View File

@ -928,6 +928,14 @@
"minecraft:sculk_sensor": { "minecraft:sculk_sensor": {
"id": "minecraft:dark_prismarine_slab", "id": "minecraft:dark_prismarine_slab",
"name": "1.17 Sculk Sensor" "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": { "sounds": {
@ -1003,7 +1011,16 @@
"block.sculk_sensor.fall": "", "block.sculk_sensor.fall": "",
"block.sculk_sensor.hit": "", "block.sculk_sensor.hit": "",
"block.sculk_sensor.place": "", "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": { "particles": {
"small_flame": "flame", "small_flame": "flame",

View File

@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion</artifactId> <artifactId>viaversion</artifactId>
<version>3.3.0-20w49a</version> <version>3.3.0-20w51a</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>