Skip to content

Commit

Permalink
feat: Add Blank Scroll to re-add bound scroll functionality #847
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 24, 2024
1 parent 6358a24 commit c409370
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "waystones:item/blank_scroll"
}
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"values": [
"waystones:warp_scroll",
"waystones:return_scroll",
"waystones:bound_scroll"
"waystones:bound_scroll",
"waystones:blank_scroll"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
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;
import net.minecraft.core.registries.Registries;
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;
Expand Down Expand Up @@ -247,6 +249,14 @@ protected void addWaystoneNameToTooltip(List<Component> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Component> list, TooltipFlag flag) {
list.add(Component.translatable("tooltip.waystones.blank_scroll").withStyle(ChatFormatting.GRAY));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -25,6 +22,7 @@ public class ModItems {
public static DeferredObject<CreativeModeTab> creativeModeTab;

public static Item returnScroll;
public static Item blankScroll;
public static Item boundScroll;
public static Item warpScroll;
public static Item warpStone;
Expand All @@ -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"));
Expand All @@ -53,6 +52,7 @@ public static void initialize(BalmItems items) {
"white_portstone",
"red_sharestone",
"warp_plate",
"blank_scroll",
"return_scroll",
"warp_scroll",
"warp_stone",
Expand All @@ -62,7 +62,6 @@ public static void initialize(BalmItems items) {
".+_waystone",
".+_sharestone",
".+_portstone",
"bound_scroll",
"attuned_shard",
"crumbling_attuned_shard",
};
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/waystones/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ModItemTagProvider(FabricDataOutput output, CompletableFuture<HolderLooku
@Override
protected void addTags(HolderLookup.Provider lookup) {
getOrCreateTagBuilder(TagKey.create(Registries.ITEM, ResourceLocation.withDefaultNamespace("enchantable/durability"))).add(ModItems.warpStone);
getOrCreateTagBuilder(ModItemTags.SCROLLS).add(ModItems.warpScroll, ModItems.returnScroll, ModItems.boundScroll);
getOrCreateTagBuilder(ModItemTags.SCROLLS).add(ModItems.warpScroll, ModItems.returnScroll, ModItems.boundScroll, ModItems.blankScroll);
getOrCreateTagBuilder(ModItemTags.WARP_SCROLLS).add(ModItems.warpScroll);
getOrCreateTagBuilder(ModItemTags.RETURN_SCROLLS).add(ModItems.returnScroll);
getOrCreateTagBuilder(ModItemTags.BOUND_SCROLLS).add(ModItems.boundScroll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void generateItemModels(ItemModelGenerators itemModelGenerator) {
itemModelGenerator.generateFlatItem(ModItems.warpScroll, ModelTemplates.FLAT_HANDHELD_ITEM);
itemModelGenerator.generateFlatItem(ModItems.returnScroll, ModelTemplates.FLAT_HANDHELD_ITEM);
itemModelGenerator.generateFlatItem(ModItems.boundScroll, ModelTemplates.FLAT_HANDHELD_ITEM);
itemModelGenerator.generateFlatItem(ModItems.blankScroll, ModelTemplates.FLAT_HANDHELD_ITEM);

final var sharestoneTemplate = new ModelTemplate(Optional.of(ResourceLocation.fromNamespaceAndPath("waystones", "item/sharestone")), Optional.empty());
for (final var sharestone : ModBlocks.sharestones) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ public void buildRecipes() {
.unlockedBy("has_ender_pearl", has(Items.ENDER_PEARL))
.save(exporter);

shaped(RecipeCategory.DECORATIONS, ModItems.blankScroll, 3)
.pattern("GFG")
.pattern("PPP")
.define('F', Items.FEATHER)
.define('G', BalmItemTags.GOLD_NUGGETS)
.define('P', Items.PAPER)
.unlockedBy("has_paper", has(Items.PAPER))
.save(exporter);

shaped(RecipeCategory.DECORATIONS, ModItems.returnScroll, 3)
.pattern("GEG")
.pattern("PPP")
Expand Down

0 comments on commit c409370

Please sign in to comment.