1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-14 04:00:30 +00:00

Abstract our our use of Forge's tags

This commit is contained in:
Jonathan Coates 2022-11-09 10:59:05 +00:00
parent 55494b7671
commit 22729f6f16
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
8 changed files with 212 additions and 90 deletions

View File

@ -2,7 +2,7 @@
"parent": "minecraft:recipes/root",
"criteria": {
"has_components": {
"conditions": {"items": [{"items": ["minecraft:redstone"]}, {"items": ["minecraft:gold_ingot"]}]},
"conditions": {"items": [{"tag": "forge:dusts/redstone"}, {"tag": "forge:ingots/gold"}]},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {

View File

@ -13,23 +13,30 @@ import dan200.computercraft.core.util.Colour;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.platform.RecipeIngredients;
import dan200.computercraft.shared.platform.Registries;
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.common.Tags;
import net.minecraft.world.level.block.Blocks;
import javax.annotation.Nonnull;
import java.util.Locale;
@ -39,6 +46,7 @@ import static dan200.computercraft.api.ComputerCraftTags.Items.COMPUTER;
import static dan200.computercraft.api.ComputerCraftTags.Items.WIRED_MODEM;
class RecipeGenerator extends RecipeProvider {
private final RecipeIngredients ingredients = PlatformHelper.get().getRecipeIngredients();
private final TurtleUpgradeDataProvider turtleUpgrades;
private final PocketUpgradeDataProvider pocketUpgrades;
@ -72,8 +80,8 @@ class RecipeGenerator extends RecipeProvider {
for (var colour : Colour.VALUES) {
ShapelessRecipeBuilder
.shapeless(ModRegistry.Items.DISK.get())
.requires(Tags.Items.DUSTS_REDSTONE)
.requires(net.minecraft.world.item.Items.PAPER)
.requires(ingredients.redstone())
.requires(Items.PAPER)
.requires(DyeItem.byColor(ofColour(colour)))
.group("computercraft:disk")
.unlockedBy("has_drive", inventoryChange(ModRegistry.Blocks.DISK_DRIVE.get()))
@ -156,8 +164,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern(" # ")
.pattern("#R#")
.pattern(" # ")
.define('#', Tags.Items.STONE)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('#', ingredients.stone())
.define('R', ingredients.redstone())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.unlockedBy("has_modem", inventoryChange(WIRED_MODEM))
.save(add);
@ -167,10 +175,10 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("#G#")
.define('#', Tags.Items.STONE)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('G', Tags.Items.GLASS_PANES)
.unlockedBy("has_redstone", inventoryChange(Tags.Items.DUSTS_REDSTONE))
.define('#', ingredients.stone())
.define('R', ingredients.redstone())
.define('G', ingredients.glassPane())
.unlockedBy("has_redstone", inventoryChange(itemPredicate(ingredients.redstone())))
.save(add);
ShapedRecipeBuilder
@ -178,10 +186,10 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("#G#")
.define('#', Tags.Items.INGOTS_GOLD)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('G', Tags.Items.GLASS_PANES)
.unlockedBy("has_components", inventoryChange(net.minecraft.world.item.Items.REDSTONE, net.minecraft.world.item.Items.GOLD_INGOT))
.define('#', ingredients.goldIngot())
.define('R', ingredients.redstone())
.define('G', ingredients.glassPane())
.unlockedBy("has_components", inventoryChange(itemPredicate(ingredients.redstone()), itemPredicate(ingredients.goldIngot())))
.save(add);
ShapedRecipeBuilder
@ -189,9 +197,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#C#")
.pattern("# #")
.define('#', Tags.Items.INGOTS_GOLD)
.define('#', ingredients.goldIngot())
.define('C', ModRegistry.Items.COMPUTER_ADVANCED.get())
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.COMPUTER_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.save(
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
new ResourceLocation(ComputerCraft.MOD_ID, "computer_advanced_upgrade")
@ -202,10 +210,10 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("#G#")
.define('#', Tags.Items.INGOTS_GOLD)
.define('R', net.minecraft.world.level.block.Blocks.COMMAND_BLOCK)
.define('G', Tags.Items.GLASS_PANES)
.unlockedBy("has_components", inventoryChange(net.minecraft.world.level.block.Blocks.COMMAND_BLOCK))
.define('#', ingredients.goldIngot())
.define('R', Blocks.COMMAND_BLOCK)
.define('G', ingredients.glassPane())
.unlockedBy("has_components", inventoryChange(Blocks.COMMAND_BLOCK))
.save(add);
ShapedRecipeBuilder
@ -213,9 +221,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#C#")
.pattern("#I#")
.define('#', Tags.Items.INGOTS_IRON)
.define('#', ingredients.ironIngot())
.define('C', ModRegistry.Items.COMPUTER_NORMAL.get())
.define('I', Tags.Items.CHESTS_WOODEN)
.define('I', ingredients.woodenChest())
.unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get()))
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.NORMAL)));
@ -224,9 +232,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#C#")
.pattern("#I#")
.define('#', Tags.Items.INGOTS_GOLD)
.define('#', ingredients.goldIngot())
.define('C', ModRegistry.Items.COMPUTER_ADVANCED.get())
.define('I', Tags.Items.CHESTS_WOODEN)
.define('I', ingredients.woodenChest())
.unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get()))
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)));
@ -235,10 +243,10 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#C#")
.pattern(" B ")
.define('#', Tags.Items.INGOTS_GOLD)
.define('#', ingredients.goldIngot())
.define('C', ModRegistry.Items.COMPUTER_ADVANCED.get())
.define('B', Tags.Items.STORAGE_BLOCKS_GOLD)
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.TURTLE_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
.define('B', ingredients.goldBlock())
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.TURTLE_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.save(
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
new ResourceLocation(ComputerCraft.MOD_ID, "turtle_advanced_upgrade")
@ -249,8 +257,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("#R#")
.define('#', Tags.Items.STONE)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('#', ingredients.stone())
.define('R', ingredients.redstone())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -259,8 +267,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#G#")
.pattern("###")
.define('#', Tags.Items.STONE)
.define('G', Tags.Items.GLASS_PANES)
.define('#', ingredients.stone())
.define('G', ingredients.glassPane())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -269,8 +277,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#G#")
.pattern("###")
.define('#', Tags.Items.INGOTS_GOLD)
.define('G', Tags.Items.GLASS_PANES)
.define('#', ingredients.goldIngot())
.define('G', ingredients.glassPane())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -279,11 +287,11 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#A#")
.pattern("#G#")
.define('#', Tags.Items.STONE)
.define('A', net.minecraft.world.item.Items.GOLDEN_APPLE)
.define('G', Tags.Items.GLASS_PANES)
.define('#', ingredients.stone())
.define('A', Items.GOLDEN_APPLE)
.define('G', ingredients.glassPane())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.unlockedBy("has_apple", inventoryChange(net.minecraft.world.item.Items.GOLDEN_APPLE))
.unlockedBy("has_apple", inventoryChange(Items.GOLDEN_APPLE))
.save(add);
ShapedRecipeBuilder
@ -291,11 +299,11 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#A#")
.pattern("#G#")
.define('#', Tags.Items.INGOTS_GOLD)
.define('A', net.minecraft.world.item.Items.GOLDEN_APPLE)
.define('G', Tags.Items.GLASS_PANES)
.define('#', ingredients.goldIngot())
.define('A', Items.GOLDEN_APPLE)
.define('G', ingredients.glassPane())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.unlockedBy("has_apple", inventoryChange(net.minecraft.world.item.Items.GOLDEN_APPLE))
.unlockedBy("has_apple", inventoryChange(Items.GOLDEN_APPLE))
.save(add);
ShapedRecipeBuilder
@ -303,9 +311,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#C#")
.pattern("# #")
.define('#', Tags.Items.INGOTS_GOLD)
.define('#', ingredients.goldIngot())
.define('C', ModRegistry.Items.POCKET_COMPUTER_NORMAL.get())
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.save(
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
new ResourceLocation(ComputerCraft.MOD_ID, "pocket_computer_advanced_upgrade")
@ -316,9 +324,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("#D#")
.define('#', Tags.Items.STONE)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('D', Tags.Items.DYES)
.define('#', ingredients.stone())
.define('R', ingredients.redstone())
.define('D', ingredients.dye())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -327,9 +335,9 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#N#")
.pattern("#R#")
.define('#', Tags.Items.STONE)
.define('N', net.minecraft.world.level.block.Blocks.NOTE_BLOCK)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('#', ingredients.stone())
.define('N', Blocks.NOTE_BLOCK)
.define('R', ingredients.redstone())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -338,8 +346,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#R#")
.pattern("###")
.define('#', Tags.Items.STONE)
.define('R', Tags.Items.DUSTS_REDSTONE)
.define('#', ingredients.stone())
.define('R', ingredients.redstone())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.unlockedBy("has_cable", inventoryChange(ModRegistry.Items.CABLE.get()))
.save(add);
@ -360,8 +368,8 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#E#")
.pattern("###")
.define('#', Tags.Items.STONE)
.define('E', Tags.Items.ENDER_PEARLS)
.define('#', ingredients.stone())
.define('E', ingredients.enderPearl())
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.save(add);
@ -370,15 +378,15 @@ class RecipeGenerator extends RecipeProvider {
.pattern("###")
.pattern("#E#")
.pattern("###")
.define('#', Tags.Items.INGOTS_GOLD)
.define('E', net.minecraft.world.item.Items.ENDER_EYE)
.define('#', ingredients.goldIngot())
.define('E', Items.ENDER_EYE)
.unlockedBy("has_computer", inventoryChange(COMPUTER))
.unlockedBy("has_wireless", inventoryChange(ModRegistry.Blocks.WIRELESS_MODEM_NORMAL.get()))
.save(add);
ShapelessRecipeBuilder
.shapeless(net.minecraft.world.item.Items.PLAYER_HEAD)
.requires(Tags.Items.HEADS)
.shapeless(Items.PLAYER_HEAD)
.requires(ingredients.head())
.requires(ModRegistry.Items.MONITOR_NORMAL.get())
.unlockedBy("has_monitor", inventoryChange(ModRegistry.Items.MONITOR_NORMAL.get()))
.save(
@ -388,8 +396,8 @@ class RecipeGenerator extends RecipeProvider {
);
ShapelessRecipeBuilder
.shapeless(net.minecraft.world.item.Items.PLAYER_HEAD)
.requires(Tags.Items.HEADS)
.shapeless(Items.PLAYER_HEAD)
.requires(ingredients.head())
.requires(ModRegistry.Items.COMPUTER_ADVANCED.get())
.unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_ADVANCED.get()))
.save(
@ -401,15 +409,15 @@ class RecipeGenerator extends RecipeProvider {
ShapelessRecipeBuilder
.shapeless(ModRegistry.Items.PRINTED_PAGES.get())
.requires(ModRegistry.Items.PRINTED_PAGE.get(), 2)
.requires(Tags.Items.STRING)
.requires(ingredients.string())
.unlockedBy("has_printer", inventoryChange(ModRegistry.Blocks.PRINTER.get()))
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get(), add));
ShapelessRecipeBuilder
.shapeless(ModRegistry.Items.PRINTED_BOOK.get())
.requires(Tags.Items.LEATHER)
.requires(ingredients.leather())
.requires(ModRegistry.Items.PRINTED_PAGE.get(), 1)
.requires(Tags.Items.STRING)
.requires(ingredients.string())
.unlockedBy("has_printer", inventoryChange(ModRegistry.Blocks.PRINTER.get()))
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get(), add));
}
@ -438,6 +446,19 @@ class RecipeGenerator extends RecipeProvider {
return ItemPredicate.Builder.item().of(item).build();
}
private static ItemPredicate itemPredicate(Ingredient ingredient) {
var json = ingredient.toJson();
if (!(json instanceof JsonObject object)) throw new IllegalStateException("Unknown ingredient " + json);
if (object.has("item")) {
return itemPredicate(ShapedRecipe.itemFromJson(object));
} else if (object.has("tag")) {
return itemPredicate(TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(GsonHelper.getAsString(object, "tag"))));
} else {
throw new IllegalArgumentException("Unknown ingredient " + json);
}
}
private static CompoundTag playerHead(String name, String uuid) {
var owner = new CompoundTag();
owner.putString("Name", name);

View File

@ -8,6 +8,7 @@ package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.core.util.Colour;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.media.items.ItemDisk;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.resources.ResourceLocation;
@ -15,15 +16,18 @@ import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.Tags;
import javax.annotation.Nonnull;
public class DiskRecipe extends CustomRecipe {
private final Ingredient redstone;
public DiskRecipe(ResourceLocation id) {
super(id);
redstone = PlatformHelper.get().getRecipeIngredients().redstone();
}
@Override
@ -38,7 +42,7 @@ public class DiskRecipe extends CustomRecipe {
if (stack.getItem() == Items.PAPER) {
if (paperFound) return false;
paperFound = true;
} else if (stack.is(Tags.Items.DUSTS_REDSTONE)) {
} else if (redstone.test(stack)) {
if (redstoneFound) return false;
redstoneFound = true;
} else if (ColourUtils.getStackColour(stack) == null) {
@ -60,7 +64,7 @@ public class DiskRecipe extends CustomRecipe {
if (stack.isEmpty()) continue;
if (stack.getItem() != Items.PAPER && !stack.is(Tags.Items.DUSTS_REDSTONE)) {
if (stack.getItem() != Items.PAPER && !redstone.test(stack)) {
var dye = ColourUtils.getStackColour(stack);
if (dye != null) tracker.addColour(dye);
}

View File

@ -7,20 +7,28 @@ package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.media.items.ItemPrintout;
import dan200.computercraft.shared.platform.PlatformHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.Tags;
import javax.annotation.Nonnull;
public final class PrintoutRecipe extends CustomRecipe {
private final Ingredient leather;
private final Ingredient string;
public PrintoutRecipe(ResourceLocation id) {
super(id);
var ingredients = PlatformHelper.get().getRecipeIngredients();
leather = ingredients.leather();
string = ingredients.string();
}
@Override
@ -66,9 +74,9 @@ public final class PrintoutRecipe extends CustomRecipe {
printouts[numPrintouts] = stack;
numPages++;
numPrintouts++;
} else if (stack.is(Tags.Items.STRING) && !stringFound) {
} else if (string.test(stack) && !stringFound) {
stringFound = true;
} else if (stack.is(Tags.Items.LEATHER) && !leatherFound) {
} else if (leather.test(stack) && !leatherFound) {
leatherFound = true;
} else {
return ItemStack.EMPTY;

View File

@ -20,12 +20,15 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Container;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.WorldlyContainer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -37,6 +40,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@ -216,4 +220,19 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
*/
@Deprecated(forRemoval = true)
IItemHandlerModifiable wrapContainerToItemHandler(Container container);
/**
* Get the {@link RecipeIngredients} for this loader.
*
* @return The loader-specific recipe ingredients.
*/
RecipeIngredients getRecipeIngredients();
/**
* Get a list of tags representing each Minecraft dye. This should follow the same order as {@linkplain DyeColor
* Minecraft's dyes}, starting with white and ending with black.
*
* @return A list of tags.
*/
List<TagKey<Item>> getDyeTags();
}

View File

@ -26,13 +26,16 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Container;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.WorldlyContainerHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -40,6 +43,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.extensions.IForgeMenuType;
@ -57,6 +61,7 @@ import net.minecraftforge.registries.RegistryObject;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
@ -191,6 +196,46 @@ public class PlatformHelperImpl implements PlatformHelper {
return item.getShareTag();
}
@Override
public RecipeIngredients getRecipeIngredients() {
return new RecipeIngredients(
Ingredient.of(Tags.Items.DUSTS_REDSTONE),
Ingredient.of(Tags.Items.STRING),
Ingredient.of(Tags.Items.LEATHER),
Ingredient.of(Tags.Items.STONE),
Ingredient.of(Tags.Items.GLASS_PANES),
Ingredient.of(Tags.Items.INGOTS_GOLD),
Ingredient.of(Tags.Items.STORAGE_BLOCKS_GOLD),
Ingredient.of(Tags.Items.INGOTS_IRON),
Ingredient.of(Tags.Items.HEADS),
Ingredient.of(Tags.Items.DYES),
Ingredient.of(Tags.Items.ENDER_PEARLS),
Ingredient.of(Tags.Items.CHESTS_WOODEN)
);
}
@Override
public List<TagKey<Item>> getDyeTags() {
return List.of(
Tags.Items.DYES_WHITE,
Tags.Items.DYES_ORANGE,
Tags.Items.DYES_MAGENTA,
Tags.Items.DYES_LIGHT_BLUE,
Tags.Items.DYES_YELLOW,
Tags.Items.DYES_LIME,
Tags.Items.DYES_PINK,
Tags.Items.DYES_GRAY,
Tags.Items.DYES_LIGHT_GRAY,
Tags.Items.DYES_CYAN,
Tags.Items.DYES_PURPLE,
Tags.Items.DYES_BLUE,
Tags.Items.DYES_BROWN,
Tags.Items.DYES_GREEN,
Tags.Items.DYES_RED,
Tags.Items.DYES_BLACK
);
}
private record RegistryWrapperImpl<T>(
ResourceLocation name, ForgeRegistry<T> registry
) implements Registries.RegistryWrapper<T> {

View File

@ -0,0 +1,41 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.platform;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
/**
* Loader-specific recipe ingredients. These may either be tags or items, depending on which mod loader we're using.
*
* @param redstone All {@link Items#REDSTONE} items.
* @param string All {@link Items#STRING} items.
* @param leather All {@link Items#LEATHER} items.
* @param stone All {@link Items#STONE} items.
* @param glassPane All {@link Items#GLASS_PANE} items.
* @param goldIngot All {@link Items#GOLD_INGOT} items.
* @param goldBlock All {@link Items#GOLD_BLOCK} items.
* @param ironIngot All {@link Items#IRON_INGOT} items.
* @param head All types of skull (player heads, mob skulls, etc...).
* @param dye All dye items.
* @param enderPearl All {@link Items#ENDER_PEARL} items.
* @param woodenChest All wooden chests (both normal and trapped chests).
*/
public record RecipeIngredients(
Ingredient redstone,
Ingredient string,
Ingredient leather,
Ingredient stone,
Ingredient glassPane,
Ingredient goldIngot,
Ingredient goldBlock,
Ingredient ironIngot,
Ingredient head,
Ingredient dye,
Ingredient enderPearl,
Ingredient woodenChest
) {
}

View File

@ -5,32 +5,16 @@
*/
package dan200.computercraft.shared.util;
import dan200.computercraft.shared.platform.PlatformHelper;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.Tags;
import java.util.List;
public final class ColourUtils {
@SuppressWarnings({ "unchecked", "rawtypes" })
private static final TagKey<Item>[] DYES = new TagKey[]{
Tags.Items.DYES_WHITE,
Tags.Items.DYES_ORANGE,
Tags.Items.DYES_MAGENTA,
Tags.Items.DYES_LIGHT_BLUE,
Tags.Items.DYES_YELLOW,
Tags.Items.DYES_LIME,
Tags.Items.DYES_PINK,
Tags.Items.DYES_GRAY,
Tags.Items.DYES_LIGHT_GRAY,
Tags.Items.DYES_CYAN,
Tags.Items.DYES_PURPLE,
Tags.Items.DYES_BLUE,
Tags.Items.DYES_BROWN,
Tags.Items.DYES_GREEN,
Tags.Items.DYES_RED,
Tags.Items.DYES_BLACK,
};
private static final List<TagKey<Item>> DYES = PlatformHelper.get().getDyeTags();
private ColourUtils() {
}
@ -38,8 +22,8 @@ public final class ColourUtils {
public static DyeColor getStackColour(ItemStack stack) {
if (stack.isEmpty()) return null;
for (var i = 0; i < DYES.length; i++) {
var dye = DYES[i];
for (var i = 0; i < DYES.size(); i++) {
var dye = DYES.get(i);
if (stack.is(dye)) return DyeColor.byId(i);
}