Skip to content

Commit

Permalink
[FEATURE] Added tooltips to butterfly items.
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-bok committed Mar 20, 2024
1 parent de7c95f commit d99f798
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 3.3.2 (2024-03-20)
- Added tooltips to butterfly items.

### 3.3.1 (2024-03-20)
- Butterflies now release heart particles when they become fertile.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=Butterfly Mod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=3.3.1
mod_version=3.3.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.bokmcdok.butterflies.world.item;

import com.bokmcdok.butterflies.world.entity.animal.Butterfly;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -65,7 +69,7 @@ public BottledButterflyItem(RegistryObject<Block> block,
}

/**
* Adds some helper text that tells us what butterfly is in the net (if any).
* Adds some helper text.
* @param stack The item stack.
* @param level The current level.
* @param components The current text components.
Expand All @@ -77,6 +81,13 @@ public void appendHoverText(@NotNull ItemStack stack,
@NotNull List<Component> components,
@NotNull TooltipFlag tooltipFlag) {
appendButterflyNameToHoverText(stack, components);

MutableComponent newComponent = Component.translatable("tooltip.butterflies.release_butterfly");
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.bokmcdok.butterflies.world.ButterflyData;
import com.bokmcdok.butterflies.world.entity.animal.Caterpillar;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -70,7 +69,7 @@ public BottledCaterpillarItem(RegistryObject<Block> block,
}

/**
* Adds some helper text that tells us what butterfly is in the net (if any).
* Adds some helper text.
* @param stack The item stack.
* @param level The current level.
* @param components The current text components.
Expand All @@ -83,11 +82,17 @@ public void appendHoverText(@NotNull ItemStack stack,
@NotNull TooltipFlag tooltipFlag) {
String translatable = "item." + species.toString().replace(':', '.');

MutableComponent newComponent = Component.translatable(translatable);
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.DARK_RED))
MutableComponent speciesComponent = Component.translatable(translatable);
Style speciesStyle = speciesComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.DARK_RED))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);
speciesComponent.setStyle(speciesStyle);
components.add(speciesComponent);

MutableComponent tooltipComponent = Component.translatable("tooltip.butterflies.release_caterpillar");
Style tooltipStyle = tooltipComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
tooltipComponent.setStyle(tooltipStyle);
components.add(tooltipComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@

import com.bokmcdok.butterflies.world.ButterflyData;
import com.bokmcdok.butterflies.world.entity.animal.ButterflyEgg;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
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 net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
* An egg that will eventually hatch into a caterpillar.
Expand Down Expand Up @@ -52,6 +63,28 @@ public ButterflyEggItem(int butterflyIndex,
this.butterflyIndex = butterflyIndex;
}

/**
* Adds some tooltips.
* @param stack The item stack.
* @param level The current level.
* @param components The current text components.
* @param tooltipFlag Is this a tooltip?
*/
@Override
public void appendHoverText(@NotNull ItemStack stack,
@Nullable Level level,
@NotNull List<Component> components,
@NotNull TooltipFlag tooltipFlag) {

MutableComponent newComponent = Component.translatable("tooltip.butterflies.place_egg");
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}

/**
* Get the butterfly index.
* @return The butterfly index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.bokmcdok.butterflies.registries.ItemRegistry;
import com.bokmcdok.butterflies.world.entity.animal.Butterfly;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -74,6 +78,18 @@ public void appendHoverText(@NotNull ItemStack stack,
@NotNull List<Component> components,
@NotNull TooltipFlag tooltipFlag) {
appendButterflyNameToHoverText(stack, components);

String localisation = "tooltip.butterflies.release_butterfly";
if (butterflyIndex < 0) {
localisation = "tooltip.butterflies.butterfly_net";
}

MutableComponent newComponent = Component.translatable(localisation);
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import com.bokmcdok.butterflies.client.gui.screens.ButterflyScrollScreen;
import com.bokmcdok.butterflies.world.CompoundTagId;
import com.bokmcdok.butterflies.world.entity.decoration.ButterflyScroll;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -75,6 +79,13 @@ public void appendHoverText(@NotNull ItemStack stack,
@NotNull List<Component> components,
@NotNull TooltipFlag tooltipFlag) {
appendButterflyNameToHoverText(stack, components);

MutableComponent newComponent = Component.translatable("tooltip.butterflies.scroll");
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}

Expand Down Expand Up @@ -185,7 +196,7 @@ protected boolean mayPlace(Player player, Direction direction, ItemStack itemSta
}

/**
* Open the screen. Kept separate so it can be excluded from server builds.
* Open the screen. Kept separate, so it can be excluded from server builds.
* @param butterflyIndex The index of the butterfly.
*/
@OnlyIn(Dist.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@

import com.bokmcdok.butterflies.ButterfliesMod;
import com.bokmcdok.butterflies.world.entity.animal.Caterpillar;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
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 net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
* A class to represent a caterpillar in the player's inventory.
Expand Down Expand Up @@ -49,6 +60,28 @@ public CaterpillarItem(String species) {
this.species = new ResourceLocation(ButterfliesMod.MODID, species);
}

/**
* Adds some tooltips.
* @param stack The item stack.
* @param level The current level.
* @param components The current text components.
* @param tooltipFlag Is this a tooltip?
*/
@Override
public void appendHoverText(@NotNull ItemStack stack,
@Nullable Level level,
@NotNull List<Component> components,
@NotNull TooltipFlag tooltipFlag) {

MutableComponent newComponent = Component.translatable("tooltip.butterflies.place_caterpillar");
Style style = newComponent.getStyle().withColor(TextColor.fromLegacyFormat(ChatFormatting.GRAY))
.withItalic(true);
newComponent.setStyle(style);
components.add(newComponent);

super.appendHoverText(stack, level, components, tooltipFlag);
}

/**
* Places the butterfly scroll on a block.
* @param context Contains information about the block the user clicked on.
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/assets/butterflies/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"advancements.butterfly.butterfly_scroll.title": "Butterfly Collector",
"advancements.butterfly.butterfly_scroll.description": "Create a butterfly scroll",
"advancements.butterfly.butterfly_book.title": "Butterfly Scribe",
"advancements.butterfly.butterfly_book.deswcription": "Fill a book with butterfly scrolls",
"advancements.butterfly.butterfly_book.description": "Fill a book with butterfly scrolls",
"advancements.butterfly.find_caterpillar.title": "This isn't Grub",
"advancements.butterfly.find_caterpillar.description": "Find a caterpillar",
"advancements.butterfly.find_all_caterpillars.title": "Worm Salad",
Expand Down Expand Up @@ -283,5 +283,12 @@
"gui.butterflies.fact.rainbow": "Rainbow butterflies have only been recently discovered.",
"gui.butterflies.fact.swallowtail": "Swallowtails are the largest butterflies in the world.",

"gui.butterflies.zhuangzi": "As I flutter in the breeze\nI think of what my mind's eye sees\nAt night when I'm an old wise man\nContemplating the things I can.\nAm I the one that dreams of he,\nOr is he the one that dreams of me?\n\n- 莊子"
"gui.butterflies.zhuangzi": "As I flutter in the breeze\nI think of what my mind's eye sees\nAt night when I'm an old wise man\nContemplating the things I can.\nAm I the one that dreams of he,\nOr is he the one that dreams of me?\n\n- 莊子",

"tooltip.butterflies.butterfly_net": "Swing (left-click) at a butterfly to catch it",
"tooltip.butterflies.release_butterfly": "Right click to release the butterfly",
"tooltip.butterflies.release_caterpillar": "Right click to release the caterpillar",
"tooltip.butterflies.place_caterpillar": "Right-click on leaves to place the caterpillar",
"tooltip.butterflies.place_egg": "Right-click on leaves to place the butterfly egg",
"tooltip.butterflies.scroll": "Right-click to read or to place on a block"
}

0 comments on commit d99f798

Please sign in to comment.