Skip to content

Commit

Permalink
Added 5 Custom Tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangerGamer-A committed Oct 11, 2024
1 parent eb651c1 commit 765c7ff
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.strangergamer.mccourse.block.custom;

import net.minecraft.world.item.Item;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.TooltipFlag;
import net.strangergamer.mccourse.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -15,6 +18,9 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

import java.util.List;


public class MagicBlock extends Block {
public MagicBlock(Properties properties) {
super(properties);
Expand All @@ -38,4 +44,9 @@ private boolean isValidItem(ItemStack item) {
return item.getItem() == ModItems.RAW_BLACK_OPAL.get()
|| item.getItem() == Items.COAL || item.getItem() == Items.DANDELION;
}
@Override
public void appendHoverText(ItemStack pStack, Item.TooltipContext pContext, List<Component> pTootipComponents, TooltipFlag pTooltipFlag) {
pTootipComponents.add(Component.translatable("tooltip.mccourse.magic_block.tooltip.1"));
super.appendHoverText(pStack, pContext, pTootipComponents, pTooltipFlag);
}
}
13 changes: 12 additions & 1 deletion src/main/java/net/strangergamer/mccourse/item/ModItems.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package net.strangergamer.mccourse.item;

import net.minecraft.world.item.Item;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.strangergamer.mccourse.MCCourseMod;
import net.strangergamer.mccourse.item.custom.ChainsawItem;
import net.strangergamer.mccourse.item.custom.FuelItem;

import java.util.List;

public class ModItems {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MCCourseMod.MOD_ID);

Expand All @@ -16,7 +21,13 @@ public class ModItems {
public static final DeferredItem<Item> CHAINSAW =
ITEMS.registerItem("chainsaw", ChainsawItem::new, new Item.Properties().durability(32));
public static final DeferredItem<Item> TOMATO =
ITEMS.registerItem("tomato", Item::new, new Item.Properties().food(ModFoodProperties.TOMATO));
ITEMS.registerItem("tomato", properties -> new Item(properties) {
@Override
public void appendHoverText(ItemStack pStack, TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
pTooltipComponents.add(Component.translatable("tooltip.mccourse.tomato.1"));
super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag);
}
}, new Item.Properties().food(ModFoodProperties.TOMATO));
public static final DeferredItem<Item> FROSTFIRE_ICE =
ITEMS.registerItem("frostfire_ice", properties -> new FuelItem(properties, 800), new Item.Properties());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package net.strangergamer.mccourse.item.custom;

import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EquipmentSlot;
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 net.minecraft.world.level.Level;

import java.util.List;
import java.util.Objects;

public class ChainsawItem extends Item {
Expand All @@ -31,4 +36,15 @@ public InteractionResult useOn(UseOnContext pContext) {

return InteractionResult.CONSUME;
}
@Override
public void appendHoverText(ItemStack pStack, TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
if(Screen.hasShiftDown()) {
pTooltipComponents.add(Component.translatable("tooltip.mccourse.chainsaw.tooltip.1"));
pTooltipComponents.add(Component.translatable("tooltip.mccourse.chainsaw.tooltip.2"));
} else {
pTooltipComponents.add(Component.translatable("tooltip.mccourse.chainsaw.tooltip.shift"));
}

super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag);
}
}
12 changes: 5 additions & 7 deletions src/main/resources/assets/mccourse/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{
"item.mccourse.black_opal": "Black Opal",
"item.mccourse.raw_black_opal": "Raw Black Opal",

"item.mccourse.chainsaw": "Chainsaw",

"item.mccourse.tomato": "Tomato",

"item.mccourse.frostfire_ice": "Frostfire Ice",

"block.mccourse.black_opal_block": "Block of Black Opal",
"block.mccourse.raw_black_opal_block": "Block of Raw Black Opal",

"block.mccourse.magic_block": "Block of Magic",

"block.mccourse.black_opal_ore": "Black Opal Ore",
"block.mccourse.black_opal_deepslate_ore": "Deepslate Black Opal Ore",
"block.mccourse.black_opal_end_ore": "End Black Opal Ore",
"block.mccourse.black_opal_nether_ore": "Nether Black Opal Ore",

"tooltip.mccourse.chainsaw.tooltip.shift": "Press §eShift§r for more Information",
"tooltip.mccourse.chainsaw.tooltip.1": "This chainsaw is awesome and will cut down trees!",
"tooltip.mccourse.chainsaw.tooltip.2": "§oChainsaw go vroom!§r",
"tooltip.mccourse.magic_block.tooltip.1": "This Block is very very §9MAGICAL§r",
"tooltip.mccourse.tomato.1": "Tomato; Tomato",
"itemGroup.mccourse.black_opal_items_tab": "MCCourse Additions"
}
5 changes: 5 additions & 0 deletions src/main/resources/assets/mccourse/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"block.mccourse.black_opal_deepslate_ore": "Minerai d’opale noire Deepslate",
"block.mccourse.black_opal_end_ore": "Minerai d’opale noire du End",
"block.mccourse.black_opal_nether_ore": "Minerai d’opale noire du Nether",
"tooltip.mccourse.chainsaw.tooltip.shift": "Appuyez sur §eShift§r pour plus d’informations",
"tooltip.mccourse.chainsaw.tooltip.1": "Cette tronçonneuse est géniale et coupera des arbres !",
"tooltip.mccourse.chainsaw.tooltip.2": "§oTronçonneuse go vroum !§r",
"tooltip.mccourse.magic_block.tooltip.1": "Ce bloc est très, très §9MAGIQUE§r",
"tooltip.mccourse.tomato.1": "Tomate; Tomate",
"itemGroup.mccourse.black_opal_items_tab": "Ajouts à MCCourse"
}
5 changes: 5 additions & 0 deletions src/main/resources/assets/mccourse/lang/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"block.mccourse.black_opal_deepslate_ore": "Minério de Opala Negra de Deepslate",
"block.mccourse.black_opal_end_ore": "Minério de Opala Negra de End",
"block.mccourse.black_opal_nether_ore": "Minério Opala Negra de Nether",
"tooltip.mccourse.chainsaw.tooltip.shift": "Pressione §eShift§r para obter mais informações",
"tooltip.mccourse.chainsaw.tooltip.1": "Esta motosserra é incrível e corta árvores!",
"tooltip.mccourse.chainsaw.tooltip.2": "§oMotosserra go vroom!§r",
"tooltip.mccourse.magic_block.tooltip.1": "Este Bloco é §9MAGICAL§r",
"tooltip.mccourse.tomato.1": "Tomate; Tomate",
"itemGroup.mccourse.black_opal_items_tab": "Adições do MCCourse"
}

0 comments on commit 765c7ff

Please sign in to comment.