mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
moved extractAuraFromPlayer to the API for convenience
This commit is contained in:
parent
dd126df00c
commit
d2531e1d8a
6 changed files with 61 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue