From c409370f46ea6fce2a417a803a31c29684adfbed Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:52:25 +0200 Subject: [PATCH] feat: Add Blank Scroll to re-add bound scroll functionality #847 --- .../waystones/models/item/blank_scroll.json | 6 +++ .../recipes/decorations/blank_scroll.json | 32 ++++++++++++ .../data/waystones/recipe/blank_scroll.json | 17 +++++++ .../data/waystones/tags/item/scrolls.json | 3 +- .../waystones/block/WaystoneBlockBase.java | 10 ++++ .../mods/waystones/item/BlankScrollItem.java | 47 ++++++++++++++++++ .../blay09/mods/waystones/item/ModItems.java | 9 ++-- .../assets/waystones/lang/en_us.json | 2 + .../waystones/textures/item/blank_scroll.png | Bin 0 -> 5416 bytes .../waystones/datagen/ModItemTagProvider.java | 2 +- .../waystones/datagen/ModModelProvider.java | 1 + .../waystones/datagen/ModRecipeProvider.java | 9 ++++ 12 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 common/src/generated/resources/assets/waystones/models/item/blank_scroll.json create mode 100644 common/src/generated/resources/data/waystones/advancement/recipes/decorations/blank_scroll.json create mode 100644 common/src/generated/resources/data/waystones/recipe/blank_scroll.json create mode 100644 common/src/main/java/net/blay09/mods/waystones/item/BlankScrollItem.java create mode 100644 common/src/main/resources/assets/waystones/textures/item/blank_scroll.png diff --git a/common/src/generated/resources/assets/waystones/models/item/blank_scroll.json b/common/src/generated/resources/assets/waystones/models/item/blank_scroll.json new file mode 100644 index 00000000..eb56b216 --- /dev/null +++ b/common/src/generated/resources/assets/waystones/models/item/blank_scroll.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/handheld", + "textures": { + "layer0": "waystones:item/blank_scroll" + } +} \ No newline at end of file diff --git a/common/src/generated/resources/data/waystones/advancement/recipes/decorations/blank_scroll.json b/common/src/generated/resources/data/waystones/advancement/recipes/decorations/blank_scroll.json new file mode 100644 index 00000000..a5ecac2f --- /dev/null +++ b/common/src/generated/resources/data/waystones/advancement/recipes/decorations/blank_scroll.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_paper": { + "conditions": { + "items": [ + { + "items": "minecraft:paper" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "waystones:blank_scroll" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_paper" + ] + ], + "rewards": { + "recipes": [ + "waystones:blank_scroll" + ] + } +} \ No newline at end of file diff --git a/common/src/generated/resources/data/waystones/recipe/blank_scroll.json b/common/src/generated/resources/data/waystones/recipe/blank_scroll.json new file mode 100644 index 00000000..bed57446 --- /dev/null +++ b/common/src/generated/resources/data/waystones/recipe/blank_scroll.json @@ -0,0 +1,17 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "F": "minecraft:feather", + "G": "#c:nuggets/gold", + "P": "minecraft:paper" + }, + "pattern": [ + "GFG", + "PPP" + ], + "result": { + "count": 3, + "id": "waystones:blank_scroll" + } +} \ No newline at end of file diff --git a/common/src/generated/resources/data/waystones/tags/item/scrolls.json b/common/src/generated/resources/data/waystones/tags/item/scrolls.json index 9fe85358..db73cde1 100644 --- a/common/src/generated/resources/data/waystones/tags/item/scrolls.json +++ b/common/src/generated/resources/data/waystones/tags/item/scrolls.json @@ -2,6 +2,7 @@ "values": [ "waystones:warp_scroll", "waystones:return_scroll", - "waystones:bound_scroll" + "waystones:bound_scroll", + "waystones:blank_scroll" ] } \ No newline at end of file diff --git a/common/src/main/java/net/blay09/mods/waystones/block/WaystoneBlockBase.java b/common/src/main/java/net/blay09/mods/waystones/block/WaystoneBlockBase.java index 7fdff029..a1c3e440 100644 --- a/common/src/main/java/net/blay09/mods/waystones/block/WaystoneBlockBase.java +++ b/common/src/main/java/net/blay09/mods/waystones/block/WaystoneBlockBase.java @@ -9,6 +9,7 @@ import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase; import net.blay09.mods.waystones.component.ModComponents; import net.blay09.mods.waystones.core.*; +import net.blay09.mods.waystones.item.ModItems; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -16,6 +17,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.RandomSource; +import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; @@ -247,6 +249,14 @@ protected void addWaystoneNameToTooltip(List tooltip, WaystoneProxy w tooltip.add(waystone.getName().copy().withStyle(ChatFormatting.AQUA)); } + @Override + protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.is(ModItems.blankScroll)) { + return InteractionResult.PASS; + } + return super.useItemOn(itemStack, state, level, pos, player, hand, blockHitResult); + } + @Override public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult blockHitResult) { final var blockEntity = level.getBlockEntity(pos); diff --git a/common/src/main/java/net/blay09/mods/waystones/item/BlankScrollItem.java b/common/src/main/java/net/blay09/mods/waystones/item/BlankScrollItem.java new file mode 100644 index 00000000..2fb1cc3b --- /dev/null +++ b/common/src/main/java/net/blay09/mods/waystones/item/BlankScrollItem.java @@ -0,0 +1,47 @@ +package net.blay09.mods.waystones.item; + +import net.blay09.mods.waystones.api.WaystonesAPI; +import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.context.UseOnContext; + +import java.util.List; + +public class BlankScrollItem extends Item { + public BlankScrollItem(Properties properties) { + super(properties.stacksTo(64)); + } + + @Override + public InteractionResult useOn(UseOnContext context) { + final var blockEntity = context.getLevel().getBlockEntity(context.getClickedPos()); + if (blockEntity instanceof WaystoneBlockEntityBase waystoneBlockEntityBase) { + final var waystone = waystoneBlockEntityBase.getWaystone(); + final var boundScrollStack = new ItemStack(ModItems.boundScroll); + WaystonesAPI.setBoundWaystone(boundScrollStack, waystone); + final var player = context.getPlayer(); + int emptySlot = player.getInventory().getFreeSlot(); + int stackableSlot = player.getInventory().getSlotWithRemainingSpace(boundScrollStack); + if ((emptySlot != -1 || stackableSlot != -1) || (!player.hasInfiniteMaterials() && context.getItemInHand().getCount() == 1)) { + context.getItemInHand().consume(1, player); + if (!player.addItem(boundScrollStack)) { + player.drop(boundScrollStack, false); + } + return InteractionResult.SUCCESS; + } + return InteractionResult.FAIL; + } + + return super.useOn(context); + } + + @Override + public void appendHoverText(ItemStack itemStack, TooltipContext context, List list, TooltipFlag flag) { + list.add(Component.translatable("tooltip.waystones.blank_scroll").withStyle(ChatFormatting.GRAY)); + } +} diff --git a/common/src/main/java/net/blay09/mods/waystones/item/ModItems.java b/common/src/main/java/net/blay09/mods/waystones/item/ModItems.java index 9fff3d42..e345491f 100644 --- a/common/src/main/java/net/blay09/mods/waystones/item/ModItems.java +++ b/common/src/main/java/net/blay09/mods/waystones/item/ModItems.java @@ -1,7 +1,5 @@ package net.blay09.mods.waystones.item; - -import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.item.BalmItems; import net.blay09.mods.waystones.Waystones; @@ -14,7 +12,6 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; -import net.minecraft.world.level.block.Block; import java.util.Comparator; import java.util.HashMap; @@ -25,6 +22,7 @@ public class ModItems { public static DeferredObject creativeModeTab; public static Item returnScroll; + public static Item blankScroll; public static Item boundScroll; public static Item warpScroll; public static Item warpStone; @@ -36,13 +34,14 @@ public class ModItems { public static void initialize(BalmItems items) { items.registerItem((identifier) -> returnScroll = new ReturnScrollItem(defaultProperties(identifier)), id("return_scroll")); + items.registerItem((identifier) -> blankScroll = new BlankScrollItem(defaultProperties(identifier)), id("blank_scroll")); items.registerItem((identifier) -> boundScroll = new BoundScrollItem(defaultProperties(identifier)), id("bound_scroll"), null); items.registerItem((identifier) -> warpScroll = new WarpScrollItem(defaultProperties(identifier)), id("warp_scroll")); items.registerItem((identifier) -> warpStone = new WarpStoneItem(defaultProperties(identifier)), id("warp_stone")); items.registerItem((identifier) -> warpDust = new WarpDustItem(defaultProperties(identifier)), id("warp_dust")); items.registerItem((identifier) -> dormantShard = new ShardItem(defaultProperties(identifier)), id("dormant_shard")); items.registerItem((identifier) -> attunedShard = new AttunedShardItem(defaultProperties(identifier)), id("attuned_shard"), null); - items.registerItem((identifier) -> deepslateShard = new ShardItem(defaultProperties(identifier)), id("deepslate_shard")); + items.registerItem((identifier) -> deepslateShard = new ShardItem(defaultProperties(identifier)), id("deepslate_shard"), null); items.registerItem((identifier) -> crumblingAttunedShard = new CrumblingAttunedShardItem(defaultProperties(identifier)), id("crumbling_attuned_shard"), null); creativeModeTab = items.registerCreativeModeTab(() -> new ItemStack(ModBlocks.waystone), id("waystones")); @@ -53,6 +52,7 @@ public static void initialize(BalmItems items) { "white_portstone", "red_sharestone", "warp_plate", + "blank_scroll", "return_scroll", "warp_scroll", "warp_stone", @@ -62,7 +62,6 @@ public static void initialize(BalmItems items) { ".+_waystone", ".+_sharestone", ".+_portstone", - "bound_scroll", "attuned_shard", "crumbling_attuned_shard", }; diff --git a/common/src/main/resources/assets/waystones/lang/en_us.json b/common/src/main/resources/assets/waystones/lang/en_us.json index 9f06f038..020f438c 100644 --- a/common/src/main/resources/assets/waystones/lang/en_us.json +++ b/common/src/main/resources/assets/waystones/lang/en_us.json @@ -42,6 +42,7 @@ "item.waystones.warp_scroll_bound": "Warp Scroll (Bound)", "item.waystones.return_scroll": "Return Scroll", "item.waystones.warp_stone": "Warp Stone", + "item.waystones.blank_scroll": "Blank Scroll", "item.waystones.bound_scroll": "Bound Scroll", "item.waystones.warp_dust": "Warp Dust", "item.waystones.dormant_shard": "Dormant Shard", @@ -153,6 +154,7 @@ "tooltip.waystones.not_enough_xp": "Not enough experience! (%d levels needed)", "tooltip.waystones.undiscovered": "Undiscovered", "tooltip.waystones.edit_restricted": "This waystone cannot be edited.", + "tooltip.waystones.blank_scroll": "Use this scroll on a waystone to bind it.", "stat.waystones.waystone_activated": "Waystones Activated", "waystones.untitled_waystone": "Untitled Waystone", "waystones:warp_plate": "Warp Plate", diff --git a/common/src/main/resources/assets/waystones/textures/item/blank_scroll.png b/common/src/main/resources/assets/waystones/textures/item/blank_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..2d78c04a35f40413a41e718c1f2fac91b5e3c287 GIT binary patch literal 5416 zcmeHKc{r478=vgiQWD3>F(xW8`@+nzGuB38WUDmZd56I)W`+@oBPA7)?Ih8nq~b)y zDG{>tMH?z)NjjFCid4=?<$GsnyT0>J*Y%zMnz`P0-uHQa_wT;%-*Z3DGf#?#yOWx- zt}+Y;Q*&{4@PvLfB$tu`bl0DnWx!x^dt>OnB2R`G&KK}l>~Ih++R6vvU^JTrgGKlB z<@!}#TdBHhz>k`nVA%Wzrl3Pl^!NK8{%ri=IjyJoz7_UYTj#fieEQ7z?XnMbO>58Y zdtFZ*A)qvAPm)~kjJr;`^t6p^zw7izd)X~@$IK&HuXTHWiocLq>wGLJuSRp}jpx@N zq=i(zn}F~3F|a?r{+-ozvyMa}~D!4sQQKlCT{Ztz>=*6_Au5;J)EO-FU|^ywx_ zLvND9ka2}p`Xt`9eY8#!t>YZTIy^~OQiU;pl3jR9Wr(hSIxlwzihfJChU>Hcg6a!{ zmyej@9P~r2?qqfHgTa|>S{JdlGT_Yn_R;#8p$D;QaXqRg2O{_vA3ExtY}0K9O|d!Z z%BRWKMZ1qC2znQbZRpxbcK4{ky*m-uQz9JQczrRc)lPnmE_aXRnzo%FNnvvNrR$HA z4^d)MJdF~V2fI=yN>pxw$5EkW%gzamRKY|{-d|U*+^f=z(J!$nx;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