Fix 1.16->1.15 lightning

Closes ViaVersion/ViaVersion#2309
This commit is contained in:
KennyTV 2021-02-01 16:17:53 +01:00
parent 0da5b65858
commit 0166d1a3b1
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 44 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
@ -37,15 +38,19 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(wrapper -> {
handler(getSpawnTracketWithDataHandler(fallingBlockType));
}
});
}
public PacketHandler getSpawnTracketWithDataHandler(EntityType fallingBlockType) {
return wrapper -> {
EntityType entityType = setOldEntityId(wrapper);
if (entityType == fallingBlockType) {
int blockState = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(blockState));
}
});
}
});
};
}
public void registerSpawnTracker(ClientboundPacketType packetType) {

View File

@ -44,7 +44,37 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@Override
protected void registerPackets() {
registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK);
protocol.registerOutgoing(ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(wrapper -> {
EntityType entityType = getTypeFromId(wrapper.get(Type.VAR_INT, 1));
if (entityType == Entity1_16Types.EntityType.LIGHTNING_BOLT) {
// Map to old weather entity packet
wrapper.cancel();
PacketWrapper spawnLightningPacket = wrapper.create(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY.ordinal());
spawnLightningPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0)); // Entity id
spawnLightningPacket.write(Type.BYTE, (byte) 1); // Lightning type
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 0)); // X
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 1)); // Y
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 2)); // Z
spawnLightningPacket.send(Protocol1_15_2To1_16.class, true, true);
}
});
handler(getSpawnTracketWithDataHandler(Entity1_16Types.EntityType.FALLING_BLOCK));
}
});
registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB);
protocol.registerOutgoing(ClientboundPackets1_16.RESPAWN, new PacketRemapper() {

View File

@ -76,7 +76,7 @@
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>LATEST</version>
<version>7.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>