NaturesAura/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java

265 lines
14 KiB
Java
Raw Normal View History

2018-11-11 13:26:19 +01:00
package de.ellpeck.naturesaura.api;
2019-02-01 17:42:59 +01:00
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
2018-11-12 22:04:40 +01:00
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.api.misc.ILevelData;
2020-10-24 15:58:38 +02:00
import de.ellpeck.naturesaura.api.misc.WeatherType;
2020-04-29 16:38:50 +02:00
import de.ellpeck.naturesaura.api.misc.WeightedOre;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.api.multiblock.Matcher;
2021-12-04 15:40:09 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
2019-02-20 23:49:21 +01:00
import net.minecraft.util.Tuple;
2021-12-04 15:40:09 +01:00
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
2018-11-12 22:04:40 +01:00
import net.minecraftforge.common.capabilities.Capability;
2021-12-04 15:40:09 +01:00
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import org.apache.commons.lang3.tuple.Pair;
2018-11-11 13:26:19 +01:00
import java.util.ArrayList;
2018-11-11 13:26:19 +01:00
import java.util.HashMap;
import java.util.List;
2018-11-11 13:26:19 +01:00
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
2018-11-11 13:26:19 +01:00
/**
2023-02-15 23:52:52 +01:00
* The main class of the Nature's Aura API. This is where you can find recipe lists and the {@link IInternalHooks} instance, which can be used to hook into internal mod functions not exposed to the API.
2018-11-11 13:26:19 +01:00
*/
public final class NaturesAuraAPI {
2018-11-17 21:54:04 +01:00
public static final String MOD_ID = "naturesaura";
2021-12-23 13:27:52 +01:00
/**
2023-02-15 23:52:52 +01:00
* A map of all the block states that the Botanist's Pickaxe can convert into their mossy variations. Contains mossy brick and mossy cobblestone by default, along with all blocks specified in the config file
*/
2019-10-20 22:30:49 +02:00
public static final BiMap<BlockState, BlockState> BOTANIST_PICKAXE_CONVERSIONS = HashBiMap.create();
/**
2023-02-15 23:52:52 +01:00
* A map of all {@link IAuraType} instances which are types of Aura present in different types of levels. {@link BasicAuraType} instances can be easily registered using {@link BasicAuraType#register()}.
*/
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
2022-06-27 15:24:04 +02:00
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "overworld"), Level.OVERWORLD, 0x89cc37, 0).register();
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "nether"), Level.NETHER, 0x871c0c, 0).register();
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "end"), Level.END, 0x302624, 0).register();
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();
/**
2023-02-15 23:52:52 +01:00
* A map of all {@link IDrainSpotEffect} suppliers which are effects that happen passively at every spot that Aura has been drained from in the level. These effects include things like vegetational increase and natural decay. To register your own drain spot effects, just add a supplier for them to this map, and they will automatically be executed once a second for every drain spot currently loaded.
*/
public static final Map<ResourceLocation, Supplier<IDrainSpotEffect>> DRAIN_SPOT_EFFECTS = new HashMap<>();
/**
2023-02-15 23:52:52 +01:00
* A map of all effect powder type. The integer the effect is registered to is the color that the powder and its effect should have. To check if a powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(Level, BlockPos, ResourceLocation)}
*/
public static final Map<ResourceLocation, Integer> EFFECT_POWDERS = new HashMap<>();
/**
2023-02-15 23:52:52 +01:00
* A map of all {@link IMultiblock} objects which are multiblock structures that can easily be looped through and checked, and also easily created using the multiblock maker debug tool.
*/
public static final Map<ResourceLocation, IMultiblock> MULTIBLOCKS = new HashMap<>();
2019-02-20 23:49:21 +01:00
/**
2023-02-15 23:52:52 +01:00
* A list of all {@link WeightedOre} objects that represent ores that can spawn inside of stone blocks in the overworld
2019-02-20 23:49:21 +01:00
*/
public static final List<WeightedOre> OVERWORLD_ORES = new ArrayList<>();
/**
2023-02-15 23:52:52 +01:00
* A list of all {@link WeightedOre} objects that represent ores that can spawn inside netherrack blocks in the nether
2019-02-20 23:49:21 +01:00
*/
public static final List<WeightedOre> NETHER_ORES = new ArrayList<>();
2019-03-12 19:34:59 +01:00
/**
2023-02-15 23:52:52 +01:00
* A map of all the entities' registry names to the amounts of aura they each generate in the projectile generator
2019-03-12 19:34:59 +01:00
*/
2021-12-04 15:40:09 +01:00
public static final Map<EntityType<?>, Integer> PROJECTILE_GENERATIONS = new HashMap<>();
2020-10-24 15:58:38 +02:00
/**
2023-02-15 23:52:52 +01:00
* A map of all the items that cause the {@link WeatherType} to be changed using the weather changer
2020-10-24 15:58:38 +02:00
*/
public static final Map<ItemStack, WeatherType> WEATHER_CHANGER_CONVERSIONS = new HashMap<>();
2018-11-12 22:04:40 +01:00
/**
2023-02-15 23:52:52 +01:00
* The capability for any item or block that stores Aura in the form of an {@link IAuraContainer}
2018-11-12 22:04:40 +01:00
*/
2021-12-23 13:27:52 +01:00
public static final Capability<IAuraContainer> CAP_AURA_CONTAINER = CapabilityManager.get(new CapabilityToken<>() {
2021-12-04 15:40:09 +01:00
});
2018-11-12 22:04:40 +01:00
/**
2023-02-15 23:52:52 +01:00
* The capability for any item that can be recharged from an Aura storage container like the Aura Cache in the form of {@link IAuraRecharge} by a player holding it in their hand
2018-11-12 22:04:40 +01:00
*/
2021-12-23 13:27:52 +01:00
public static final Capability<IAuraRecharge> CAP_AURA_RECHARGE = CapabilityManager.get(new CapabilityToken<>() {
2021-12-04 15:40:09 +01:00
});
2018-11-12 22:04:40 +01:00
/**
2023-02-15 23:52:52 +01:00
* The capability that any chunk in a level has to store Aura in it. As this is only applicable to chunks and all chunks in the level automatically get assigned this capability, using it directly is not necessary for addon developers. To retrieve this capability from any chunk, use the helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, BlockPos)}.
2018-11-12 22:04:40 +01:00
*/
2021-12-23 13:27:52 +01:00
public static final Capability<IAuraChunk> CAP_AURA_CHUNK = CapabilityManager.get(new CapabilityToken<>() {
2021-12-04 15:40:09 +01:00
});
2019-02-17 22:51:05 +01:00
/**
2023-02-15 23:52:52 +01:00
* The capability that any level has to store Nature's Aura specific data in it. To retrieve this capability from any level, use the helper methods {@link ILevelData#getLevelData(net.minecraft.world.level.Level)} or {@link ILevelData#getOverworldData(net.minecraft.world.level.Level)}.
2019-02-17 22:51:05 +01:00
*/
2021-12-23 13:27:52 +01:00
public static final Capability<ILevelData> CAP_LEVEL_DATA = CapabilityManager.get(new CapabilityToken<>() {
2021-12-04 15:40:09 +01:00
});
private static final IInternalHooks INSTANCE;
static {
try {
2021-12-23 13:27:52 +01:00
INSTANCE = (IInternalHooks) Class.forName("de.ellpeck.naturesaura.InternalHooks").getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
2018-11-12 22:04:40 +01:00
2018-11-11 13:26:19 +01:00
/**
2023-02-15 23:52:52 +01:00
* This method returns the active {@link IInternalHooks} instance which can be used to hook into the mod's internal functionalities.
2018-11-11 13:26:19 +01:00
*
* @return The active {@link IInternalHooks} instance
*/
public static IInternalHooks instance() {
2022-06-27 15:24:04 +02:00
return NaturesAuraAPI.INSTANCE;
2018-11-11 13:26:19 +01:00
}
/**
* @see #instance()
*/
public interface IInternalHooks {
/**
2023-02-15 23:52:52 +01:00
* 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
*/
2021-12-04 15:40:09 +01:00
boolean extractAuraFromPlayer(Player player, int amount, boolean simulate);
/**
2023-02-15 23:52:52 +01:00
* Helper method to insert aura into an {@link IAuraContainer} in the supplied player's inventory or baubles slots. The method returns true if the aura could be inserted.
*
* @param player The player
* @param amount The amount to insert
* @param simulate If the insertion should be simulated
* @return If the insertion was successful
*/
2021-12-04 15:40:09 +01:00
boolean insertAuraIntoPlayer(Player player, int amount, boolean simulate);
2018-11-11 13:26:19 +01:00
/**
2023-02-15 23:52:52 +01:00
* 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 you want to send it from the server side, you need to create your own packet.
2018-11-11 13:26:19 +01:00
*
* @param posX The x position
* @param posY The y position
* @param posZ The z position
* @param motionX The x motion
* @param motionY The y motion
* @param motionZ The z motion
* @param color The color the particle should have, in hex
* @param scale The scale of the particle
* @param maxAge The max age before the particle should die
2023-02-15 23:52:52 +01:00
* @param gravity The amount of gravity the particle should have, can be 0
2018-11-11 13:26:19 +01:00
* @param collision If the particle should collide with blocks
2023-02-15 23:52:52 +01:00
* @param fade If the particle should slowly fade out or suddenly disappear
2018-11-11 13:26:19 +01:00
*/
2018-11-13 00:36:47 +01:00
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);
/**
2023-02-15 23:52:52 +01:00
* This method can be used to spawn the magic particle effect used by Nature's Aura. The particle will be created to spawn at the start position and move towards the end position, dying when it reaches it. It will not have an effect on the client side, so if you want to send it from the server side, you need to create your own packet.
2018-11-13 00:36:47 +01:00
*
* @param startX The start x
* @param startY The start y
* @param startZ The start z
* @param endX The end x
* @param endY The end y
* @param endZ The end z
* @param speed The speed at which the particle should go
* @param color The color of the particle
* @param scale The scale of the particle
*/
void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale);
2018-11-11 13:26:19 +01:00
2019-02-19 17:23:03 +01:00
/**
2023-02-15 23:52:52 +01:00
* Sets wether Nature's Aura particles that are spawned will be rendered with depth test enabled or not. Default value is true, please reset after changing.
2019-02-19 17:23:03 +01:00
*
* @param depth Wether depth test should be enabled or not
*/
void setParticleDepth(boolean depth);
/**
2023-02-15 23:52:52 +01:00
* Sets the range that Nature's Aura particles that are spawned will have to have from the player at most to actually be spawned. Default value is 32, please reset after changing.
2019-02-19 17:23:03 +01:00
*
* @param range The range that particle spawning should have
*/
void setParticleSpawnRange(int range);
2020-02-28 15:36:12 +01:00
void setParticleCulling(boolean cull);
/**
2023-02-15 23:52:52 +01:00
* This method is used to create a custom multiblock from within the API. The multiblock will automatically be registered both to Nature's Aura's multiblock registry and Patchouli's multiblock registry.
*
* @param name The name the multiblock should have
2023-02-15 23:52:52 +01:00
* @param pattern The pattern that the multiblock should have, where each character is mapped to a raw matcher
* @param rawMatchers Each char matcher in the form of the char followed by a matcher, either in the form of a Block, an BlockState or a {@link Matcher}, similar to the old way that crafting recipes work.
* @return the multiblock instance
*/
IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers);
2019-02-20 23:49:21 +01:00
/**
2023-02-15 23:52:52 +01:00
* Get all the active effect powders in the given area and consume the position and the range that they have. To register a powder with the supplied name, use {@link #EFFECT_POWDERS}
2019-02-20 23:49:21 +01:00
*
2021-12-04 15:40:09 +01:00
* @param level The level
2019-02-20 23:49:21 +01:00
* @param area The area to find powders in
* @param name The registry name of the powder
* @return A list of powders' positions and ranges
*/
2021-12-04 15:40:09 +01:00
List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name);
2019-02-20 23:49:21 +01:00
/**
2023-02-15 23:52:52 +01:00
* Returns true if there is an effect powder entity active anywhere around the given position based on the radius it has. This is a shorthand function of {@link #getActiveEffectPowders(Level, net.minecraft.world.phys.AABB, ResourceLocation)} that returns true if the list is non-empty
*
2021-12-04 15:40:09 +01:00
* @param level The level
* @param pos The center position
* @param name The registry name of the powder
* @return If the effect is currently inhibited by any inhibitors
*/
2021-12-04 15:40:09 +01:00
boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getSpotsInArea(Level, BlockPos, int, BiConsumer)
2018-11-11 13:26:19 +01:00
*/
2021-12-04 15:40:09 +01:00
void getAuraSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getSpotAmountInArea(Level, BlockPos, int)
*/
2021-12-04 15:40:09 +01:00
int getSpotAmountInArea(Level level, BlockPos pos, int radius);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getAuraInArea(Level, BlockPos, int)
2018-11-11 13:26:19 +01:00
*/
2021-12-04 15:40:09 +01:00
int getAuraInArea(Level level, BlockPos pos, int radius);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getAuraAndSpotAmountInArea(Level, BlockPos, int)
*/
2021-12-04 15:40:09 +01:00
Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius);
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#triangulateAuraInArea(Level, BlockPos, int)
*/
2021-12-04 15:40:09 +01:00
int triangulateAuraInArea(Level level, BlockPos pos, int radius);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getLowestSpot(Level, BlockPos, int, BlockPos)
2018-11-11 13:26:19 +01:00
*/
2021-12-04 15:40:09 +01:00
BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot);
2018-11-11 13:26:19 +01:00
/**
2021-12-04 15:40:09 +01:00
* @see IAuraChunk#getHighestSpot(Level, BlockPos, int, BlockPos)
2018-11-11 13:26:19 +01:00
*/
2021-12-04 15:40:09 +01:00
BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot);
2018-11-11 13:26:19 +01:00
}
}