diff options
| author | 2024-01-08 21:17:52 +0100 | |
|---|---|---|
| committer | 2024-01-08 21:17:52 +0100 | |
| commit | 3d561d43e6cc1b3e90c56ba35e47ff5d3a4d91d0 (patch) | |
| tree | 9d5b9f3f1c6380a1e6c0fa2b9c087e0a385d5467 | |
| parent | Reorganised build gradle a bit (diff) | |
| download | mc-eris-alchemy-3d561d43e6cc1b3e90c56ba35e47ff5d3a4d91d0.tar.gz mc-eris-alchemy-3d561d43e6cc1b3e90c56ba35e47ff5d3a4d91d0.tar.xz mc-eris-alchemy-3d561d43e6cc1b3e90c56ba35e47ff5d3a4d91d0.zip | |
Replace ItemMixin.java with proper ItemTooltipCallback usage.
5 files changed, 21 insertions, 33 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java index a4368fc..fe7e40d 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java | |||
| @@ -12,9 +12,12 @@ import net.minecraft.world.item.Rarity; | |||
| 12 | import org.quiltmc.loader.api.ModContainer; | 12 | import org.quiltmc.loader.api.ModContainer; |
| 13 | import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; | 13 | import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; |
| 14 | import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; | 14 | import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; |
| 15 | import org.quiltmc.qsl.tooltip.api.client.ItemTooltipCallback; | ||
| 15 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 17 | 18 | ||
| 19 | import java.text.DecimalFormat; | ||
| 20 | |||
| 18 | public class ErisAlchemy implements ModInitializer { | 21 | public class ErisAlchemy implements ModInitializer { |
| 19 | public static final String ID = "eris_alchemy"; | 22 | public static final String ID = "eris_alchemy"; |
| 20 | public static final Logger LOGGER = LoggerFactory.getLogger(ID); | 23 | public static final Logger LOGGER = LoggerFactory.getLogger(ID); |
| @@ -47,5 +50,14 @@ public class ErisAlchemy implements ModInitializer { | |||
| 47 | Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ID, "high_covalence_dust"), HIGH_COVALENCE_DUST); | 50 | Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ID, "high_covalence_dust"), HIGH_COVALENCE_DUST); |
| 48 | 51 | ||
| 49 | Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, CovalenceRepair.Serializer.ID, CovalenceRepair.Serializer.INSTANCE); | 52 | Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, CovalenceRepair.Serializer.ID, CovalenceRepair.Serializer.INSTANCE); |
| 53 | |||
| 54 | var doubleFormat = new DecimalFormat("0"); | ||
| 55 | doubleFormat.setMaximumFractionDigits(1); | ||
| 56 | |||
| 57 | ItemTooltipCallback.EVENT.register((stack, player, context, tooltip) -> { | ||
| 58 | var world = player == null ? null : player.level(); | ||
| 59 | var emc = EMC.getInstance(world).get(stack.getItem()); | ||
| 60 | emc.ifPresent(value -> tooltip.add(Component.literal("EMC %s".formatted(doubleFormat.format(value))))); | ||
| 61 | }); | ||
| 50 | } | 62 | } |
| 51 | } | 63 | } |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java deleted file mode 100644 index aa6270b..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.mixin; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.EMC; | ||
| 4 | import net.minecraft.network.chat.Component; | ||
| 5 | import net.minecraft.world.item.Item; | ||
| 6 | import net.minecraft.world.item.ItemStack; | ||
| 7 | import net.minecraft.world.item.TooltipFlag; | ||
| 8 | import net.minecraft.world.level.Level; | ||
| 9 | import org.spongepowered.asm.mixin.Mixin; | ||
| 10 | import org.spongepowered.asm.mixin.Unique; | ||
| 11 | import org.spongepowered.asm.mixin.injection.At; | ||
| 12 | import org.spongepowered.asm.mixin.injection.Inject; | ||
| 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
| 14 | |||
| 15 | import java.text.DecimalFormat; | ||
| 16 | import java.util.List; | ||
| 17 | |||
| 18 | @Mixin(Item.class) | ||
| 19 | public abstract class ItemMixin { | ||
| 20 | @Unique | ||
| 21 | private static final DecimalFormat doubleFormat = new DecimalFormat("0"); | ||
| 22 | |||
| 23 | static { | ||
| 24 | doubleFormat.setMaximumFractionDigits(1); | ||
| 25 | } | ||
| 26 | |||
| 27 | @Inject(method = "appendHoverText", at = @At("RETURN")) | ||
| 28 | public void onAppendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag context, CallbackInfo ci) { | ||
| 29 | var emc = EMC.getInstance(world).get(stack.getItem()); | ||
| 30 | emc.ifPresent(value -> tooltip.add(Component.literal("EMC %s".formatted(doubleFormat.format(value))))); | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/src/main/resources/assets/eris_alchemy/patchouli_books/guide_book/en_us/entries/root/emc.json b/src/main/resources/assets/eris_alchemy/patchouli_books/guide_book/en_us/entries/root/emc.json new file mode 100644 index 0000000..1e3658a --- /dev/null +++ b/src/main/resources/assets/eris_alchemy/patchouli_books/guide_book/en_us/entries/root/emc.json | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | { | ||
| 2 | "name": "EMC", | ||
| 3 | "icon": "eris_alchemy:textures/gui/question-mark.png", | ||
| 4 | "category": "eris_alchemy:root", | ||
| 5 | "pages": [{ | ||
| 6 | "type": "patchouli:text", | ||
| 7 | "text": "$(thing)EMC$() (Energy-Matter Covalence) is an intrinsic property that $(strike)all$() most items have. You can view it as a measure of how $(italic)valuable$() an item is in the system of Eris Alchemy. Items that have an EMC value have it displayed in their tooltip you can see when mousing over it. On its own it doesn't change anything for the item, but can be useful with special items & blocks." | ||
| 8 | }] | ||
| 9 | } \ No newline at end of file | ||
diff --git a/src/main/resources/assets/eris_alchemy/textures/gui/question-mark.png b/src/main/resources/assets/eris_alchemy/textures/gui/question-mark.png new file mode 100644 index 0000000..335014c --- /dev/null +++ b/src/main/resources/assets/eris_alchemy/textures/gui/question-mark.png | |||
| Binary files differ | |||
diff --git a/src/main/resources/eris_alchemy.mixins.json b/src/main/resources/eris_alchemy.mixins.json index 1fdb6bd..56177c0 100644 --- a/src/main/resources/eris_alchemy.mixins.json +++ b/src/main/resources/eris_alchemy.mixins.json | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | "CoralFanBlockMixin", | 8 | "CoralFanBlockMixin", |
| 9 | "CoralPlantBlockMixin", | 9 | "CoralPlantBlockMixin", |
| 10 | "CoralWallFanBlockMixin", | 10 | "CoralWallFanBlockMixin", |
| 11 | "ItemMixin", | ||
| 12 | "RecipeMixin", | 11 | "RecipeMixin", |
| 13 | "SmithingTransformRecipeMixin" | 12 | "SmithingTransformRecipeMixin" |
| 14 | ], | 13 | ], |