diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java index 24fb12e0..ad2bd118 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java @@ -4,15 +4,13 @@ import at.petrak.hexcasting.api.item.ManaHolderItem; import net.minecraft.ChatFormatting; import net.minecraft.advancements.Advancement; 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.network.chat.TranslatableComponent; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -60,15 +58,15 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem { } @Override - public InteractionResultHolder use(Level level, Player player, InteractionHand usedHand) { - if (level instanceof ServerLevel slevel) { + public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity consumer) { + if (level instanceof ServerLevel slevel && consumer instanceof ServerPlayer player) { var rootAdv = slevel.getServer().getAdvancements().getAdvancement(modLoc("root")); if (rootAdv != null) { var children = new ArrayList(); children.add(rootAdv); addChildren(rootAdv, children); - var adman = ((ServerPlayer) player).getAdvancements(); + var adman = player.getAdvancements(); for (var kid : children) { var progress = adman.getOrStartProgress(kid); @@ -81,25 +79,31 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem { } } - return InteractionResultHolder.success(player.getItemInHand(usedHand)); + ItemStack copy = stack.copy(); + super.finishUsingItem(stack, level, consumer); + return copy; } - private static MutableComponent rainbow(MutableComponent component, Level level) { + private static final TextColor HEX_COLOR = TextColor.fromRgb(0xb38ef3); + + private static Style rainbow(Style style, Level level) { if (level == null) { - return component.withStyle(ChatFormatting.WHITE); + return style.withColor(ChatFormatting.WHITE); } - return component.withStyle((s) -> - s.withColor(TextColor.fromRgb(Mth.hsvToRgb(level.getGameTime() * 2 % 360 / 360F, 1F, 1F)))); + return style.withColor(TextColor.fromRgb(Mth.hsvToRgb(level.getGameTime() * 2 % 360 / 360F, 1F, 1F))); } @Override public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltipComponents, TooltipFlag isAdvanced) { String prefix = "item.hexcasting.creative_unlocker."; - tooltipComponents.add(new TranslatableComponent(prefix + "tooltip.0", rainbow(new TranslatableComponent(prefix + "for_emphasis"), level) - .withStyle(ChatFormatting.GRAY))); - tooltipComponents.add(new TranslatableComponent(prefix + "tooltip.1").withStyle(ChatFormatting.GRAY)); + tooltipComponents.add(new TranslatableComponent(prefix + "tooltip.0", + new TranslatableComponent(prefix + "for_emphasis").withStyle((s) -> rainbow(s, level))) + .withStyle(ChatFormatting.GRAY)); + tooltipComponents.add(new TranslatableComponent(prefix + "tooltip.1", + new TranslatableComponent(prefix + "mod_name").withStyle((s) -> s.withColor(HEX_COLOR))) + .withStyle(ChatFormatting.GRAY)); } private static void addChildren(Advancement root, List out) { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java index 9c7ac96e..ad816f4e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java @@ -9,10 +9,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.food.FoodProperties; -import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.*; import java.util.EnumMap; import java.util.LinkedHashMap; @@ -87,7 +84,9 @@ public class HexItems { new Item(props().food(new FoodProperties.Builder().nutrition(14).saturationMod(1.2f).build()))); public static final ItemCreativeUnlocker CREATIVE_UNLOCKER = make("creative_unlocker", - new ItemCreativeUnlocker(props())); + new ItemCreativeUnlocker(unstackable() + .rarity(Rarity.EPIC) + .food(new FoodProperties.Builder().nutrition(20).saturationMod(1f).alwaysEat().build()))); // diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.json b/Common/src/main/resources/assets/hexcasting/lang/en_us.json index 7983f946..212edeb6 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -57,10 +57,11 @@ "item.hexcasting.pride_colorizer_12": "Intersex Pigment", "item.hexcasting.pride_colorizer_13": "Aroace Pigment", "item.hexcasting.uuid_colorizer": "Soulglimmer Pigment", - "item.hexcasting.creative_unlocker": "Creative Unlocker", - "item.hexcasting.creative_unlocker.for_emphasis": "INFINITE MEDIA", + "item.hexcasting.creative_unlocker": "The Media Cube", "item.hexcasting.creative_unlocker.tooltip.0": "Contains %s.", - "item.hexcasting.creative_unlocker.tooltip.1": "Right-click to unlock all Hexcasting advancements and abilities.", + "item.hexcasting.creative_unlocker.for_emphasis": "INFINITE MEDIA", + "item.hexcasting.creative_unlocker.tooltip.1": "Consume to unlock all %s knowledge.", + "item.hexcasting.creative_unlocker.mod_name": "Hexcasting", "block.hexcasting.conjured": "Conjured Block",