Strip unnecessary block entity tag from container NBT

This commit is contained in:
RednedEpic 2023-06-13 22:54:55 -05:00
parent 1b0d03824a
commit d43a862491
3 changed files with 34 additions and 37 deletions

View file

@ -315,7 +315,7 @@ public final class Items {
public static final Item PURPUR_PILLAR = register(new BlockItem("purpur_pillar", builder()));
public static final Item PURPUR_STAIRS = register(new BlockItem("purpur_stairs", builder()));
public static final Item SPAWNER = register(new BlockItem("spawner", builder()));
public static final Item CHEST = register(new BlockItem("chest", builder()));
public static final Item CHEST = register(new ChestItem("chest", builder()));
public static final Item CRAFTING_TABLE = register(new BlockItem("crafting_table", builder()));
public static final Item FARMLAND = register(new BlockItem("farmland", builder()));
public static final Item FURNACE = register(new BlockItem("furnace", builder()));
@ -397,7 +397,7 @@ public final class Items {
public static final Item END_STONE_BRICKS = register(new BlockItem("end_stone_bricks", builder()));
public static final Item DRAGON_EGG = register(new BlockItem("dragon_egg", builder()));
public static final Item SANDSTONE_STAIRS = register(new BlockItem("sandstone_stairs", builder()));
public static final Item ENDER_CHEST = register(new BlockItem("ender_chest", builder()));
public static final Item ENDER_CHEST = register(new ChestItem("ender_chest", builder()));
public static final Item EMERALD_BLOCK = register(new BlockItem("emerald_block", builder()));
public static final Item OAK_STAIRS = register(new BlockItem("oak_stairs", builder()));
public static final Item SPRUCE_STAIRS = register(new BlockItem("spruce_stairs", builder()));
@ -694,7 +694,7 @@ public final class Items {
public static final Item SCULK_SENSOR = register(new BlockItem("sculk_sensor", builder()));
public static final Item CALIBRATED_SCULK_SENSOR = register(new BlockItem("calibrated_sculk_sensor", builder()));
public static final Item TRIPWIRE_HOOK = register(new BlockItem("tripwire_hook", builder()));
public static final Item TRAPPED_CHEST = register(new BlockItem("trapped_chest", builder()));
public static final Item TRAPPED_CHEST = register(new ChestItem("trapped_chest", builder()));
public static final Item TNT = register(new BlockItem("tnt", builder()));
public static final Item REDSTONE_LAMP = register(new BlockItem("redstone_lamp", builder()));
public static final Item NOTE_BLOCK = register(new BlockItem("note_block", builder()));
@ -1192,7 +1192,7 @@ public final class Items {
public static final Item PIGLIN_BANNER_PATTERN = register(new Item("piglin_banner_pattern", builder().stackSize(1)));
public static final Item GOAT_HORN = register(new GoatHornItem("goat_horn", builder().stackSize(1)));
public static final Item COMPOSTER = register(new BlockItem("composter", builder()));
public static final Item BARREL = register(new BlockItem("barrel", builder()));
public static final Item BARREL = register(new ChestItem("barrel", builder()));
public static final Item SMOKER = register(new BlockItem("smoker", builder()));
public static final Item BLAST_FURNACE = register(new BlockItem("blast_furnace", builder()));
public static final Item CARTOGRAPHY_TABLE = register(new BlockItem("cartography_table", builder()));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -23,42 +23,31 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.translator.inventory.item;
package org.geysermc.geyser.item.type;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.session.GeyserSession;
public abstract class NbtItemStackTranslator {
/**
* Translate the item NBT to Bedrock
* @param session the client's current session
* @param itemTag the item's CompoundTag (cloned from Geyser's cached copy)
* @param mapping Geyser's item mapping
*/
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
public class ChestItem extends BlockItem {
public ChestItem(String javaIdentifier, Builder builder) {
super(javaIdentifier, builder);
}
/**
* Translate the item NBT to Java.
* @param itemTag the item's CompoundTag
* @param mapping Geyser's item mapping
*/
public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
@Override
public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) {
super.translateNbtToBedrock(session, tag);
// Strip the BlockEntityTag from the chests contents
// sent to the client. The client does not parse this
// or use it for anything, as this tag is fully
// server-side, so we remove it to reduce bandwidth and
// solve potential issues with very large tags.
// There was a problem in the past where this would strip
// NBT data in creative mode, however with the new server
// authoritative inventories, this is no longer a concern.
tag.remove("BlockEntityTag");
}
/**
* Gets whether this nbt translator takes in this item.
*
* @param item Geyser's item mapping
* @return if the item should be processed under this class
*/
public boolean acceptItem(Item item) {
return true;
} // TODO
}

View file

@ -77,9 +77,17 @@ public class ShulkerBoxItem extends BlockItem {
itemsList.add(boxItemTag);
}
tag.put(itemsList);
// Don't actually bother with removing the block entity tag. Too risky to translate
// if the user is on creative and messing with a shulker box
//itemTag.remove("BlockEntityTag");
// Strip the BlockEntityTag from the chests contents
// sent to the client. The client does not parse this
// or use it for anything, as this tag is fully
// server-side, so we remove it to reduce bandwidth and
// solve potential issues with very large tags.
// There was a problem in the past where this would strip
// NBT data in creative mode, however with the new server
// authoritative inventories, this is no longer a concern.
tag.remove("BlockEntityTag");
}
@Override