made the API instance be set internally

This commit is contained in:
Ell 2020-09-26 13:49:23 +02:00
parent 43481bda17
commit b280ede21e
3 changed files with 12 additions and 18 deletions

View file

@ -62,7 +62,6 @@ public final class NaturesAura {
}
private void preInit(FMLCommonSetupEvent event) {
NaturesAuraAPI.setInstance(new InternalHooks());
Helper.registerCap(IAuraContainer.class);
Helper.registerCap(IAuraRecharge.class);
Helper.registerCap(IAuraChunk.class);

View file

@ -20,7 +20,6 @@ import net.minecraft.util.Tuple;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.DimensionType;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
@ -124,28 +123,24 @@ public final class NaturesAuraAPI {
*/
@CapabilityInject(IWorldData.class)
public static Capability<IWorldData> capWorldData;
private static IInternalHooks instance;
private static final IInternalHooks INSTANCE;
static {
try {
INSTANCE = (IInternalHooks) Class.forName("de.ellpeck.naturesaura.InternalHooks").newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
/**
* This method returns the active {@link IInternalHooks} instance which can
* be used to hook into the mod's internal functionalities.This will be
* overriden to a proper implementation. If you want to use this instance,
* use it after Nature's Aura's preInit phase.
* be used to hook into the mod's internal functionalities.
*
* @return The active {@link IInternalHooks} instance
*/
public static IInternalHooks instance() {
return instance;
}
/**
* This is an internal function. Do not use.
*/
public static void setInstance(IInternalHooks inst) {
if (instance == null)
instance = inst;
else
throw new IllegalStateException();
return INSTANCE;
}
/**

View file

@ -14,7 +14,7 @@ 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
* #getAuraChunk(World, BlockPos)}.
* #getAuraChunk(IWorld, BlockPos)}.
* <p>
* It is not intended for API users to create custom implementation of this
* class.