From 9e16817e474f043c531bbd55db94e7a24ec791c4 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Mon, 4 Apr 2022 13:08:43 +0200 Subject: [PATCH] Added ingredient to make an oak drawer with non minecraft wood closes #23 --- build.gradle | 2 +- .../recipes/oak_drawer_alternate_x1.json | 37 ++++++++ .../recipes/oak_drawer_alternate_x2.json | 37 ++++++++ .../recipes/oak_drawer_alternate_x4.json | 37 ++++++++ .../functionalstorage/FunctionalStorage.java | 84 +++++++++-------- .../functionalstorage/block/DrawerBlock.java | 26 ++++++ .../recipe/DrawerlessWoodIngredient.java | 90 +++++++++++++++++++ 7 files changed, 275 insertions(+), 38 deletions(-) create mode 100644 src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x1.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x2.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x4.json create mode 100644 src/main/java/com/buuz135/functionalstorage/recipe/DrawerlessWoodIngredient.java diff --git a/build.gradle b/build.gradle index e537db6..29badda 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ minecraft { property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" - args '--mod', 'functionalstorage', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + args '--mod', 'functionalstorage,titanium', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') mods { functionalstorage { diff --git a/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x1.json b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x1.json new file mode 100644 index 0000000..bd4f511 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x1.json @@ -0,0 +1,37 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:oak_1", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "PPP", + "PCP", + "PPP" + ], + "key": { + "P": { + "type": "functionalstorage:woodless" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:oak_1" + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x2.json b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x2.json new file mode 100644 index 0000000..2f4b6cc --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x2.json @@ -0,0 +1,37 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:oak_2", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "PCP", + "PPP", + "PCP" + ], + "key": { + "P": { + "type": "functionalstorage:woodless" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:oak_2" + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x4.json b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x4.json new file mode 100644 index 0000000..7bdacf7 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/oak_drawer_alternate_x4.json @@ -0,0 +1,37 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:oak_4", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "CPC", + "PPP", + "CPC" + ], + "key": { + "P": { + "type": "functionalstorage:woodless" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:oak_4" + } + } + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index 0692bdf..ed5c8d4 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -20,6 +20,7 @@ import com.buuz135.functionalstorage.item.LinkingToolItem; import com.buuz135.functionalstorage.item.StorageUpgradeItem; import com.buuz135.functionalstorage.item.UpgradeItem; import com.buuz135.functionalstorage.network.EnderDrawerSyncMessage; +import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; import com.buuz135.functionalstorage.util.*; import com.hrznstudio.titanium.block.BasicBlock; import com.hrznstudio.titanium.block.BasicTileBlock; @@ -43,6 +44,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.api.distmarker.Dist; @@ -53,7 +55,9 @@ import net.minecraftforge.client.event.RenderTooltipEvent; import net.minecraftforge.client.model.generators.BlockModelProvider; import net.minecraftforge.client.model.generators.ItemModelProvider; import net.minecraftforge.common.Tags; +import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.util.NonNullLazy; +import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.Mod; @@ -131,6 +135,9 @@ public class FunctionalStorage extends ModuleController { } } }).subscribe(); + EventManager.modGeneric(RegistryEvent.Register.class, RecipeSerializer.class).process(register -> { + CraftingHelper.register(DrawerlessWoodIngredient.NAME, DrawerlessWoodIngredient.SERIALIZER); + }).subscribe(); } @@ -265,9 +272,46 @@ public class FunctionalStorage extends ModuleController { .isPresent()) .collect(Collectors.toList()) ); - event.getGenerator().addProvider(new BlockItemModelGeneratorProvider(event.getGenerator(), MOD_ID, blocksToProcess)); - event.getGenerator().addProvider(new FunctionalStorageBlockstateProvider(event.getGenerator(), event.getExistingFileHelper(), blocksToProcess)); - event.getGenerator().addProvider(new TitaniumLootTableProvider(event.getGenerator(), blocksToProcess)); + if (false){ + event.getGenerator().addProvider(new BlockItemModelGeneratorProvider(event.getGenerator(), MOD_ID, blocksToProcess)); + event.getGenerator().addProvider(new FunctionalStorageBlockstateProvider(event.getGenerator(), event.getExistingFileHelper(), blocksToProcess)); + event.getGenerator().addProvider(new TitaniumLootTableProvider(event.getGenerator(), blocksToProcess)); + + event.getGenerator().addProvider(new FunctionalStorageItemTagsProvider(event.getGenerator(), new BlockTagsProvider(event.getGenerator()), MOD_ID, event.getExistingFileHelper())); + event.getGenerator().addProvider(new FunctionalStorageLangProvider(event.getGenerator(), MOD_ID, "en_us")); + event.getGenerator().addProvider(new FunctionalStorageBlockTagsProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper())); + event.getGenerator().addProvider(new ItemModelProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper()) { + @Override + protected void registerModels() { + for (StorageUpgradeItem.StorageTier storageTier : STORAGE_UPGRADES.keySet()) { + item(STORAGE_UPGRADES.get(storageTier).get()); + } + item(COLLECTOR_UPGRADE.get()); + item(PULLING_UPGRADE.get()); + item(PUSHING_UPGRADE.get()); + item(VOID_UPGRADE.get()); + } + + private void item(Item item) { + singleTexture(item.getRegistryName().getPath(), new ResourceLocation("minecraft:item/generated"), "layer0", new ResourceLocation(MOD_ID, "items/" + item.getRegistryName().getPath())); + } + }); + event.getGenerator().addProvider(new BlockModelProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper()) { + @Override + protected void registerModels() { + for (DrawerType value : DrawerType.values()) { + for (RegistryObject blockRegistryObject : DRAWER_TYPES.get(value).stream().map(Pair::getLeft).collect(Collectors.toList())) { + withExistingParent(blockRegistryObject.get().getRegistryName().getPath() + "_locked", modLoc(blockRegistryObject.get().getRegistryName().getPath())) + .texture("lock_icon", modLoc("blocks/lock")); + } + } + withExistingParent(COMPACTING_DRAWER.getLeft().get().getRegistryName().getPath() + "_locked", modLoc(COMPACTING_DRAWER.getLeft().get().getRegistryName().getPath())) + .texture("lock_icon", modLoc("blocks/lock")); + withExistingParent(ENDER_DRAWER.getLeft().get().getRegistryName().getPath() + "_locked", modLoc(ENDER_DRAWER.getLeft().get().getRegistryName().getPath())) + .texture("lock_icon", modLoc("blocks/lock")); + } + }); + } event.getGenerator().addProvider(new TitaniumRecipeProvider(event.getGenerator()) { @Override public void register(Consumer consumer) { @@ -363,39 +407,5 @@ public class FunctionalStorage extends ModuleController { .save(consumer); } }); - event.getGenerator().addProvider(new FunctionalStorageItemTagsProvider(event.getGenerator(), new BlockTagsProvider(event.getGenerator()), MOD_ID, event.getExistingFileHelper())); - event.getGenerator().addProvider(new FunctionalStorageLangProvider(event.getGenerator(), MOD_ID, "en_us")); - event.getGenerator().addProvider(new FunctionalStorageBlockTagsProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper())); - event.getGenerator().addProvider(new ItemModelProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper()) { - @Override - protected void registerModels() { - for (StorageUpgradeItem.StorageTier storageTier : STORAGE_UPGRADES.keySet()) { - item(STORAGE_UPGRADES.get(storageTier).get()); - } - item(COLLECTOR_UPGRADE.get()); - item(PULLING_UPGRADE.get()); - item(PUSHING_UPGRADE.get()); - item(VOID_UPGRADE.get()); - } - - private void item(Item item) { - singleTexture(item.getRegistryName().getPath(), new ResourceLocation("minecraft:item/generated"), "layer0", new ResourceLocation(MOD_ID, "items/" + item.getRegistryName().getPath())); - } - }); - event.getGenerator().addProvider(new BlockModelProvider(event.getGenerator(), MOD_ID, event.getExistingFileHelper()) { - @Override - protected void registerModels() { - for (DrawerType value : DrawerType.values()) { - for (RegistryObject blockRegistryObject : DRAWER_TYPES.get(value).stream().map(Pair::getLeft).collect(Collectors.toList())) { - withExistingParent(blockRegistryObject.get().getRegistryName().getPath() + "_locked", modLoc(blockRegistryObject.get().getRegistryName().getPath())) - .texture("lock_icon", modLoc("blocks/lock")); - } - } - withExistingParent(COMPACTING_DRAWER.getLeft().get().getRegistryName().getPath() + "_locked", modLoc(COMPACTING_DRAWER.getLeft().get().getRegistryName().getPath())) - .texture("lock_icon", modLoc("blocks/lock")); - withExistingParent(ENDER_DRAWER.getLeft().get().getRegistryName().getPath() + "_locked", modLoc(ENDER_DRAWER.getLeft().get().getRegistryName().getPath())) - .texture("lock_icon", modLoc("blocks/lock")); - } - }); } } diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 6648ff4..c0a9fdb 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -5,6 +5,7 @@ import com.buuz135.functionalstorage.block.tile.DrawerControllerTile; import com.buuz135.functionalstorage.block.tile.DrawerTile; import com.buuz135.functionalstorage.inventory.item.DrawerCapabilityProvider; import com.buuz135.functionalstorage.item.LinkingToolItem; +import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; import com.buuz135.functionalstorage.util.IWoodType; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; @@ -22,6 +23,7 @@ import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; @@ -260,6 +262,14 @@ public class DrawerBlock extends RotatableBlock { .define('P', woodType.getPlanks()) .define('C', Tags.Items.CHESTS_WOODEN) .save(consumer); + if (woodType.getName().equals("oak")){ + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .setName(new ResourceLocation(FunctionalStorage.MOD_ID, "oak_drawer_alternate_x1")) + .pattern("PPP").pattern("PCP").pattern("PPP") + .define('P', new DrawerlessWoodIngredient()) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + } } if (type == FunctionalStorage.DrawerType.X_2){ TitaniumShapedRecipeBuilder.shapedRecipe(this) @@ -267,6 +277,14 @@ public class DrawerBlock extends RotatableBlock { .define('P', woodType.getPlanks()) .define('C', Tags.Items.CHESTS_WOODEN) .save(consumer); + if (woodType.getName().equals("oak")){ + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .setName(new ResourceLocation(FunctionalStorage.MOD_ID, "oak_drawer_alternate_x2")) + .pattern("PCP").pattern("PPP").pattern("PCP") + .define('P', new DrawerlessWoodIngredient()) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + } } if (type == FunctionalStorage.DrawerType.X_4){ TitaniumShapedRecipeBuilder.shapedRecipe(this) @@ -274,6 +292,14 @@ public class DrawerBlock extends RotatableBlock { .define('P', woodType.getPlanks()) .define('C', Tags.Items.CHESTS_WOODEN) .save(consumer); + if (woodType.getName().equals("oak")){ + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .setName(new ResourceLocation(FunctionalStorage.MOD_ID, "oak_drawer_alternate_x4")) + .pattern("CPC").pattern("PPP").pattern("CPC") + .define('P', new DrawerlessWoodIngredient()) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + } } } diff --git a/src/main/java/com/buuz135/functionalstorage/recipe/DrawerlessWoodIngredient.java b/src/main/java/com/buuz135/functionalstorage/recipe/DrawerlessWoodIngredient.java new file mode 100644 index 0000000..4cc80de --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/recipe/DrawerlessWoodIngredient.java @@ -0,0 +1,90 @@ +package com.buuz135.functionalstorage.recipe; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.hrznstudio.titanium.util.TagUtil; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraftforge.common.crafting.IIngredientSerializer; +import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Array; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.buuz135.functionalstorage.FunctionalStorage.MOD_ID; + +public class DrawerlessWoodIngredient extends Ingredient { + + public static WoodlessIngredientSerializer SERIALIZER = new WoodlessIngredientSerializer(); + public static ResourceLocation NAME = new ResourceLocation(MOD_ID, "woodless"); + + private List woodless; + + public DrawerlessWoodIngredient() { + super(Stream.empty()); + } + + @Override + public ItemStack[] getItems() { + return getWoods().stream().map(ItemStack::new).toArray(ItemStack[]::new); + } + + @Override + public boolean test(@Nullable ItemStack stack) { + return getWoods().contains(stack.getItem()); + } + + @Override + public IIngredientSerializer getSerializer() { + return SERIALIZER; + } + + private List getWoods(){ + if (woodless == null){ + woodless = TagUtil.getAllEntries(ForgeRegistries.ITEMS, ItemTags.PLANKS).stream().filter(item -> !item.getRegistryName().getNamespace().equalsIgnoreCase("minecraft")).collect(Collectors.toList()); + if (woodless.isEmpty()){ + woodless.add(Items.OAK_PLANKS); + } + } + return woodless; + } + + @Override + public JsonElement toJson() { + JsonObject element = new JsonObject(); + element.addProperty("type", NAME.toString()); + return element; + } + + @Override + protected void invalidate() { + super.invalidate(); + this.woodless = null; + } + + public static class WoodlessIngredientSerializer implements IIngredientSerializer{ + + @Override + public Ingredient parse(FriendlyByteBuf buffer) { + return new DrawerlessWoodIngredient(); + } + + @Override + public Ingredient parse(JsonObject json) { + return new DrawerlessWoodIngredient(); + } + + @Override + public void write(FriendlyByteBuf buffer, Ingredient ingredient) { + + } + } +}