added aura mending

This commit is contained in:
Ellpeck 2020-01-25 19:18:45 +01:00
parent c59d7e610e
commit 386dec00d1
9 changed files with 141 additions and 15 deletions

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; 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.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
@ -189,12 +190,7 @@ public final class Helper {
return new ICapabilityProvider() { return new ICapabilityProvider() {
private final IAuraRecharge recharge = (container, containerSlot, itemSlot, isSelected) -> { private final IAuraRecharge recharge = (container, containerSlot, itemSlot, isSelected) -> {
if (isSelected || !needsSelected) { if (isSelected || !needsSelected) {
int toDrain = 300; return rechargeAuraItem(stack, container, 300);
if (stack.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) {
stack.setDamage(stack.getDamage() - 1);
container.drainAura(toDrain, false);
return true;
}
} }
return false; 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) { public static BlockState getStateFromString(String raw) {
String[] split = raw.split("\\["); String[] split = raw.split("\\[");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -13,6 +13,7 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter; import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.enchant.ModEnchantment;
import de.ellpeck.naturesaura.items.AuraCache; import de.ellpeck.naturesaura.items.AuraCache;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.items.RangeVisualizer; 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.AbstractGui;
import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; 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.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; 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.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeColors; import net.minecraft.world.biome.BiomeColors;
@ -50,6 +55,7 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
import net.minecraftforge.energy.EnergyStorage; import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -74,6 +80,23 @@ public class ClientEvents {
private float height; private float height;
private float previousHeight; private float previousHeight;
@SubscribeEvent
public void onTooltip(ItemTooltipEvent event) {
ItemStack stack = event.getItemStack();
List<ITextComponent> tooltip = event.getToolTip();
for (Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.getEnchantments(stack).entrySet()) {
Enchantment enchantment = entry.getKey();
if (!(enchantment instanceof ModEnchantment))
continue;
String info = I18n.format(enchantment.getName() + ".desc");
List<String> 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 @SubscribeEvent
public void onDebugRender(RenderGameOverlayEvent.Text event) { public void onDebugRender(RenderGameOverlayEvent.Text event) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.items; package de.ellpeck.naturesaura.items;
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; 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.container.ItemAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.render.ITrinketItem; import de.ellpeck.naturesaura.api.render.ITrinketItem;
import com.mojang.blaze3d.platform.GlStateManager; import de.ellpeck.naturesaura.enchant.ModEnchantments;
import net.minecraft.item.ItemGroup; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.world.World; 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.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; 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 net.minecraftforge.common.util.LazyOptional;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -46,11 +48,15 @@ public class AuraCache extends ItemImpl implements ITrinketItem {
} }
for (int i = 0; i < player.inventory.getSizeInventory(); i++) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i); ItemStack stack = player.inventory.getStackInSlot(i);
if (stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent()) {
IAuraRecharge recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null); IAuraRecharge recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null);
if (recharge.rechargeFromContainer(container, itemSlot, i, player.inventory.currentItem == i)) { 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; break;
}
} }
} }
} }

View file

@ -7,6 +7,8 @@ import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.blocks.*; import de.ellpeck.naturesaura.blocks.*;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityEnderCrate; 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.EntityEffectInhibitor;
import de.ellpeck.naturesaura.entities.EntityMoverMinecart; import de.ellpeck.naturesaura.entities.EntityMoverMinecart;
import de.ellpeck.naturesaura.entities.ModEntities; import de.ellpeck.naturesaura.entities.ModEntities;
@ -25,6 +27,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
@ -207,6 +210,14 @@ public final class ModRegistry {
Helper.populateObjectHolders(ModContainers.class, event.getRegistry()); Helper.populateObjectHolders(ModContainers.class, event.getRegistry());
} }
@SubscribeEvent
public static void registerEnchantments(RegistryEvent.Register<Enchantment> event) {
event.getRegistry().registerAll(
new AuraMendingEnchantment()
);
Helper.populateObjectHolders(ModEnchantments.class, event.getRegistry());
}
@SubscribeEvent @SubscribeEvent
public static void registerEntities(RegistryEvent.Register<EntityType<?>> event) { public static void registerEntities(RegistryEvent.Register<EntityType<?>> event) {
event.getRegistry().registerAll( event.getRegistry().registerAll(

View file

@ -167,5 +167,7 @@
"command.naturesaura.aura.usage": "/naaura store|drain <amount> [range] OR /naaura reset <range>", "command.naturesaura.aura.usage": "/naaura store|drain <amount> [range] OR /naaura reset <range>",
"effect.naturesaura.breathless": "Breathless", "effect.naturesaura.breathless": "Breathless",
"entity.naturesaura.effect_inhibitor": "Effect Powder", "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"
} }

View file

@ -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."
}
]
}