2018-11-11 13:26:19 +01:00
|
|
|
package de.ellpeck.naturesaura;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2018-12-14 13:51:08 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
2019-02-21 12:27:54 +01:00
|
|
|
import de.ellpeck.naturesaura.api.misc.IWorldData;
|
2018-11-23 19:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
|
|
|
|
import de.ellpeck.naturesaura.blocks.multi.Multiblock;
|
2018-11-11 22:58:58 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.Compat;
|
2019-02-21 12:27:54 +01:00
|
|
|
import de.ellpeck.naturesaura.misc.WorldData;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2018-11-11 22:58:58 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2018-11-23 19:21:52 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-02-20 23:49:21 +01:00
|
|
|
import net.minecraft.util.Tuple;
|
2018-12-14 00:47:01 +01:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2018-11-11 13:26:19 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-01-28 14:58:08 +01:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.world.IWorld;
|
2018-11-11 13:26:19 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-12-05 11:21:08 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableFloat;
|
2018-11-11 13:26:19 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
|
|
|
import org.apache.commons.lang3.mutable.MutableObject;
|
|
|
|
|
2019-02-21 12:27:54 +01:00
|
|
|
import java.util.ArrayList;
|
2018-12-14 00:47:01 +01:00
|
|
|
import java.util.List;
|
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
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean extractAuraFromPlayer(PlayerEntity player, int amount, boolean simulate) {
|
2018-12-14 13:51:08 +01:00
|
|
|
return this.auraPlayerInteraction(player, amount, true, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean insertAuraIntoPlayer(PlayerEntity player, int amount, boolean simulate) {
|
2018-12-14 13:51:08 +01:00
|
|
|
return this.auraPlayerInteraction(player, amount, false, simulate);
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private boolean auraPlayerInteraction(PlayerEntity player, int amount, boolean extract, boolean simulate) {
|
2019-11-04 19:08:49 +01:00
|
|
|
if (extract && player.isCreative())
|
2018-11-11 22:58:58 +01:00
|
|
|
return true;
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
if (Compat.baubles) { // Baubles dont exist for 1.14 yet
|
|
|
|
/*
|
2018-11-11 22:58:58 +01:00
|
|
|
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)) {
|
2018-12-14 13:51:08 +01:00
|
|
|
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null);
|
|
|
|
if (extract)
|
|
|
|
amount -= container.drainAura(amount, simulate);
|
|
|
|
else
|
|
|
|
amount -= container.storeAura(amount, simulate);
|
2018-11-11 22:58:58 +01:00
|
|
|
if (amount <= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
*/
|
2018-11-11 22:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
|
|
|
ItemStack stack = player.inventory.getStackInSlot(i);
|
2019-11-04 19:08:49 +01:00
|
|
|
if (!stack.isEmpty() && stack.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) {
|
|
|
|
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null);
|
2018-12-14 13:51:08 +01:00
|
|
|
if (extract)
|
|
|
|
amount -= container.drainAura(amount, simulate);
|
|
|
|
else
|
|
|
|
amount -= container.storeAura(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) {
|
2019-11-04 19:08:49 +01:00
|
|
|
Vec3d dir = new Vec3d(endX - startX, endY - startY, endZ - startZ);
|
|
|
|
double length = dir.length();
|
2019-03-31 14:17:29 +02:00
|
|
|
if (length > 0) {
|
2019-11-04 19:08:49 +01:00
|
|
|
dir.normalize();
|
2018-11-13 00:36:47 +01:00
|
|
|
this.spawnMagicParticle(startX, startY, startZ,
|
|
|
|
dir.x * speed, dir.y * speed, dir.z * speed,
|
2019-03-31 14:17:29 +02:00
|
|
|
color, scale, (int) (length / speed), 0F, false, false);
|
2018-11-13 00:36:47 +01:00
|
|
|
}
|
2018-11-11 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 17:23:03 +01:00
|
|
|
@Override
|
|
|
|
public void setParticleDepth(boolean depth) {
|
|
|
|
NaturesAura.proxy.setParticleDepth(depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setParticleSpawnRange(int range) {
|
|
|
|
NaturesAura.proxy.setParticleSpawnRange(range);
|
|
|
|
}
|
|
|
|
|
2018-11-23 19:21:52 +01:00
|
|
|
@Override
|
|
|
|
public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
|
|
|
|
return new Multiblock(name, pattern, rawMatchers);
|
|
|
|
}
|
|
|
|
|
2018-12-14 00:47:01 +01:00
|
|
|
@Override
|
2019-02-21 12:27:54 +01:00
|
|
|
public List<Tuple<Vec3d, Integer>> getActiveEffectPowders(World world, AxisAlignedBB area, ResourceLocation name) {
|
|
|
|
List<Tuple<Vec3d, Integer>> found = new ArrayList<>();
|
|
|
|
for (Tuple<Vec3d, Integer> powder : ((WorldData) IWorldData.getWorldData(world)).effectPowders.get(name))
|
2020-01-21 23:02:39 +01:00
|
|
|
if (area.contains(powder.getA()))
|
2019-02-21 12:27:54 +01:00
|
|
|
found.add(powder);
|
|
|
|
return found;
|
2019-02-20 23:49:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) {
|
2019-02-21 12:27:54 +01:00
|
|
|
Vec3d posVec = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
|
|
|
List<Tuple<Vec3d, Integer>> powders = this.getActiveEffectPowders(world, new AxisAlignedBB(pos).grow(64), name);
|
|
|
|
for (Tuple<Vec3d, Integer> powder : powders) {
|
2020-01-21 23:02:39 +01:00
|
|
|
AxisAlignedBB bounds = Helper.aabb(powder.getA()).grow(powder.getB());
|
|
|
|
if (bounds.contains(posVec))
|
2019-02-20 23:49:21 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-12-14 00:47:01 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
@Override
|
2018-12-02 01:36:41 +01:00
|
|
|
public void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
|
2019-02-09 21:55:40 +01:00
|
|
|
Helper.getAuraChunksInArea(world, pos, radius, chunk -> chunk.getSpotsInArea(pos, radius, consumer));
|
2018-11-11 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 17:51:26 +01:00
|
|
|
@Override
|
|
|
|
public int getSpotAmountInArea(World world, BlockPos pos, int radius) {
|
|
|
|
MutableInt result = new MutableInt();
|
|
|
|
this.getAuraSpotsInArea(world, pos, radius, (blockpos, drainSpot) -> result.increment());
|
|
|
|
return result.intValue();
|
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
@Override
|
|
|
|
public int getAuraInArea(World world, BlockPos pos, int radius) {
|
|
|
|
MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA);
|
2018-12-02 01:36:41 +01:00
|
|
|
this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot));
|
2018-11-11 13:26:19 +01:00
|
|
|
return result.intValue();
|
|
|
|
}
|
|
|
|
|
2018-12-05 11:21:08 +01:00
|
|
|
@Override
|
|
|
|
public int triangulateAuraInArea(World world, BlockPos pos, int radius) {
|
|
|
|
MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA);
|
|
|
|
IAuraChunk.getSpotsInArea(world, pos, radius, (blockPos, spot) -> {
|
2020-01-21 23:02:39 +01:00
|
|
|
float percentage = 1F - (float) Math.sqrt(pos.distanceSq(blockPos)) / radius;
|
2018-12-05 11:21:08 +01:00
|
|
|
result.add(spot * percentage);
|
|
|
|
});
|
|
|
|
return result.intValue();
|
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
@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) -> {
|
2018-12-02 01:36:41 +01:00
|
|
|
if (drainSpot < lowestAmount.intValue()) {
|
|
|
|
lowestAmount.setValue(drainSpot);
|
2018-11-11 13:26:19 +01:00
|
|
|
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) -> {
|
2018-12-02 01:36:41 +01:00
|
|
|
if (drainSpot > highestAmount.intValue()) {
|
|
|
|
highestAmount.setValue(drainSpot);
|
2018-11-11 13:26:19 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|