Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2025-01-11 15:41:03 +01:00
Properly track minecart object entity types in <= 1.12.2 (#946)
Dieser Commit ist enthalten in:
Ursprung
481b06cd2a
Commit
29ec02687c
@ -18,9 +18,16 @@
|
||||
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.ShortTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.BlockColors1_11_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
@ -41,17 +48,10 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.ShortTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
@ -226,10 +226,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
public PacketHandler getFallingBlockHandler() {
|
||||
return wrapper -> {
|
||||
final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0));
|
||||
final int objectData = wrapper.get(Types.INT, 0);
|
||||
final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0), objectData);
|
||||
if (type == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
final int objectData = wrapper.get(Types.INT, 0);
|
||||
|
||||
final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15);
|
||||
if (block == null) return;
|
||||
|
||||
|
@ -36,7 +36,6 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> {
|
||||
@ -125,7 +124,9 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
|
||||
protected PacketHandler getObjectTrackerHandler() {
|
||||
return wrapper -> {
|
||||
EntityType type = objectTypeFromId(wrapper.get(Types.BYTE, 0));
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
EntityType type = objectTypeFromId(id, data);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
@ -142,18 +143,20 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) {
|
||||
protected PacketHandler getObjectRewriter(ObjectTypeGetter objectGetter) {
|
||||
return wrapper -> {
|
||||
ObjectType type = objectGetter.apply(wrapper.get(Types.BYTE, 0));
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
ObjectType type = objectGetter.get(id, data);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityReplacement data = getObjectData(type);
|
||||
if (data != null) {
|
||||
wrapper.set(Types.BYTE, 0, (byte) data.replacementId());
|
||||
if (data.objectData() != -1) {
|
||||
wrapper.set(Types.INT, 0, data.objectData());
|
||||
EntityReplacement replacement = getObjectData(type);
|
||||
if (replacement != null) {
|
||||
wrapper.set(Types.BYTE, 0, (byte) replacement.replacementId());
|
||||
if (replacement.objectData() != -1) {
|
||||
wrapper.set(Types.INT, 0, replacement.objectData());
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -169,4 +172,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
|
||||
void setId(PacketWrapper wrapper, int id);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface ObjectTypeGetter {
|
||||
|
||||
ObjectType get(int id, int data);
|
||||
}
|
||||
}
|
||||
|
@ -164,11 +164,11 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_10.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_10.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_10.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_10.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
|
@ -117,11 +117,11 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<Clientbound
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_11.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_11.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
|
@ -364,11 +364,11 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_11.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_11.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.storage.ParrotStorage;
|
||||
@ -35,7 +36,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
|
||||
public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_12To1_11_1> {
|
||||
|
||||
@ -285,11 +285,11 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_12.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_12.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_12.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_12.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
byte type = wrapper.get(Types.BYTE, 0);
|
||||
EntityTypes1_13.EntityType entType = EntityTypes1_13.getTypeFromId(type, true);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
EntityTypes1_13.EntityType entType = EntityTypes1_13.ObjectType.getEntityType(type, data);
|
||||
if (entType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Rewrite falling block
|
||||
if (entType.is(EntityTypes1_13.EntityType.FALLING_BLOCK)) {
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
wrapper.set(Types.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
@ -159,11 +159,11 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_13.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_13.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
|
@ -90,14 +90,14 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(wrapper -> {
|
||||
EntityTypes1_13.ObjectType type = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0));
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
EntityTypes1_13.ObjectType type = EntityTypes1_13.ObjectType.findById(id, data);
|
||||
if (type == EntityTypes1_13.ObjectType.FALLING_BLOCK) {
|
||||
int blockState = wrapper.get(Types.INT, 0);
|
||||
int combined = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(blockState);
|
||||
int combined = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(data);
|
||||
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
|
||||
wrapper.set(Types.INT, 0, combined);
|
||||
} else if (type == EntityTypes1_13.ObjectType.ITEM_FRAME) {
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
data = switch (data) {
|
||||
case 3 -> 0;
|
||||
case 4 -> 1;
|
||||
@ -134,7 +134,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
handler(wrapper -> {
|
||||
int type = wrapper.get(Types.VAR_INT, 1);
|
||||
EntityType entityType = EntityTypes1_13.getTypeFromId(type, false);
|
||||
EntityType entityType = EntityTypes1_13.EntityType.findById(type);
|
||||
if (entityType == null) {
|
||||
return;
|
||||
}
|
||||
@ -358,12 +358,12 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_13.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_13.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +138,7 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int mappedId = newEntityId(id);
|
||||
EntityTypes1_13.EntityType entityType = EntityTypes1_13.getTypeFromId(mappedId, false);
|
||||
EntityTypes1_13.EntityType entityType = EntityTypes1_13.EntityType.findById(mappedId);
|
||||
if (entityType == null) {
|
||||
// Would be EntityType.PIG on a 1.14 client, but later discarded anyway since not an object type
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
projectVersion=5.2.2-SNAPSHOT
|
||||
|
||||
# Smile emoji
|
||||
mcVersions=1.21.4,1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
|
||||
mcVersions=1.21.4, 1.21.3, 1.21.2, 1.21.1, 1.21, 1.20.6, 1.20.5, 1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
|
||||
mcVersionRange=1.10-1.21.4
|
||||
velocityVersion=3.4
|
||||
|
||||
|
@ -3,7 +3,7 @@ metadata.format.version = "1.1"
|
||||
[versions]
|
||||
|
||||
# ViaVersion
|
||||
viaver = "5.2.1-SNAPSHOT"
|
||||
viaver = "5.2.2-SNAPSHOT"
|
||||
|
||||
# Common provided
|
||||
netty = "4.0.20.Final"
|
||||
|
0
sponge/build.gradle.kts
Normale Datei
0
sponge/build.gradle.kts
Normale Datei
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren