1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-15 04:30:29 +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
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
6 changed files with 11 additions and 64 deletions

View File

@ -5,14 +5,11 @@
package dan200.computercraft.shared.details; package dan200.computercraft.shared.details;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.platform.RegistryWrappers; import dan200.computercraft.shared.platform.RegistryWrappers;
import dan200.computercraft.shared.util.NBTUtil; import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component; 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.EnchantedBookItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -45,7 +42,9 @@ public class ItemDetails {
} }
data.put("tags", DetailHelpers.getTags(stack.getTags())); 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(); var tag = stack.getTag();
if (tag != null && tag.contains("display", Tag.TAG_COMPOUND)) { 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. * 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.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -273,15 +272,6 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
*/ */
int getBurnTime(ItemStack stack); 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 * Get the "container" item to be returned after crafting. For instance, crafting with a lava bucket should return
* an empty bucket. * 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.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe; 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"); throw new UnsupportedOperationException("Cannot interact with the world inside tests");
} }
@Nullable
@Override
public ResourceLocation getCreativeTabId(CreativeModeTab tab) {
return null;
}
@Override @Override
public RecipeIngredients getRecipeIngredients() { public RecipeIngredients getRecipeIngredients() {
throw new UnsupportedOperationException("Cannot query recipes inside tests"); throw new UnsupportedOperationException("Cannot query recipes inside tests");

View File

@ -256,12 +256,6 @@ public class PlatformHelperImpl implements PlatformHelper {
return fuel == null ? 0 : fuel; return fuel == null ? 0 : fuel;
} }
@Nullable
@Override
public ResourceLocation getCreativeTabId(CreativeModeTab tab) {
return tab.getId();
}
@Override @Override
public ItemStack getCraftingRemainingItem(ItemStack stack) { public ItemStack getCraftingRemainingItem(ItemStack stack) {
return stack.getRecipeRemainder(); return stack.getRecipeRemainder();

View File

@ -96,13 +96,18 @@ public class InventoryMethods implements GenericPeripheral {
* <p> * <p>
* The returned information contains the same information as each item in * The returned information contains the same information as each item in
* {@link #list}, as well as additional details like the display name * {@link #list}, as well as additional details like the display name
* (`displayName`), item groups (`itemGroups`), which are the creative tabs * (`displayName`), and item and item durability (`damage`, `maxDamage`, `durability`).
* an item will appear under, and item and item durability (`damage`,
* `maxDamage`, `durability`).
* <p> * <p>
* Some items include more information (such as enchantments) - it is * Some items include more information (such as enchantments) - it is
* recommended to print it out using @{textutils.serialize} or in the Lua * recommended to print it out using @{textutils.serialize} or in the Lua
* REPL, to explore what is available. * REPL, to explore what is available.
* <p>
* :::info Deprecated fields
* Older versions of CC: Tweaked exposed an {@code itemGroups} field, listing the
* creative tabs an item was available under. This information is no longer available on
* more recent versions of the game, and so this field will always be empty. Do not use this
* field in new code!
* :::
* *
* @param inventory The current inventory. * @param inventory The current inventory.
* @param slot The slot to get information about. * @param slot The slot to get information about.
@ -119,10 +124,6 @@ public class InventoryMethods implements GenericPeripheral {
* print(("%s (%s)"):format(item.displayName, item.name)) * print(("%s (%s)"):format(item.displayName, item.name))
* print(("Count: %d/%d"):format(item.count, item.maxCount)) * print(("Count: %d/%d"):format(item.count, item.maxCount))
* *
* for _, group in pairs(item.itemGroups) do
* print(("Group: %s"):format(group.displayName))
* end
*
* if item.damage then * if item.damage then
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage)) * print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
* end * end

View File

@ -38,7 +38,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
@ -52,7 +51,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.CreativeModeTabRegistry;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
import net.minecraftforge.common.ToolActions; import net.minecraftforge.common.ToolActions;
@ -258,12 +256,6 @@ public class PlatformHelperImpl implements PlatformHelper {
return ForgeHooks.getBurnTime(stack, null); return ForgeHooks.getBurnTime(stack, null);
} }
@Nullable
@Override
public ResourceLocation getCreativeTabId(CreativeModeTab tab) {
return CreativeModeTabRegistry.getName(tab);
}
@Override @Override
public ItemStack getCraftingRemainingItem(ItemStack stack) { public ItemStack getCraftingRemainingItem(ItemStack stack) {
return stack.getCraftingRemainingItem(); return stack.getCraftingRemainingItem();