diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index d6b71d96..0d7224f9 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -180,32 +180,4 @@ public final class Helper { } }; } - - public static boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { - if (player.capabilities.isCreativeMode) - return true; - - if (Compat.baubles) { - IItemHandler baubles = BaublesApi.getBaublesHandler(player); - for (int i = 0; i < baubles.getSlots(); i++) { - ItemStack stack = baubles.getStackInSlot(i); - if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { - amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); - if (amount <= 0) - return true; - } - } - } - - for (int i = 0; i < player.inventory.getSizeInventory(); i++) { - ItemStack stack = player.inventory.getStackInSlot(i); - if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { - amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); - if (amount <= 0) - return true; - } - } - - return false; - } } diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 2a2444b6..b9622116 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -1,17 +1,51 @@ package de.ellpeck.naturesaura; +import baubles.api.BaublesApi; import de.ellpeck.naturesaura.api.NACapabilities; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.compat.Compat; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.items.IItemHandler; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableObject; import java.util.function.BiConsumer; public class InternalHooks implements NaturesAuraAPI.IInternalHooks { + @Override + public boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { + if (player.capabilities.isCreativeMode) + return true; + + if (Compat.baubles) { + IItemHandler baubles = BaublesApi.getBaublesHandler(player); + for (int i = 0; i < baubles.getSlots(); i++) { + ItemStack stack = baubles.getStackInSlot(i); + if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { + amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); + if (amount <= 0) + return true; + } + } + } + + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { + amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); + if (amount <= 0) + return true; + } + } + + return false; + } + @Override public void spawnMagicParticle(World world, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { NaturesAura.proxy.spawnMagicParticle(world, posX, posY, posZ, motionX, motionY, motionZ, color, scale, maxAge, gravity, collision, fade); diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index a070a667..8344bfb5 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -1,9 +1,11 @@ package de.ellpeck.naturesaura.api; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.internal.StubHooks; import de.ellpeck.naturesaura.api.recipes.AltarRecipe; import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -63,6 +65,20 @@ public final class NaturesAuraAPI { */ public interface IInternalHooks { + /** + * Helper method to extract aura from an {@link IAuraContainer} in the + * supplied player's inventory or baubles slots. The method returns true + * if the aura could be extracted. Note that, if the player is in + * creative mode, this method will always return true and no extraction + * will take place. + * + * @param player The player + * @param amount The amount to extract + * @param simulate If the extraction should be simulated + * @return If the extraction was successful + */ + boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate); + /** * This method can be used to spawn the magic particle effect used by * Nature's Aura. It will not have an effect on the client side, so if diff --git a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java index 3b820144..ff660be3 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java @@ -1,6 +1,7 @@ package de.ellpeck.naturesaura.api.internal; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.apache.commons.lang3.mutable.MutableInt; @@ -8,6 +9,11 @@ import org.apache.commons.lang3.mutable.MutableInt; import java.util.function.BiConsumer; public class StubHooks implements NaturesAuraAPI.IInternalHooks { + @Override + public boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { + return false; + } + @Override public void spawnMagicParticle(World world, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java index 7510e7b6..b970d468 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.items; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.reg.IColorProvidingItem; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; @@ -56,7 +57,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem { } } else { if (stored != null && stored != color) { - if (Helper.extractAuraFromPlayer(player, 10, world.isRemote)) { + if (NaturesAuraAPI.instance().extractAuraFromPlayer(player, 10, world.isRemote)) { if (firstColor == null) { world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java index 4108b18c..fe36b072 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.items; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.renderers.ITrinketItem; @@ -72,7 +73,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem { return; if (living.getDistanceSq(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F) return; - if (living instanceof EntityPlayer && !Helper.extractAuraFromPlayer((EntityPlayer) living, 10, false)) + if (living instanceof EntityPlayer && !NaturesAuraAPI.instance().extractAuraFromPlayer((EntityPlayer) living, 10, false)) return; DamageSource source; @@ -90,7 +91,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem { continue; if (living.getDistanceSq(mob) > range * range) continue; - if (living instanceof EntityPlayer && !Helper.extractAuraFromPlayer((EntityPlayer) living, 5, false)) + if (living instanceof EntityPlayer && !NaturesAuraAPI.instance().extractAuraFromPlayer((EntityPlayer) living, 5, false)) break; mob.attackEntityFrom(source, 4F); }