diff --git a/gradle.properties b/gradle.properties index 32c0d0a..23a53c0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G -version=1.0.1 -apiversion=1.0.1 +version=1.0.2 +apiversion=1.0.2 mcversion=1.12.2 forgeminversion=14.23.5.2768 forgeversion=14.23.5.2847 diff --git a/src/main/java/thecodex6824/auracontrol/AuraConfig.java b/src/main/java/thecodex6824/auracontrol/AuraConfig.java index 690d237..caaba49 100644 --- a/src/main/java/thecodex6824/auracontrol/AuraConfig.java +++ b/src/main/java/thecodex6824/auracontrol/AuraConfig.java @@ -54,16 +54,23 @@ private AuraConfig() {} @RequiresMcRestart public static String[] biomeList = {}; + @Name("ControlAura") + @Comment({ + "Whether the biome list should affect Aura generation." + }) + @RequiresMcRestart + public static boolean aura = true; + @Name("ControlCrystals") @Comment({ - "Whether the biome list should affect Vis Crystal generation, in addition to the aura." + "Whether the biome list should affect Vis Crystal generation." }) @RequiresMcRestart public static boolean crystals = false; @Name("ControlTrees") @Comment({ - "Whether the biome list should affect Thaumcraft tree generation, in addition to the aura." + "Whether the biome list should affect Thaumcraft tree generation." }) @RequiresMcRestart public static boolean trees = false; diff --git a/src/main/java/thecodex6824/auracontrol/AuraControl.java b/src/main/java/thecodex6824/auracontrol/AuraControl.java index 7471d7e..b71c28d 100644 --- a/src/main/java/thecodex6824/auracontrol/AuraControl.java +++ b/src/main/java/thecodex6824/auracontrol/AuraControl.java @@ -22,18 +22,35 @@ import java.util.Set; +import javax.annotation.Nullable; + import com.google.common.collect.ImmutableSet; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.Capability.IStorage; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import thecodex6824.auracontrol.api.AuraControlAPI; +import thecodex6824.auracontrol.api.CapabilityOriginalAuraInfo; +import thecodex6824.auracontrol.api.IOriginalAuraInfo; +import thecodex6824.auracontrol.api.OriginalAuraInfo; @Mod(modid = AuraControlAPI.MODID, name = AuraControlAPI.NAME, version = AuraControl.VERSION, useMetadata = true) +@EventBusSubscriber(modid = AuraControlAPI.MODID) public class AuraControl { public static final String VERSION = "@VERSION@"; @@ -43,6 +60,24 @@ public class AuraControl { @EventHandler public void preInit(FMLPreInitializationEvent event) { AuraControlAPI.setMethodHandler(new InternalMethodHandler()); + CapabilityManager.INSTANCE.register(IOriginalAuraInfo.class, new IStorage() { + @Override + public void readNBT(Capability capability, IOriginalAuraInfo instance, EnumFacing side, NBTBase nbt) { + if (!(instance instanceof OriginalAuraInfo) || !(nbt instanceof NBTTagCompound)) + throw new UnsupportedOperationException("Can't deserialize non-API implementation"); + + ((OriginalAuraInfo) instance).deserializeNBT((NBTTagCompound) nbt); + } + + @Override + @Nullable + public NBTBase writeNBT(Capability capability, IOriginalAuraInfo instance, EnumFacing side) { + if (!(instance instanceof OriginalAuraInfo)) + throw new UnsupportedOperationException("Can't serialize non-API implementation"); + + return ((OriginalAuraInfo) instance).serializeNBT(); + } + }, OriginalAuraInfo::new); } @EventHandler @@ -55,6 +90,7 @@ public void init(FMLInitializationEvent event) { else allowedBiomes.removeIf(b -> list.contains(b.getRegistryName().toString())); + AuraControlAPI.setHandleAuraGen(AuraConfig.aura); AuraControlAPI.setHandleCrystalGen(AuraConfig.crystals); AuraControlAPI.setHandleTreeGen(AuraConfig.trees); @@ -62,4 +98,10 @@ public void init(FMLInitializationEvent event) { GameRegistry.registerWorldGenerator(new AuraWorldGenerator(), 100000); } + @SubscribeEvent + public static void onAttachCapabilityChunk(AttachCapabilitiesEvent event) { + event.addCapability(new ResourceLocation(AuraControlAPI.NAME, "original_aura_info"), + new SimpleCapabilityProvider<>(new OriginalAuraInfo(), CapabilityOriginalAuraInfo.AURA_INFO)); + } + } diff --git a/src/main/java/thecodex6824/auracontrol/InternalMethodHandler.java b/src/main/java/thecodex6824/auracontrol/InternalMethodHandler.java index 2dc6aa7..063a371 100644 --- a/src/main/java/thecodex6824/auracontrol/InternalMethodHandler.java +++ b/src/main/java/thecodex6824/auracontrol/InternalMethodHandler.java @@ -37,6 +37,7 @@ public class InternalMethodHandler implements IInternalMethodHandler { protected HashSet allowedBiomes = new HashSet<>(); protected boolean crystalGen; protected boolean treeGen; + protected boolean auraGen; @Override public Set getAllowedBiomes() { @@ -45,12 +46,14 @@ public Set getAllowedBiomes() { @Override public void handleAura(World world, int chunkX, int chunkZ) { - Biome biome = world.getBiome(new BlockPos(chunkX * 16 + 8, 64, chunkZ * 16 + 8)); - if (!AuraControlAPI.getAllowedBiomes().contains(biome)) { - AuraChunk chunk = AuraHandler.getAuraChunk(world.provider.getDimension(), chunkX, chunkZ); - chunk.setBase((short) 0); - chunk.setVis(0.0F); - chunk.setFlux(0.0F); + if (auraGen) { + Biome biome = world.getBiome(new BlockPos(chunkX * 16 + 8, 64, chunkZ * 16 + 8)); + if (!AuraControlAPI.getAllowedBiomes().contains(biome)) { + AuraChunk chunk = AuraHandler.getAuraChunk(world.provider.getDimension(), chunkX, chunkZ); + chunk.setBase((short) 0); + chunk.setVis(0.0F); + chunk.setFlux(0.0F); + } } } @@ -69,6 +72,16 @@ public void setupTCWorldgenFlags(World world, int chunkX, int chunkZ) { } } + @Override + public boolean shouldHandleAuraGen() { + return auraGen; + } + + @Override + public void setHandleAuraGen(boolean allow) { + auraGen = allow; + } + @Override public boolean shouldHandleCrystalGen() { return crystalGen; diff --git a/src/main/java/thecodex6824/auracontrol/SimpleCapabilityProvider.java b/src/main/java/thecodex6824/auracontrol/SimpleCapabilityProvider.java new file mode 100644 index 0000000..41bf8b2 --- /dev/null +++ b/src/main/java/thecodex6824/auracontrol/SimpleCapabilityProvider.java @@ -0,0 +1,66 @@ +/** + * AuraControl + * Copyright (c) 2020 TheCodex6824. + * + * This file is part of AuraControl. + * + * AuraControl is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AuraControl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AuraControl. If not, see . + */ + +package thecodex6824.auracontrol; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilitySerializable; + +public class SimpleCapabilityProvider implements ICapabilitySerializable { + + protected C instance; + protected Capability cap; + + public SimpleCapabilityProvider(C inst, Capability c) { + cap = c; + instance = inst; + } + + @Override + public void deserializeNBT(NBTTagCompound nbt) { + cap.readNBT(instance, null, nbt); + } + + @Override + public NBTTagCompound serializeNBT() { + return (NBTTagCompound) cap.writeNBT(instance, null); + } + + @Override + public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == cap; + } + + @Override + @Nullable + public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + // in case some mod decides to query caps before they were set up + if (cap != null && capability == cap) + return cap.cast(instance); + + return null; + } + +} diff --git a/src/main/java/thecodex6824/auracontrol/api/AuraControlAPI.java b/src/main/java/thecodex6824/auracontrol/api/AuraControlAPI.java index 48a86d7..7299fc2 100644 --- a/src/main/java/thecodex6824/auracontrol/api/AuraControlAPI.java +++ b/src/main/java/thecodex6824/auracontrol/api/AuraControlAPI.java @@ -37,34 +37,93 @@ private AuraControlAPI() {} private static IInternalMethodHandler handler; + /** + * For internal use only - sets the handler for API methods + * @param newHandler The handler to use + */ public static void setMethodHandler(IInternalMethodHandler newHandler) { handler = newHandler; } + /** + * Returns the set of all biomes that should have an aura and aura features. + * It will always be the allowed biomes regardless of how the user configured + * the list (i.e. regardless of whether a blocklist or allowlist was used). + * @return The set of all biomes that should have an aura generated + */ public static Set getAllowedBiomes() { return handler.getAllowedBiomes(); } + /** + * Modifies the aura, taking the allowed biome list into account, for the given chunk. + * It may set the chunk vis cap, vis amount, and flux amount, but will not change + * the information in the chunk's OriginalAuraInfo capability. + * @param world The world the chunk is located in + * @param chunkX The chunk X coordinate + * @param chunkZ The chunk Z coordinate + * @see IOriginalAuraInfo + */ public static void handleAura(World world, int chunkX, int chunkZ) { handler.handleAura(world, chunkX, chunkZ); } + /** + * Prepares the static final fields in TC's config class to support disabling + * crystals and Thaumcraft trees in biomes with no aura. This needs to be called + * before Thaumcraft's world generator is called. + * @param world The world the chunk is located in + * @param chunkX The chunk X coordinate + * @param chunkZ The chunk Z coordinate + */ public static void setupTCWorldgenFlags(World world, int chunkX, int chunkZ) { handler.setupTCWorldgenFlags(world, chunkX, chunkZ); } + /** + * Returns if aura gen should be controlled. + * @return If crystal gen should be controlled + */ + public static boolean shouldHandleAuraGen() { + return handler.shouldHandleAuraGen(); + } + + /** + * Sets if crystal gen should be controlled. + * @param handle If crystal gen should be handled + */ + public static void setHandleAuraGen(boolean handle) { + handler.setHandleAuraGen(handle); + } + + /** + * Returns if crystal gen should be controlled. + * @return If crystal gen should be controlled + */ public static boolean shouldHandleCrystalGen() { return handler.shouldHandleCrystalGen(); } + /** + * Sets if crystal gen should be controlled. + * @param handle If crystal gen should be handled + */ public static void setHandleCrystalGen(boolean handle) { handler.setHandleCrystalGen(handle); } + /** + * Returns if Thaumcraft tree gen should be controlled. + * @return If tree gen should be controlled + */ public static boolean shouldHandleTreeGen() { return handler.shouldHandleTreeGen(); } + /** + * Sets if Thaumcraft tree gen should be controlled. + * @param handle If tree gen should be handled + */ public static void setHandleTreeGen(boolean handle) { handler.setHandleTreeGen(handle); } diff --git a/src/main/java/thecodex6824/auracontrol/api/CapabilityOriginalAuraInfo.java b/src/main/java/thecodex6824/auracontrol/api/CapabilityOriginalAuraInfo.java index 6853bf3..35ada2b 100644 --- a/src/main/java/thecodex6824/auracontrol/api/CapabilityOriginalAuraInfo.java +++ b/src/main/java/thecodex6824/auracontrol/api/CapabilityOriginalAuraInfo.java @@ -23,6 +23,11 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; +/** + * Holds the Capability instance for the OriginalAuraInfo + * capability. + * @see IOriginalAuraInfo + */ public final class CapabilityOriginalAuraInfo { private CapabilityOriginalAuraInfo() {} diff --git a/src/main/java/thecodex6824/auracontrol/api/IOriginalAuraInfo.java b/src/main/java/thecodex6824/auracontrol/api/IOriginalAuraInfo.java index 2b775f1..a8615be 100644 --- a/src/main/java/thecodex6824/auracontrol/api/IOriginalAuraInfo.java +++ b/src/main/java/thecodex6824/auracontrol/api/IOriginalAuraInfo.java @@ -20,18 +20,53 @@ package thecodex6824.auracontrol.api; +/** + * Capability that holds the statistics for an aura chunk, + * at the time it was generated. Useful for detecting modifications + * to the aura, or restoring it to its original values. Mods (including AuraControl) + * can, and are expected to, modify this at worldgen time to reflect the final values + * of the generated aura. + */ public interface IOriginalAuraInfo { + /** + * Returns the base aura level, also known as the vis cap. + * @return The base aura level + */ public short getBase(); + /** + * Sets the base aura level. + * @param newBase The new base aura level + */ public void setBase(short newBase); + /** + * Returns the amount of vis in the aura, which can be + * different from the vis cap. + * @return The vis level + */ public float getVis(); + /** + * Sets the amount of vis in the aura. + * @param newVis The new vis level + */ public void setVis(float newVis); + /** + * Returns the amount of flux in the aura. Vanilla Thaumcraft + * barely adds any flux, if any, at worldgen time, but mods + * like Thaumic Augmentation may add some as part of their + * worldgen. + * @return The amount of flux in the aura + */ public float getFlux(); + /** + * Sets the amount of flux in the aura. + * @param newFlux The new flux level + */ public void setFlux(float newFlux); } diff --git a/src/main/java/thecodex6824/auracontrol/api/OriginalAuraInfo.java b/src/main/java/thecodex6824/auracontrol/api/OriginalAuraInfo.java index 839e6da..7fe8c36 100644 --- a/src/main/java/thecodex6824/auracontrol/api/OriginalAuraInfo.java +++ b/src/main/java/thecodex6824/auracontrol/api/OriginalAuraInfo.java @@ -23,6 +23,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.INBTSerializable; +/** + * Default implementation for the OriginalAuraInfo capability. + * @see IOriginalAuraInfo + */ public class OriginalAuraInfo implements IOriginalAuraInfo, INBTSerializable { protected short base; diff --git a/src/main/java/thecodex6824/auracontrol/api/internal/IInternalMethodHandler.java b/src/main/java/thecodex6824/auracontrol/api/internal/IInternalMethodHandler.java index e67fec4..61b1472 100644 --- a/src/main/java/thecodex6824/auracontrol/api/internal/IInternalMethodHandler.java +++ b/src/main/java/thecodex6824/auracontrol/api/internal/IInternalMethodHandler.java @@ -25,6 +25,9 @@ import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +/** + * For internal use only. + */ public interface IInternalMethodHandler { public Set getAllowedBiomes(); @@ -33,6 +36,10 @@ public interface IInternalMethodHandler { public void setupTCWorldgenFlags(World world, int chunkX, int chunkZ); + public boolean shouldHandleAuraGen(); + + public void setHandleAuraGen(boolean allow); + public boolean shouldHandleCrystalGen(); public void setHandleCrystalGen(boolean handle); diff --git a/src/main/java/thecodex6824/auracontrol/api/package-info.java b/src/main/java/thecodex6824/auracontrol/api/package-info.java new file mode 100644 index 0000000..d62e63f --- /dev/null +++ b/src/main/java/thecodex6824/auracontrol/api/package-info.java @@ -0,0 +1,28 @@ +/** + * AuraControl + * Copyright (c) 2020 TheCodex6824. + * + * This file is part of AuraControl. + * + * AuraControl is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AuraControl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AuraControl. If not, see . + */ + +/** + * API providing access to AuraControl's ability to restrict aura generation, as well as + * other associated features. + */ +@net.minecraftforge.fml.common.API(owner = AuraControlAPI.MODID, provides = AuraControlAPI.PROVIDES, + apiVersion = AuraControlAPI.API_VERSION) +@javax.annotation.ParametersAreNonnullByDefault +package thecodex6824.auracontrol.api; \ No newline at end of file diff --git a/src/main/resources/icon.png b/src/main/resources/icon.png new file mode 100644 index 0000000..4c6deb5 Binary files /dev/null and b/src/main/resources/icon.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index f7272a8..c5daee4 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -5,8 +5,10 @@ "description": "An addon mod for Thaumcraft that allows tweaking the generation of the Aura by biome.", "version": "${version}", "mcversion": "${mcversion}", + "url": "https://github.com/TheCodex6824/AuraControl", "authorList": ["TheCodex6824"], "credits": "The Thaumcraft community for being cool", + "logoFile": "icon.png", "screenshots": [], "useDependencyInformation": true, "requiredMods": ["forge@[${forgeminversion},)", "thaumcraft@[6.1.BETA26,)"],