Skip to content

Commit

Permalink
custom tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaupenjoe committed Aug 29, 2024
1 parent e1a5d36 commit a2536a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kaupenjoe.tutorialmod.block.custom;

import net.kaupenjoe.tutorialmod.item.ModItems;
import net.kaupenjoe.tutorialmod.util.ModTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -35,14 +36,18 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player
@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if(entity instanceof ItemEntity itemEntity) {
if(itemEntity.getStack().getItem() == ModItems.RAW_PINK_GARNET) {
if(isValidItem(itemEntity.getStack())) {
itemEntity.setStack(new ItemStack(Items.DIAMOND, itemEntity.getStack().getCount()));
}
}

super.onSteppedOn(world, pos, state, entity);
}

private boolean isValidItem(ItemStack stack) {
return stack.isIn(ModTags.Items.TRANSFORMABLE_ITEMS);
}

@Override
public void appendTooltip(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType options) {
tooltip.add(Text.translatable("tooltip.tutorialmod.magic_block.tooltip"));
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/kaupenjoe/tutorialmod/util/ModTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.kaupenjoe.tutorialmod.util;

import net.kaupenjoe.tutorialmod.TutorialMod;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

public class ModTags {
public static class Blocks {

private static TagKey<Block> createTag(String name) {
return TagKey.of(RegistryKeys.BLOCK, Identifier.of(TutorialMod.MOD_ID, name));
}
}

public static class Items {
public static final TagKey<Item> TRANSFORMABLE_ITEMS = createTag("transformable_items");

private static TagKey<Item> createTag(String name) {
return TagKey.of(RegistryKeys.ITEM, Identifier.of(TutorialMod.MOD_ID, name));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"values": [
"tutorialmod:pink_garnet",
"tutorialmod:raw_pink_garnet",
"minecraft:coal",
"minecraft:stick",
"minecraft:apple"
]
}

0 comments on commit a2536a3

Please sign in to comment.