1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-01 06:03:00 +00:00

Deprecate itemGroups field

Since 1.19.3, this was only populated when the player opened the
creative menu, and so was useless in survival or multi-player
worlds.

Rather than removing the field entirely (🦑 backwards compatibility), we
replace it with the empty list. We also remove it from the docs, and add
a note explaining what the field used to do.

Closes #1285, albeit in the least satisfactory way possible.
This commit is contained in:
Jonathan Coates
2023-06-08 20:32:50 +01:00
parent cba207d62d
commit 68ef9f717b
6 changed files with 11 additions and 64 deletions

View File

@@ -5,14 +5,11 @@
package dan200.computercraft.shared.details;
import com.google.gson.JsonParseException;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.platform.RegistryWrappers;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@@ -45,7 +42,9 @@ public class ItemDetails {
}
data.put("tags", DetailHelpers.getTags(stack.getTags()));
data.put("itemGroups", getItemGroups(stack));
// Include deprecated itemGroups field
data.put("itemGroups", List.of());
var tag = stack.getTag();
if (tag != null && tag.contains("display", Tag.TAG_COMPOUND)) {
@@ -84,27 +83,6 @@ public class ItemDetails {
}
}
/**
* Retrieve all item groups an item stack pertains to.
*
* @param stack Stack to analyse
* @return A filled list that contains pairs of item group IDs and their display names.
*/
private static List<Map<String, Object>> getItemGroups(ItemStack stack) {
return CreativeModeTabs.allTabs().stream()
.filter(x -> x.shouldDisplay() && x.getType() == CreativeModeTab.Type.CATEGORY && x.contains(stack))
.map(group -> {
Map<String, Object> groupData = new HashMap<>(2);
var id = PlatformHelper.get().getCreativeTabId(group);
if (id != null) groupData.put("id", id.toString());
groupData.put("displayName", group.getDisplayName().getString());
return groupData;
})
.toList();
}
/**
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
*

View File

@@ -33,7 +33,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@@ -273,15 +272,6 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
*/
int getBurnTime(ItemStack stack);
/**
* Get a unique identifier for this creative tab.
*
* @param tab The tab to get
* @return The unique identifier, or {@code null} if not available.
*/
@Nullable
ResourceLocation getCreativeTabId(CreativeModeTab tab);
/**
* Get the "container" item to be returned after crafting. For instance, crafting with a lava bucket should return
* an empty bucket.

View File

@@ -36,7 +36,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
@@ -165,13 +164,6 @@ public class TestPlatformHelper extends AbstractComputerCraftAPI implements Plat
throw new UnsupportedOperationException("Cannot interact with the world inside tests");
}
@Nullable
@Override
public ResourceLocation getCreativeTabId(CreativeModeTab tab) {
return null;
}
@Override
public RecipeIngredients getRecipeIngredients() {
throw new UnsupportedOperationException("Cannot query recipes inside tests");