Skip to content

Commit

Permalink
custom tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaupenjoe committed Aug 29, 2024
1 parent e88cf8b commit e1a5d36
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.List;

public class MagicBlock extends Block {
public MagicBlock(Settings settings) {
super(settings);
Expand All @@ -37,4 +42,10 @@ public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity enti

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

@Override
public void appendTooltip(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType options) {
tooltip.add(Text.translatable("tooltip.tutorialmod.magic_block.tooltip"));
super.appendTooltip(stack, context, tooltip, options);
}
}
13 changes: 12 additions & 1 deletion src/main/java/net/kaupenjoe/tutorialmod/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@
import net.kaupenjoe.tutorialmod.item.custom.ChiselItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.List;

public class ModItems {
public static final Item PINK_GARNET = registerItem("pink_garnet", new Item(new Item.Settings()));
public static final Item RAW_PINK_GARNET = registerItem("raw_pink_garnet", new Item(new Item.Settings()));

public static final Item CHISEL = registerItem("chisel", new ChiselItem(new Item.Settings().maxDamage(32)));
public static final Item CAULIFLOWER = registerItem("cauliflower", new Item(new Item.Settings().food(ModFoodComponents.CAULIFLOWER)));
public static final Item CAULIFLOWER = registerItem("cauliflower", new Item(new Item.Settings().food(ModFoodComponents.CAULIFLOWER)) {
@Override
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
tooltip.add(Text.translatable("tooltip.tutorialmod.cauliflower.tooltip"));
super.appendTooltip(stack, context, tooltip, type);
}
});

public static final Item STARLIGHT_ASHES = registerItem("starlight_ashes", new Item(new Item.Settings()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.world.World;

import java.util.List;
import java.util.Map;

public class ChiselItem extends Item {
Expand Down Expand Up @@ -46,4 +51,15 @@ public ActionResult useOnBlock(ItemUsageContext context) {

return ActionResult.SUCCESS;
}

@Override
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
if(Screen.hasShiftDown()) {
tooltip.add(Text.translatable("tooltip.tutorialmod.chisel.shift_down"));
} else {
tooltip.add(Text.translatable("tooltip.tutorialmod.chisel"));
}

super.appendTooltip(stack, context, tooltip, type);
}
}
9 changes: 8 additions & 1 deletion src/main/resources/assets/tutorialmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@


"itemgroup.tutorialmod.pink_garnet_items": "Pink Garnet Items",
"itemgroup.tutorialmod.pink_garnet_blocks": "Pink Garnet Blocks"
"itemgroup.tutorialmod.pink_garnet_blocks": "Pink Garnet Blocks",

"tooltip.tutorialmod.magic_block.tooltip": "This block is very, very §9MAGICAL§r",

"tooltip.tutorialmod.chisel.shift_down": "This item chisels blocks into Bricks!",
"tooltip.tutorialmod.chisel": "Press §eShift§r for more Information!",

"tooltip.tutorialmod.cauliflower.tooltip": "This is delicious!"
}

0 comments on commit e1a5d36

Please sign in to comment.