diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 2e377d1a..36482ff4 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura; import com.mojang.blaze3d.platform.GlStateManager; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import de.ellpeck.naturesaura.chunk.AuraChunk; @@ -189,12 +190,7 @@ public final class Helper { return new ICapabilityProvider() { private final IAuraRecharge recharge = (container, containerSlot, itemSlot, isSelected) -> { if (isSelected || !needsSelected) { - int toDrain = 300; - if (stack.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) { - stack.setDamage(stack.getDamage() - 1); - container.drainAura(toDrain, false); - return true; - } + return rechargeAuraItem(stack, container, 300); } return false; }; @@ -209,6 +205,15 @@ public final class Helper { }; } + public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container, int toDrain) { + if (stack.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) { + stack.setDamage(stack.getDamage() - 1); + container.drainAura(toDrain, false); + return true; + } + return false; + } + public static BlockState getStateFromString(String raw) { String[] split = raw.split("\\["); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); diff --git a/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java b/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java new file mode 100644 index 00000000..c7964991 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java @@ -0,0 +1,30 @@ +package de.ellpeck.naturesaura.enchant; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.inventory.EquipmentSlotType; +import net.minecraft.item.ItemStack; + +public class AuraMendingEnchantment extends ModEnchantment { + + public AuraMendingEnchantment() { + super("aura_mending", Rarity.RARE, EnchantmentType.ALL, EquipmentSlotType.values()); + } + + @Override + protected boolean canApplyTogether(Enchantment ench) { + return super.canApplyTogether(ench) && ench != Enchantments.MENDING; + } + + @Override + public boolean canApply(ItemStack stack) { + return super.canApply(stack) && !stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent(); + } + + @Override + public int getMaxLevel() { + return 1; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantment.java b/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantment.java new file mode 100644 index 00000000..1f14d47d --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantment.java @@ -0,0 +1,23 @@ +package de.ellpeck.naturesaura.enchant; + +import de.ellpeck.naturesaura.reg.IModItem; +import de.ellpeck.naturesaura.reg.ModRegistry; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.inventory.EquipmentSlotType; + +public class ModEnchantment extends Enchantment implements IModItem { + + private final String name; + + protected ModEnchantment(String name, Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType[] slots) { + super(rarityIn, typeIn, slots); + this.name = name; + ModRegistry.add(this); + } + + @Override + public String getBaseName() { + return this.name; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantments.java b/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantments.java new file mode 100644 index 00000000..4eb383c5 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/enchant/ModEnchantments.java @@ -0,0 +1,10 @@ +package de.ellpeck.naturesaura.enchant; + +import net.minecraft.enchantment.Enchantment; + +@SuppressWarnings("FieldNamingConvention") +public final class ModEnchantments { + + public static Enchantment AURA_MENDING; + +} diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index e85a5bbb..6fc0470e 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -13,6 +13,7 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute; import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter; import de.ellpeck.naturesaura.compat.Compat; +import de.ellpeck.naturesaura.enchant.ModEnchantment; import de.ellpeck.naturesaura.items.AuraCache; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.RangeVisualizer; @@ -27,6 +28,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.resources.I18n; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -37,6 +40,8 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeColors; @@ -50,6 +55,7 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.common.IPlantable; import net.minecraftforge.energy.EnergyStorage; import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.apache.commons.lang3.mutable.MutableInt; import org.lwjgl.opengl.GL11; @@ -74,6 +80,23 @@ public class ClientEvents { private float height; private float previousHeight; + @SubscribeEvent + public void onTooltip(ItemTooltipEvent event) { + ItemStack stack = event.getItemStack(); + List tooltip = event.getToolTip(); + for (Map.Entry entry : EnchantmentHelper.getEnchantments(stack).entrySet()) { + Enchantment enchantment = entry.getKey(); + if (!(enchantment instanceof ModEnchantment)) + continue; + String info = I18n.format(enchantment.getName() + ".desc"); + List split = Minecraft.getInstance().fontRenderer.listFormattedStringToWidth(info, 250); + ITextComponent name = enchantment.getDisplayName(entry.getValue()); + int addIndex = tooltip.indexOf(name) + 1; + for (int i = split.size() - 1; i >= 0; i--) + tooltip.add(addIndex, new StringTextComponent(TextFormatting.DARK_GRAY + split.get(i))); + } + } + @SubscribeEvent public void onDebugRender(RenderGameOverlayEvent.Text event) { Minecraft mc = Minecraft.getInstance(); diff --git a/src/main/java/de/ellpeck/naturesaura/items/AuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/AuraCache.java index eccffcd5..7df2c693 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/AuraCache.java +++ b/src/main/java/de/ellpeck/naturesaura/items/AuraCache.java @@ -1,5 +1,6 @@ package de.ellpeck.naturesaura.items; +import com.mojang.blaze3d.platform.GlStateManager; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; @@ -7,20 +8,21 @@ import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.ItemAuraContainer; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.render.ITrinketItem; -import com.mojang.blaze3d.platform.GlStateManager; -import net.minecraft.item.ItemGroup; +import de.ellpeck.naturesaura.enchant.ModEnchantments; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.EquipmentSlotType; +import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.NonNullList; import net.minecraft.world.World; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; @@ -46,11 +48,15 @@ public class AuraCache extends ItemImpl implements ITrinketItem { } for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack stack = player.inventory.getStackInSlot(i); - if (stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent()) { - IAuraRecharge recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null); - if (recharge.rechargeFromContainer(container, itemSlot, i, player.inventory.currentItem == i)) { + IAuraRecharge recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null); + if (recharge != null) { + if (recharge.rechargeFromContainer(container, itemSlot, i, player.inventory.currentItem == i)) + break; + } else if (EnchantmentHelper.getEnchantmentLevel(ModEnchantments.AURA_MENDING, stack) > 0) { + int mainSize = player.inventory.mainInventory.size(); + boolean isArmor = i >= mainSize && i < mainSize + player.inventory.armorInventory.size(); + if ((isArmor || player.inventory.currentItem == i) && Helper.rechargeAuraItem(stack, container, 1000)) break; - } } } } diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index ddebfa07..3a241a9c 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -7,6 +7,8 @@ import de.ellpeck.naturesaura.api.misc.IWorldData; import de.ellpeck.naturesaura.blocks.*; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.TileEntityEnderCrate; +import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment; +import de.ellpeck.naturesaura.enchant.ModEnchantments; import de.ellpeck.naturesaura.entities.EntityEffectInhibitor; import de.ellpeck.naturesaura.entities.EntityMoverMinecart; import de.ellpeck.naturesaura.entities.ModEntities; @@ -25,6 +27,7 @@ import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.data.DataGenerator; +import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.inventory.EquipmentSlotType; @@ -207,6 +210,14 @@ public final class ModRegistry { Helper.populateObjectHolders(ModContainers.class, event.getRegistry()); } + @SubscribeEvent + public static void registerEnchantments(RegistryEvent.Register event) { + event.getRegistry().registerAll( + new AuraMendingEnchantment() + ); + Helper.populateObjectHolders(ModEnchantments.class, event.getRegistry()); + } + @SubscribeEvent public static void registerEntities(RegistryEvent.Register> event) { event.getRegistry().registerAll( diff --git a/src/main/resources/assets/naturesaura/lang/en_us.json b/src/main/resources/assets/naturesaura/lang/en_us.json index 13913b67..20240c7d 100644 --- a/src/main/resources/assets/naturesaura/lang/en_us.json +++ b/src/main/resources/assets/naturesaura/lang/en_us.json @@ -167,5 +167,7 @@ "command.naturesaura.aura.usage": "/naaura store|drain [range] OR /naaura reset ", "effect.naturesaura.breathless": "Breathless", "entity.naturesaura.effect_inhibitor": "Effect Powder", - "entity.naturesaura.mover_cart": "Aura Attraction Cart" + "entity.naturesaura.mover_cart": "Aura Attraction Cart", + "enchantment.naturesaura.aura_mending": "Nature's Mend", + "enchantment.naturesaura.aura_mending.desc": "Nature's Aura Enchantment" } \ No newline at end of file diff --git a/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/using/aura_mending.json b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/using/aura_mending.json new file mode 100644 index 00000000..76477404 --- /dev/null +++ b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/using/aura_mending.json @@ -0,0 +1,16 @@ +{ + "name": "Nature's Mend", + "icon": "minecraft:enchanted_book", + "category": "using", + "advancement": "naturesaura:infused_tools", + "pages": [ + { + "type": "text", + "text": "Having gained knowledge of the powers of $(l:items/infused_iron_tools)Infused Iron tools$(), one could wish for a certain one of these abilities to be applied to other tools, specifically their Aura-aided $(thing)repairing$(). The $(item)Nature's Mend$() enchantment gives any tool or armor piece the ability to be repaired, as long as the user is carrying an $(l:items/aura_cache)Aura Cache$() or similar storage device." + }, + { + "type": "text", + "text": "For tools to be repaired, the additional requirement of $(thing)sneaking$() while holding the item has to be met as well.$(p)It should be noted that, while not being exceedingly rare, this enchantment has a similar chance of appearing as, say, the $(item)Looting$() enchantment." + } + ] +} \ No newline at end of file