2018-11-11 13:26:19 +01:00
|
|
|
package de.ellpeck.naturesaura.api.aura.chunk;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2018-11-11 13:26:19 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.world.IWorld;
|
2018-11-11 13:26:19 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
import net.minecraftforge.common.util.INBTSerializable;
|
|
|
|
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class whose instances hold information about the aura present in any given
|
|
|
|
* {@link Chunk}. To get an instance for a chunk, use {@link
|
2020-01-21 21:04:44 +01:00
|
|
|
* #getAuraChunk(IWorld, BlockPos)}.
|
2018-11-11 13:26:19 +01:00
|
|
|
* <p>
|
|
|
|
* It is not intended for API users to create custom implementation of this
|
|
|
|
* class.
|
|
|
|
*/
|
2019-10-20 22:30:49 +02:00
|
|
|
public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
|
2018-11-11 13:26:19 +01:00
|
|
|
/**
|
|
|
|
* The default amount of Aura that a chunk has stored
|
|
|
|
*/
|
2019-01-29 11:46:38 +01:00
|
|
|
int DEFAULT_AURA = 1000000;
|
2018-11-11 13:26:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to get information about the Aura in any given chunk.
|
|
|
|
* This is a convenience method.
|
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos A position that the chunk contains
|
|
|
|
* @return The {@link IAuraChunk} instance belonging to the chunk
|
|
|
|
*/
|
2020-01-21 21:04:44 +01:00
|
|
|
static IAuraChunk getAuraChunk(IWorld world, BlockPos pos) {
|
|
|
|
Chunk chunk = (Chunk) world.getChunk(pos);
|
|
|
|
return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
|
2018-11-11 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method uses the supplied consumer to iterate over all the drain
|
|
|
|
* spots, represented as a position and the number of Aura in them, in any
|
|
|
|
* given area.
|
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @param consumer A consumer that gets given the position and amount of
|
|
|
|
* aura in each drain spot found
|
|
|
|
*/
|
2018-12-02 01:36:41 +01:00
|
|
|
static void getSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
|
2018-11-11 13:26:19 +01:00
|
|
|
NaturesAuraAPI.instance().getAuraSpotsInArea(world, pos, radius, consumer);
|
|
|
|
}
|
|
|
|
|
2019-02-15 17:51:26 +01:00
|
|
|
/**
|
|
|
|
* Convenience method that adds up the amount of aura spots from {@link
|
|
|
|
* #getSpotsInArea(World, BlockPos, int, BiConsumer)} and returns it.
|
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @return The amount of spots found in the area
|
|
|
|
*/
|
|
|
|
static int getSpotAmountInArea(World world, BlockPos pos, int radius) {
|
|
|
|
return NaturesAuraAPI.instance().getSpotAmountInArea(world, pos, radius);
|
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
/**
|
|
|
|
* Convenience method that adds up all of the aura from each drain spot from
|
|
|
|
* {@link #getSpotsInArea(World, BlockPos, int, BiConsumer)} and
|
2018-12-05 11:21:08 +01:00
|
|
|
* conveniently returns it. For a better visual display with a more gradual
|
|
|
|
* increase, use {@link #triangulateAuraInArea(World, BlockPos, int)}.
|
2018-11-11 13:26:19 +01:00
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @return The amount of Aura present in that area, based on the drain spots
|
|
|
|
* that are found
|
|
|
|
*/
|
|
|
|
static int getAuraInArea(World world, BlockPos pos, int radius) {
|
|
|
|
return NaturesAuraAPI.instance().getAuraInArea(world, pos, radius);
|
|
|
|
}
|
|
|
|
|
2018-12-05 11:21:08 +01:00
|
|
|
/**
|
|
|
|
* Convenience method that adds up all of the aura from each drain spot from
|
|
|
|
* {@link #getSpotsInArea(World, BlockPos, int, BiConsumer)}, but multiplies
|
|
|
|
* their amount by the percentual distance to the supplied position. This
|
|
|
|
* will cause for a lot more gradual of an increase and decrease of Aura
|
|
|
|
* when moving closer to actual spots. This should be used for visual
|
|
|
|
* purposes as it is more performance intensive than {@link
|
|
|
|
* #getAuraInArea(World, BlockPos, int)}.
|
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @return The amount of Aura presetn in that area, based on the drain spots
|
|
|
|
* that are found and their distance to the center
|
|
|
|
*/
|
|
|
|
static int triangulateAuraInArea(World world, BlockPos pos, int radius) {
|
|
|
|
return NaturesAuraAPI.instance().triangulateAuraInArea(world, pos, radius);
|
|
|
|
}
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
/**
|
|
|
|
* This method returns the position of the lowest drain spot (meaning the
|
|
|
|
* one that has the least Aura stored) in the given area. This should be
|
|
|
|
* used with any machines that fill up Aura in an area, so that the most
|
2018-11-17 12:27:28 +01:00
|
|
|
* drained spots get selected first. Note that, when there is no drain spot
|
|
|
|
* with an amount lower than 0, the default will always be returned.
|
2018-11-11 13:26:19 +01:00
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @param defaultSpot A position that will be used to create a new drain
|
|
|
|
* spot when none are found
|
|
|
|
* @return The position of the lowest drain spot
|
|
|
|
*/
|
|
|
|
static BlockPos getLowestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
|
|
|
return NaturesAuraAPI.instance().getLowestAuraDrainSpot(world, pos, radius, defaultSpot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method returns the position of the highest drain spot (meaning the
|
|
|
|
* one that has the most Aura stored) in the given area. This should be used
|
|
|
|
* with any machines that use up Aura so that the spots with the highest
|
2018-11-17 12:27:28 +01:00
|
|
|
* amount are drained first. Note that, when there is no drain spot with an
|
|
|
|
* amount greater than 0, the defautl will always be returned.
|
2018-11-11 13:26:19 +01:00
|
|
|
*
|
|
|
|
* @param world The world
|
|
|
|
* @param pos The center position
|
|
|
|
* @param radius The radius around the center to search for spots in
|
|
|
|
* @param defaultSpot A position that will be used to create a new drain
|
|
|
|
* spot when none are found
|
|
|
|
* @return The position of the highest drain spot
|
|
|
|
*/
|
2020-01-21 21:04:44 +01:00
|
|
|
static BlockPos getHighestSpot(IWorld world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
2018-11-11 13:26:19 +01:00
|
|
|
return NaturesAuraAPI.instance().getHighestAuraDrainSpot(world, pos, radius, defaultSpot);
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:34:57 +01:00
|
|
|
/**
|
|
|
|
* Drains the given amount of Aura from the given position. Returns the
|
|
|
|
* amount of Aura that was drained.
|
|
|
|
*
|
|
|
|
* @param pos The position
|
|
|
|
* @param amount The amount to drain
|
|
|
|
* @param aimForZero If true, and draining the given amount would make the
|
|
|
|
* level go from positive to negative, an amount will be
|
|
|
|
* drained instead that will cause the spot's amount to be
|
|
|
|
* 0.
|
|
|
|
* @return The amount of Aura drained. Will only be different from the
|
|
|
|
* supplied amount if stopAtZero is true
|
|
|
|
*/
|
2018-11-24 17:32:39 +01:00
|
|
|
int drainAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate);
|
2018-11-18 20:34:57 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-24 17:32:39 +01:00
|
|
|
* Convenience version of {@link #drainAura(BlockPos, int, boolean,
|
|
|
|
* boolean)} with aimForZero and simulate set to false, as this is the most
|
|
|
|
* likely behavior you will want. Notice that {@link #storeAura(BlockPos,
|
|
|
|
* int)} has aimForZero set to true.
|
2018-11-18 20:34:57 +01:00
|
|
|
*/
|
|
|
|
int drainAura(BlockPos pos, int amount);
|
2018-11-11 13:26:19 +01:00
|
|
|
|
2018-11-18 20:34:57 +01:00
|
|
|
/**
|
|
|
|
* Stores the given amount of Aura at the given position. Returns the amount
|
|
|
|
* of Aura that was stored.
|
|
|
|
*
|
|
|
|
* @param pos The position
|
|
|
|
* @param amount The amount to store
|
|
|
|
* @param aimForZero If true, and storing the given amount would make the
|
|
|
|
* level go from negative to positive, an amount will be
|
|
|
|
* stored instead that will cause the spot's amount to be
|
|
|
|
* 0.
|
|
|
|
* @return The amount of Aura stored. Will only be different from the
|
|
|
|
* supplied amount if stopAtZero is true
|
|
|
|
*/
|
2018-11-24 17:32:39 +01:00
|
|
|
int storeAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate);
|
2018-11-18 20:34:57 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-24 17:32:39 +01:00
|
|
|
* Convenience version of {@link #storeAura(BlockPos, int, boolean,
|
|
|
|
* boolean)} with aimForZero set to true and simulate set to false, as this
|
|
|
|
* is the most likely behavior you will want. Notice that {@link
|
|
|
|
* #drainAura(BlockPos, int)} has aimForZero set to false.
|
2018-11-18 20:34:57 +01:00
|
|
|
*/
|
|
|
|
int storeAura(BlockPos pos, int amount);
|
2018-11-11 13:26:19 +01:00
|
|
|
|
2018-12-02 01:36:41 +01:00
|
|
|
int getDrainSpot(BlockPos pos);
|
2018-11-11 13:26:19 +01:00
|
|
|
|
2018-11-12 01:29:33 +01:00
|
|
|
IAuraType getType();
|
2018-11-11 13:26:19 +01:00
|
|
|
|
|
|
|
void markDirty();
|
|
|
|
}
|