From 438a1b0c24a4e46910c368d3c93bf5d7c65a0ec1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 20 May 2020 15:41:55 +0200 Subject: [PATCH] eir's token --- .../models/item/break_prevention.json | 6 ++ .../items/ItemBreakPrevention.java | 73 ++++++++++++++++++ .../ellpeck/naturesaura/items/ModItems.java | 1 + .../ellpeck/naturesaura/reg/ModRegistry.java | 3 +- .../assets/naturesaura/lang/en_us.json | 3 + .../textures/item/break_prevention.png | Bin 0 -> 376 bytes .../en_us/entries/items/break_prevention.json | 17 ++++ .../recipes/tree_ritual/break_prevention.json | 24 ++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/generated/resources/assets/naturesaura/models/item/break_prevention.json create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemBreakPrevention.java create mode 100644 src/main/resources/assets/naturesaura/textures/item/break_prevention.png create mode 100644 src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/break_prevention.json create mode 100644 src/main/resources/data/naturesaura/recipes/tree_ritual/break_prevention.json diff --git a/src/generated/resources/assets/naturesaura/models/item/break_prevention.json b/src/generated/resources/assets/naturesaura/models/item/break_prevention.json new file mode 100644 index 00000000..da2e36b1 --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/item/break_prevention.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:item/break_prevention" + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemBreakPrevention.java b/src/main/java/de/ellpeck/naturesaura/items/ItemBreakPrevention.java new file mode 100644 index 00000000..b7b3ece9 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemBreakPrevention.java @@ -0,0 +1,73 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.misc.IWorldData; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ElytraItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.AnvilUpdateEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import java.lang.ref.WeakReference; +import java.util.List; + +public class ItemBreakPrevention extends ItemImpl { + public ItemBreakPrevention() { + super("break_prevention"); + MinecraftForge.EVENT_BUS.register(new Events()); + } + + public static class Events { + @SubscribeEvent + public void onAnvilUpdate(AnvilUpdateEvent event) { + ItemStack stack = event.getLeft(); + if (stack.getToolTypes().isEmpty() || !stack.isDamageable()) + return; + ItemStack second = event.getRight(); + if (second.getItem() != ModItems.BREAK_PREVENTION) + return; + ItemStack output = stack.copy(); + output.getOrCreateTag().putBoolean(NaturesAura.MOD_ID + ":break_prevention", true); + event.setOutput(output); + event.setMaterialCost(1); + event.setCost(1); + } + + @SubscribeEvent + public void onBreakSpeed(PlayerEvent.BreakSpeed event) { + PlayerEntity player = event.getPlayer(); + if (player == null) + return; + ItemStack stack = player.getHeldItemMainhand(); + if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention")) + return; + if (ElytraItem.isUsable(stack)) + return; + event.setNewSpeed(0); + } + + @SubscribeEvent + public void onTooltip(ItemTooltipEvent event) { + ItemStack stack = event.getItemStack(); + if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention")) + return; + List tooltip = event.getToolTip(); + tooltip.add(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".break_prevention").setStyle(new Style().setColor(TextFormatting.GRAY))); + if (ElytraItem.isUsable(stack)) + return; + if (tooltip.size() < 1) + return; + tooltip.get(0).appendSibling(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".broken").setStyle(new Style().setColor(TextFormatting.GRAY))); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index 2e2044e7..d5ed7c1f 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -60,4 +60,5 @@ public final class ModItems { public static Item SKY_SHOES; public static Item FORTRESS_FINDER; public static Item END_CITY_FINDER; + public static Item BREAK_PREVENTION; } diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 58c9683e..2275f358 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -215,7 +215,8 @@ public final class ModRegistry { new ItemArmor("sky_pants", ModArmorMaterial.SKY, EquipmentSlotType.LEGS), new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlotType.FEET), new ItemStructureFinder("fortress_finder", "Fortress", 0xba2800), - new ItemStructureFinder("end_city_finder", "EndCity", 0xca5cd6) + new ItemStructureFinder("end_city_finder", "EndCity", 0xca5cd6), + new ItemBreakPrevention() ); Helper.populateObjectHolders(ModItems.class, event.getRegistry()); } diff --git a/src/main/resources/assets/naturesaura/lang/en_us.json b/src/main/resources/assets/naturesaura/lang/en_us.json index 3df7bc15..ad2571ee 100644 --- a/src/main/resources/assets/naturesaura/lang/en_us.json +++ b/src/main/resources/assets/naturesaura/lang/en_us.json @@ -129,6 +129,7 @@ "item.naturesaura.light_staff": "Staff of Baldur", "item.naturesaura.fortress_finder": "Eye of the Blaze", "item.naturesaura.end_city_finder": "Eye of the Shulker", + "item.naturesaura.break_prevention": "Eir's Token", "container.naturesaura:tree_ritual.name": "Ritual of the Forest", "container.naturesaura:altar.name": "Natural Altar Infusion", "container.naturesaura:offering.name": "Offering to the Gods", @@ -150,6 +151,8 @@ "info.naturesaura.range_visualizer.end": "You lose focus of the magnification...", "info.naturesaura.range_visualizer.end_all": "You lose focus of all magnifications...", "info.naturesaura.remaining": "%s remaining", + "info.naturesaura.break_prevention": "Eir's Token applied", + "info.naturesaura.broken": " (Broken)", "advancement.naturesaura.root": "Nature's Aura", "advancement.naturesaura.root.desc": "Becoming a magical botanist", "advancement.naturesaura.get_book": "Pages of Discovery", diff --git a/src/main/resources/assets/naturesaura/textures/item/break_prevention.png b/src/main/resources/assets/naturesaura/textures/item/break_prevention.png new file mode 100644 index 0000000000000000000000000000000000000000..f85466aee0eafc629e1ad9a3d2947042525218b2 GIT binary patch literal 376 zcmV-;0f+vHP)1p=5S$ZErx=1sP-95rLg*9vfg0Cp^aQ;lPf(*eO@5$H zm|#){%wbz#*~($1(4{bY+@7R(;6S(R%+BtufDz=$O6SQ+Pu*>JW8_nF!Kt~J7~Q8t z7&(iB$)qd}22N&fQc+0(0BN*fiRGpiMI}X^JhC`zfo!MILhpY)*oOq|){FqzqUr!} z`03bj9TI2I0#%Bh9$0+t`&fsbe*ZiOJ3e!5m7ChkAbec{0NQJZZ@Fh36Njl0vE0;x z1c*$+E{vr8JX7R#_^jRB!3+Rk8N8sqcIG<;Gytgn9|!gfZvEcSvfcZ57E$g?s8TJ=%f-Sv?iHUsyEdHeVhF3GLV1d2+EEXKfvO|rKY0R8~& WOu?jRn%n^Z0000!pAI literal 0 HcmV?d00001 diff --git a/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/break_prevention.json b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/break_prevention.json new file mode 100644 index 00000000..d6f1cabb --- /dev/null +++ b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/break_prevention.json @@ -0,0 +1,17 @@ +{ + "name": "Eir's Token", + "icon": "naturesaura:break_prevention", + "category": "items", + "advancement": "naturesaura:sky_ingot", + "pages": [ + { + "type": "text", + "text": "There are few things more unpleasant than one's favorite $(thing)tool$() breaking when it is needed most, removing the ability to even repair it and rendering all enchanting efforts useless. To mitigate this problem, $(item)Eir's Token$() can be applied to any tool using an $(thing)anvil$(). Any tools that have this token applied will, instead of breaking when their durability reaches zero, simply $(thing)stop functioning$() instead." + }, + { + "type": "naturesaura:tree_ritual", + "text": "Creating the $(item)Eir's Token$() using the $(l:practices/tree_ritual)Ritual of the Forest$()", + "recipe": "naturesaura:break_prevention" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/naturesaura/recipes/tree_ritual/break_prevention.json b/src/main/resources/data/naturesaura/recipes/tree_ritual/break_prevention.json new file mode 100644 index 00000000..2e0366de --- /dev/null +++ b/src/main/resources/data/naturesaura/recipes/tree_ritual/break_prevention.json @@ -0,0 +1,24 @@ +{ + "type": "naturesaura:tree_ritual", + "ingredients": [ + { + "item": "minecraft:diamond" + }, + { + "item": "naturesaura:tainted_gold" + }, + { + "item": "naturesaura:sky_ingot" + }, + { + "item": "naturesaura:token_fear" + } + ], + "sapling": { + "item": "minecraft:oak_sapling" + }, + "output": { + "item": "naturesaura:break_prevention" + }, + "time": 200 +} \ No newline at end of file