Add sanity checks for some block nbt (#3129)

This commit is contained in:
creeper123123321 2022-10-01 05:14:41 -03:00 committed by GitHub
parent c96b2bd859
commit e71c88f860
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 19 deletions

View File

@ -309,8 +309,12 @@ public class InventoryPackets extends ItemRewriter<Protocol1_13To1_12_2> {
if (blockEntityTag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
if (pattern instanceof CompoundTag) {
IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.asInt()); // Invert color id
Tag c = ((CompoundTag) pattern).get("Color");
if (c instanceof NumberTag) {
// Invert color id
((CompoundTag) pattern).put("Color",
new IntTag(15 - ((NumberTag) c).asInt()));
}
}
}
}

View File

@ -51,8 +51,8 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Tag base = tag.get("Base");
int color = 0;
if (base != null) {
color = ((NumberTag) tag.get("Base")).asInt();
if (base instanceof NumberTag) {
color = ((NumberTag) base).asInt();
}
// Standing banner
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
@ -64,8 +64,9 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
if (tag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) tag.get("Patterns")) {
Tag patterns = tag.get("Patterns");
if (patterns instanceof ListTag) {
for (Tag pattern : (ListTag) patterns) {
if (pattern instanceof CompoundTag) {
Tag c = ((CompoundTag) pattern).get("Color");
if (c instanceof IntTag) {

View File

@ -42,7 +42,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
int blockId = storage.get(position).getOriginal() - 972 + 748;
Tag color = tag.get("color");
if (color != null) {
if (color instanceof NumberTag) {
blockId += (((NumberTag) color).asInt() * 16);
}

View File

@ -43,11 +43,12 @@ 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) {
id += ((NumberTag) tag.get("SkullType")).asInt() * 20;
if (skullType instanceof NumberTag) {
id += ((NumberTag) skullType).asInt() * 20;
}
if (tag.contains("Rot")) {
id += ((NumberTag) tag.get("Rot")).asInt();
Tag rot = tag.get("Rot");
if (rot instanceof NumberTag) {
id += ((NumberTag) rot).asInt();
}
} else {
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);

View File

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.EntityNameRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -26,11 +27,11 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockE
public class SpawnerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) {
CompoundTag data = tag.get("SpawnData");
if (data.contains("id") && data.get("id") instanceof StringTag) {
StringTag s = data.get("id");
s.setValue(EntityNameRewriter.rewrite(s.getValue()));
Tag data = tag.get("SpawnData");
if (data instanceof CompoundTag) {
Tag id = ((CompoundTag) data).get("id");
if (id instanceof StringTag) {
((StringTag) id).setValue(EntityNameRewriter.rewrite(((StringTag) id).getValue()));
}
}

View File

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -212,8 +213,8 @@ public final class WorldPackets {
private static void handleSpawners(int typeId, final CompoundTag tag) {
if (typeId == 8) {
final CompoundTag entity = tag.get("SpawnData");
if (entity != null) {
final Tag entity = tag.get("SpawnData");
if (entity instanceof CompoundTag) {
final CompoundTag spawnData = new CompoundTag();
tag.put("SpawnData", spawnData);
spawnData.put("entity", entity);

View File

@ -18,6 +18,8 @@
package com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -63,7 +65,9 @@ public class Protocol1_9_1_2To1_9_3_4 extends AbstractProtocol<ClientboundPacket
wrapper.write(Type.POSITION, position); // Position
for (int i = 1; i < 5; i++) {
// Should technically be written as COMPONENT, but left as String for simplification/to remove redundant wrapping for VR
wrapper.write(Type.STRING, (String) tag.get("Text" + i).getValue()); // Sign line
Tag textTag = tag.get("Text" + i);
String line = textTag instanceof StringTag ? ((StringTag) textTag).getValue() : "";
wrapper.write(Type.STRING, line); // Sign line
}
}
}