Also handle the block entity data packet for nbt

Fixes #1816
This commit is contained in:
KennyTV 2020-06-25 11:18:07 +02:00
parent dd0ec0033a
commit 6761489ebf
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
5 changed files with 65 additions and 39 deletions

View File

@ -223,8 +223,9 @@ public class Protocol1_11To1_10 extends Protocol<ClientboundPackets1_9_3, Client
for (CompoundTag tag : chunk.getBlockEntities()) { for (CompoundTag tag : chunk.getBlockEntities()) {
if (tag.contains("id")) { if (tag.contains("id")) {
String identifier = ((StringTag) tag.get("id")).getValue(); String identifier = ((StringTag) tag.get("id")).getValue();
if (identifier.equals("MobSpawner")) if (identifier.equals("MobSpawner")) {
EntityIdRewriter.toClientSpawner(tag); EntityIdRewriter.toClientSpawner(tag);
}
// Handle new identifier // Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier)); ((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));

View File

@ -99,8 +99,10 @@ public class WorldPackets {
if (newId != -1) { if (newId != -1) {
BlockStorage storage = wrapper.user().get(BlockStorage.class); BlockStorage storage = wrapper.user().get(BlockStorage.class);
if (storage.contains(position)) BlockStorage.ReplacementData replacementData = storage.get(position);
storage.get(position).setReplacement(newId); if (replacementData != null) {
replacementData.setReplacement(newId);
}
} }
if (action == 5) // Set type of flower in flower pot if (action == 5) // Set type of flower in flower pot
@ -431,8 +433,10 @@ public class WorldPackets {
Position position = new Position(x, (short) y, z); Position position = new Position(x, (short) y, z);
// Store the replacement blocks for blockupdates // Store the replacement blocks for blockupdates
if (storage.contains(position)) BlockStorage.ReplacementData replacementData = storage.get(position);
storage.get(position).setReplacement(newId); if (replacementData != null) {
replacementData.setReplacement(newId);
}
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
} }

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -8,7 +9,12 @@ import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.platform.providers.Provider; import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BannerHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BedHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.CommandBlockHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.FlowerPotHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.SkullHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.SpawnerHandler;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -36,10 +42,10 @@ public class BlockEntityProvider implements Provider {
* @throws Exception Gotta throw that exception * @throws Exception Gotta throw that exception
*/ */
public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception {
if (!tag.contains("id")) Tag idTag = tag.get("id");
return -1; if (idTag == null) return -1;
String id = (String) tag.get("id").getValue(); String id = (String) idTag.getValue();
BlockEntityHandler handler = handlers.get(id); BlockEntityHandler handler = handlers.get(id);
if (handler == null) { if (handler == null) {
if (Via.getManager().isDebug()) { if (Via.getManager().isDebug()) {
@ -50,8 +56,9 @@ public class BlockEntityProvider implements Provider {
int newBlock = handler.transform(user, tag); int newBlock = handler.transform(user, tag);
if (sendUpdate && newBlock != -1) if (sendUpdate && newBlock != -1) {
sendBlockChange(user, position, newBlock); sendBlockChange(user, position, newBlock);
}
return newBlock; return newBlock;
} }
@ -67,6 +74,4 @@ public class BlockEntityProvider implements Provider {
public interface BlockEntityHandler { public interface BlockEntityHandler {
int transform(UserConnection user, CompoundTag tag); int transform(UserConnection user, CompoundTag tag);
} }
} }

View File

@ -23,7 +23,6 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
} }
int id = storage.get(position).getOriginal(); int id = storage.get(position).getOriginal();
if (id >= SKULL_WALL_START && id <= SKULL_END) { if (id >= SKULL_WALL_START && id <= SKULL_END) {
Tag skullType = tag.get("SkullType"); Tag skullType = tag.get("SkullType");
if (skullType != null) { if (skullType != null) {

View File

@ -5,6 +5,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.minecraft.Position;
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.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -69,42 +70,58 @@ public class WorldPackets {
if (chunk.getBlockEntities() == null) return; if (chunk.getBlockEntities() == null) return;
for (CompoundTag blockEntity : chunk.getBlockEntities()) { for (CompoundTag blockEntity : chunk.getBlockEntities()) {
StringTag idTag = blockEntity.get("id"); handleBlockEntity(blockEntity);
if (idTag == null) continue;
String id = idTag.getValue();
if (id.equals("minecraft:conduit")) {
StringTag targetUuidTag = blockEntity.remove("target_uuid");
if (targetUuidTag == null) continue;
// target_uuid -> Target
UUID targetUuid = UUID.fromString(targetUuidTag.getValue());
blockEntity.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid)));
} else if (id.equals("minecraft:skull") && blockEntity.get("Owner") instanceof CompoundTag) {
CompoundTag ownerTag = blockEntity.remove("Owner");
StringTag ownerUuidTag = ownerTag.remove("Id");
if (ownerUuidTag != null) {
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid)));
}
// Owner -> SkullOwner
CompoundTag skullOwnerTag = new CompoundTag("SkullOwner");
for (Tag tag : ownerTag) {
skullOwnerTag.put(tag);
}
blockEntity.put(skullOwnerTag);
}
} }
}); });
} }
}); });
protocol.registerOutgoing(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Position position = wrapper.passthrough(Type.POSITION1_14);
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
CompoundTag tag = wrapper.passthrough(Type.NBT);
handleBlockEntity(tag);
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32, blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32,
WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
} }
private static void handleBlockEntity(CompoundTag compoundTag) {
StringTag idTag = compoundTag.get("id");
if (idTag == null) return;
String id = idTag.getValue();
if (id.equals("minecraft:conduit")) {
StringTag targetUuidTag = compoundTag.remove("target_uuid");
if (targetUuidTag == null) return;
// target_uuid -> Target
UUID targetUuid = UUID.fromString(targetUuidTag.getValue());
compoundTag.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid)));
} else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
CompoundTag ownerTag = compoundTag.remove("Owner");
StringTag ownerUuidTag = ownerTag.remove("Id");
if (ownerUuidTag != null) {
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid)));
}
// Owner -> SkullOwner
CompoundTag skullOwnerTag = new CompoundTag("SkullOwner");
for (Tag tag : ownerTag) {
skullOwnerTag.put(tag);
}
compoundTag.put(skullOwnerTag);
}
}
public static int getNewParticleId(int id) { public static int getNewParticleId(int id) {
if (id >= 27) { if (id >= 27) {
id += 2; // soul flame, soul id += 2; // soul flame, soul