3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 22:02:50 +02:00

Also handle the block entity data packet for nbt

Fixes #1816
Dieser Commit ist enthalten in:
KennyTV 2020-06-25 11:18:07 +02:00
Ursprung dd0ec0033a
Commit 6761489ebf
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
5 geänderte Dateien mit 65 neuen und 39 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -99,8 +99,10 @@ public class WorldPackets {
if (newId != -1) {
BlockStorage storage = wrapper.user().get(BlockStorage.class);
if (storage.contains(position))
storage.get(position).setReplacement(newId);
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
}
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);
// Store the replacement blocks for blockupdates
if (storage.contains(position))
storage.get(position).setReplacement(newId);
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
}

Datei anzeigen

@ -1,6 +1,7 @@
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.Tag;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
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.type.Type;
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.Map;
@ -36,10 +42,10 @@ public class BlockEntityProvider implements Provider {
* @throws Exception Gotta throw that exception
*/
public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception {
if (!tag.contains("id"))
return -1;
Tag idTag = tag.get("id");
if (idTag == null) return -1;
String id = (String) tag.get("id").getValue();
String id = (String) idTag.getValue();
BlockEntityHandler handler = handlers.get(id);
if (handler == null) {
if (Via.getManager().isDebug()) {
@ -50,8 +56,9 @@ public class BlockEntityProvider implements Provider {
int newBlock = handler.transform(user, tag);
if (sendUpdate && newBlock != -1)
if (sendUpdate && newBlock != -1) {
sendBlockChange(user, position, newBlock);
}
return newBlock;
}
@ -67,6 +74,4 @@ public class BlockEntityProvider implements Provider {
public interface BlockEntityHandler {
int transform(UserConnection user, CompoundTag tag);
}
}

Datei anzeigen

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

Datei anzeigen

@ -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.StringTag;
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.ChunkSection;
import us.myles.ViaVersion.api.protocol.Protocol;
@ -69,42 +70,58 @@ public class WorldPackets {
if (chunk.getBlockEntities() == null) return;
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
StringTag idTag = blockEntity.get("id");
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);
}
handleBlockEntity(blockEntity);
}
});
}
});
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.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32,
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) {
if (id >= 27) {
id += 2; // soul flame, soul