Skip to content

Commit

Permalink
Added A Custom Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangerGamer-A committed Oct 11, 2024
1 parent 765c7ff commit 5b48155
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.TooltipFlag;
import net.strangergamer.mccourse.item.ModItems;
import net.strangergamer.mccourse.util.ModTags;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -41,8 +42,7 @@ public void stepOn(Level pLevel, BlockPos pPos, BlockState pState, Entity pEntit
super.stepOn(pLevel, pPos, pState, pEntity);
}
private boolean isValidItem(ItemStack item) {
return item.getItem() == ModItems.RAW_BLACK_OPAL.get()
|| item.getItem() == Items.COAL || item.getItem() == Items.DANDELION;
return item.is(ModTags.Items.TRANSFORMABLE_ITEMS);
}
@Override
public void appendHoverText(ItemStack pStack, Item.TooltipContext pContext, List<Component> pTootipComponents, TooltipFlag pTooltipFlag) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/strangergamer/mccourse/util/ModTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.strangergamer.mccourse.util;

import net.strangergamer.mccourse.MCCourseMod;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
public class ModTags {
public static class Blocks {
private static TagKey<Block> createTag(String name) {
return BlockTags.create(ResourceLocation.fromNamespaceAndPath(MCCourseMod.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 ItemTags.create(ResourceLocation.fromNamespaceAndPath(MCCourseMod.MOD_ID, name));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
"mccourse:raw_black_opal",
"minecraft:coal",
"minecraft:dandelion",
"minecraft:compass"
]
}

0 comments on commit 5b48155

Please sign in to comment.