2018-11-11 13:26:19 +01:00
|
|
|
package de.ellpeck.naturesaura;
|
|
|
|
|
2018-11-11 22:58:58 +01:00
|
|
|
import baubles.api.BaublesApi;
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2018-11-11 22:58:58 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.Compat;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-11-11 13:26:19 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2018-11-11 22:58:58 +01:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
2018-11-11 13:26:19 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
|
|
|
import org.apache.commons.lang3.mutable.MutableObject;
|
2018-11-13 00:36:47 +01:00
|
|
|
import org.lwjgl.util.vector.Vector3f;
|
2018-11-11 13:26:19 +01:00
|
|
|
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
|
|
public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
2018-11-11 22:58:58 +01:00
|
|
|
@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);
|
2018-11-12 22:04:40 +01:00
|
|
|
if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
|
|
|
|
amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate);
|
2018-11-11 22:58:58 +01:00
|
|
|
if (amount <= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
|
|
|
ItemStack stack = player.inventory.getStackInSlot(i);
|
2018-11-12 22:04:40 +01:00
|
|
|
if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
|
|
|
|
amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate);
|
2018-11-11 22:58:58 +01:00
|
|
|
if (amount <= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
@Override
|
2018-11-13 00:36:47 +01:00
|
|
|
public void spawnMagicParticle(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(posX, posY, posZ, motionX, motionY, motionZ, color, scale, maxAge, gravity, collision, fade);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
|
|
|
|
Vector3f dir = new Vector3f(endX - startX, endY - startY, endZ - startZ);
|
|
|
|
if (dir.length() > 0) {
|
|
|
|
int maxAge = (int) (dir.length() / speed);
|
|
|
|
dir.normalise();
|
|
|
|
|
|
|
|
this.spawnMagicParticle(startX, startY, startZ,
|
|
|
|
dir.x * speed, dir.y * speed, dir.z * speed,
|
|
|
|
color, scale, maxAge, 0F, false, false);
|
|
|
|
}
|
2018-11-11 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer) {
|
|
|
|
world.profiler.func_194340_a(() -> NaturesAura.MOD_ID + ":getSpotsInArea");
|
|
|
|
for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) {
|
|
|
|
for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) {
|
|
|
|
if (Helper.isChunkLoaded(world, x, z)) {
|
|
|
|
Chunk chunk = world.getChunk(x, z);
|
2018-11-12 22:04:40 +01:00
|
|
|
if (chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
|
|
|
|
IAuraChunk auraChunk = chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
|
2018-11-11 13:26:19 +01:00
|
|
|
auraChunk.getSpotsInArea(pos, radius, consumer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
world.profiler.endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getAuraInArea(World world, BlockPos pos, int radius) {
|
|
|
|
MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA);
|
|
|
|
this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot.intValue()));
|
|
|
|
return result.intValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
|
|
|
MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
|
|
|
MutableObject<BlockPos> lowestSpot = new MutableObject<>();
|
|
|
|
this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
|
|
|
int amount = drainSpot.intValue();
|
|
|
|
if (amount < lowestAmount.intValue()) {
|
|
|
|
lowestAmount.setValue(amount);
|
|
|
|
lowestSpot.setValue(blockPos);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
BlockPos lowest = lowestSpot.getValue();
|
2018-11-17 12:27:28 +01:00
|
|
|
if (lowest == null || lowestAmount.intValue() >= 0)
|
2018-11-11 13:26:19 +01:00
|
|
|
lowest = defaultSpot;
|
|
|
|
return lowest;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
|
|
|
MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE);
|
|
|
|
MutableObject<BlockPos> highestSpot = new MutableObject<>();
|
|
|
|
this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
|
|
|
int amount = drainSpot.intValue();
|
|
|
|
if (amount > highestAmount.intValue()) {
|
|
|
|
highestAmount.setValue(amount);
|
|
|
|
highestSpot.setValue(blockPos);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
BlockPos highest = highestSpot.getValue();
|
2018-11-17 12:27:28 +01:00
|
|
|
if (highest == null || highestAmount.intValue() <= 0)
|
2018-11-11 13:26:19 +01:00
|
|
|
highest = defaultSpot;
|
|
|
|
return highest;
|
|
|
|
}
|
|
|
|
}
|