mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 18:15:39 +01:00
Add sanity checks for some block nbt (#3129)
This commit is contained in:
parent
c96b2bd859
commit
e71c88f860
@ -309,8 +309,12 @@ public class InventoryPackets extends ItemRewriter<Protocol1_13To1_12_2> {
|
|||||||
if (blockEntityTag.get("Patterns") instanceof ListTag) {
|
if (blockEntityTag.get("Patterns") instanceof ListTag) {
|
||||||
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
|
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
|
||||||
if (pattern instanceof CompoundTag) {
|
if (pattern instanceof CompoundTag) {
|
||||||
IntTag c = ((CompoundTag) pattern).get("Color");
|
Tag c = ((CompoundTag) pattern).get("Color");
|
||||||
c.setValue(15 - c.asInt()); // Invert color id
|
if (c instanceof NumberTag) {
|
||||||
|
// Invert color id
|
||||||
|
((CompoundTag) pattern).put("Color",
|
||||||
|
new IntTag(15 - ((NumberTag) c).asInt()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
|
|||||||
|
|
||||||
Tag base = tag.get("Base");
|
Tag base = tag.get("Base");
|
||||||
int color = 0;
|
int color = 0;
|
||||||
if (base != null) {
|
if (base instanceof NumberTag) {
|
||||||
color = ((NumberTag) tag.get("Base")).asInt();
|
color = ((NumberTag) base).asInt();
|
||||||
}
|
}
|
||||||
// Standing banner
|
// Standing banner
|
||||||
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
|
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);
|
Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.get("Patterns") instanceof ListTag) {
|
Tag patterns = tag.get("Patterns");
|
||||||
for (Tag pattern : (ListTag) tag.get("Patterns")) {
|
if (patterns instanceof ListTag) {
|
||||||
|
for (Tag pattern : (ListTag) patterns) {
|
||||||
if (pattern instanceof CompoundTag) {
|
if (pattern instanceof CompoundTag) {
|
||||||
Tag c = ((CompoundTag) pattern).get("Color");
|
Tag c = ((CompoundTag) pattern).get("Color");
|
||||||
if (c instanceof IntTag) {
|
if (c instanceof IntTag) {
|
||||||
|
@ -42,7 +42,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
|
|||||||
int blockId = storage.get(position).getOriginal() - 972 + 748;
|
int blockId = storage.get(position).getOriginal() - 972 + 748;
|
||||||
|
|
||||||
Tag color = tag.get("color");
|
Tag color = tag.get("color");
|
||||||
if (color != null) {
|
if (color instanceof NumberTag) {
|
||||||
blockId += (((NumberTag) color).asInt() * 16);
|
blockId += (((NumberTag) color).asInt() * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,12 @@ 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 instanceof NumberTag) {
|
||||||
id += ((NumberTag) tag.get("SkullType")).asInt() * 20;
|
id += ((NumberTag) skullType).asInt() * 20;
|
||||||
}
|
}
|
||||||
if (tag.contains("Rot")) {
|
Tag rot = tag.get("Rot");
|
||||||
id += ((NumberTag) tag.get("Rot")).asInt();
|
if (rot instanceof NumberTag) {
|
||||||
|
id += ((NumberTag) rot).asInt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
|
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
|
||||||
|
@ -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.CompoundTag;
|
||||||
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.viaversion.viaversion.api.connection.UserConnection;
|
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.data.EntityNameRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
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 {
|
public class SpawnerHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||||
@Override
|
@Override
|
||||||
public int transform(UserConnection user, CompoundTag tag) {
|
public int transform(UserConnection user, CompoundTag tag) {
|
||||||
if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) {
|
Tag data = tag.get("SpawnData");
|
||||||
CompoundTag data = tag.get("SpawnData");
|
if (data instanceof CompoundTag) {
|
||||||
if (data.contains("id") && data.get("id") instanceof StringTag) {
|
Tag id = ((CompoundTag) data).get("id");
|
||||||
StringTag s = data.get("id");
|
if (id instanceof StringTag) {
|
||||||
s.setValue(EntityNameRewriter.rewrite(s.getValue()));
|
((StringTag) id).setValue(EntityNameRewriter.rewrite(((StringTag) id).getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||||
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.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||||
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
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) {
|
private static void handleSpawners(int typeId, final CompoundTag tag) {
|
||||||
if (typeId == 8) {
|
if (typeId == 8) {
|
||||||
final CompoundTag entity = tag.get("SpawnData");
|
final Tag entity = tag.get("SpawnData");
|
||||||
if (entity != null) {
|
if (entity instanceof CompoundTag) {
|
||||||
final CompoundTag spawnData = new CompoundTag();
|
final CompoundTag spawnData = new CompoundTag();
|
||||||
tag.put("SpawnData", spawnData);
|
tag.put("SpawnData", spawnData);
|
||||||
spawnData.put("entity", entity);
|
spawnData.put("entity", entity);
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
package com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4;
|
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.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.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
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
|
wrapper.write(Type.POSITION, position); // Position
|
||||||
for (int i = 1; i < 5; i++) {
|
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
|
// 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user