Move some classes to the api and fix broken api classes

This commit is contained in:
Nedelosk committed 2017-11-03 16:09:17 +01:00
1 parent e7766d3ad9
commit a0e15f76ca
58 files changed
+306 -182

No files matched your search

@@ -2,11 +2,26 @@ package forestry.modules;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import forestry.api.modules.ForestryModule;
import forestry.api.modules.IForestryModule;
import forestry.core.IPickupHandler;
import forestry.core.IResupplyHandler;
import forestry.core.ISaveEventHandler;
import forestry.core.config.Constants;
import forestry.core.network.IPacketRegistry;
public class BlankForestryModule implements IForestryModule {
@@ -25,4 +40,43 @@ public class BlankForestryModule implements IForestryModule {
}
return forestryModule.name() + " Module";
}
public boolean processIMCMessage(FMLInterModComms.IMCMessage message){
return false;
}
public void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated){
}
public void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ){
}
public void decorateBiome(World world, Random rand, BlockPos pos){
}
/**
* Can be used to hide items in JEI.
*/
public void getHiddenItems(List<ItemStack> hiddenItems){
}
@Nullable
public ISaveEventHandler getSaveEventHandler(){
return null;
}
@Nullable
public IPacketRegistry getPacketRegistry(){
return null;
}
@Nullable
public IPickupHandler getPickupHandler(){
return null;
}
@Nullable
public IResupplyHandler getResupplyHandler(){
return null;
}
}
@@ -1,69 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.modules;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Annotation to provide additional information on IForestryModules. This information will be available via the "/forestry module info {@link #moduleID()}" command ingame.
*
* @author Nedelosk
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ForestryModule {
/**
* @return Unique identifier for the module, no spaces!
*/
String moduleID();
/**
* @return The unique identifier of the module container.
*/
String containerID();
/**
* @return Nice and readable module name.
*/
String name();
/**
* @return ForestryModule author's name.
*/
String author() default "";
/**
* @return URL of plugin homepage.
*/
String url() default "";
/**
* @return Not used (yet?).
*/
String help() default "";
/**
* @return The name of the loot table file, if any.
*/
String lootTable() default "";
/**
* @return True if this is a core module.
*/
boolean coreModule() default false;
/**
* @return Version of the module, if any.
*/
String version() default "";
/**
* @return Localization key for a short description what the module does.
*/
String unlocalizedDescription() default "";
}
@@ -6,6 +6,9 @@ import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import forestry.Forestry;
import forestry.api.modules.ForestryModule;
import forestry.api.modules.IForestryModule;
import forestry.api.modules.IModuleContainer;
import forestry.core.config.Constants;
public class ForestryModules implements IModuleContainer {
@@ -12,6 +12,8 @@ import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import forestry.api.modules.ForestryModule;
import forestry.api.modules.IForestryModule;
import forestry.core.utils.Log;
public class ForestryPluginUtil {
@@ -1,116 +0,0 @@
package forestry.modules;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.command.ICommand;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import forestry.core.IPickupHandler;
import forestry.core.IResupplyHandler;
import forestry.core.ISaveEventHandler;
import forestry.core.network.IPacketRegistry;
public interface IForestryModule {
default boolean isAvailable() {
return true;
}
default boolean canBeDisabled() {
return true;
}
default String getFailMessage() {
return "";
}
/**
* The ForestryModule.moduleID()s of any other modules this module depends on.
*/
default Set<ResourceLocation> getDependencyUids(){
return Collections.emptySet();
}
default void setupAPI() {
}
default void disabledSetupAPI() {
}
default void registerItemsAndBlocks() {
}
default void preInit() {
}
default void registerTriggers() {
}
default void registerBackpackItems() {
}
default void registerCrates() {
}
default void doInit() {
}
default void registerRecipes(){
}
default void addLootPoolNames(Set<String> lootPoolNames){
}
default void postInit(){
}
default boolean processIMCMessage(FMLInterModComms.IMCMessage message){
return false;
}
default void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated){
}
default void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ){
}
default void decorateBiome(World world, Random rand, BlockPos pos){
}
default void getHiddenItems(List<ItemStack> hiddenItems){
}
@Nullable
default ISaveEventHandler getSaveEventHandler(){
return null;
}
@Nullable
default IPacketRegistry getPacketRegistry(){
return null;
}
@Nullable
default IPickupHandler getPickupHandler(){
return null;
}
@Nullable
default IResupplyHandler getResupplyHandler(){
return null;
}
@Nullable
default ICommand[] getConsoleCommands(){
return null;
}
}
@@ -1,19 +0,0 @@
package forestry.modules;
import net.minecraftforge.common.config.Configuration;
public interface IModuleContainer {
/**
* @return Unique identifier for the module container, no spaces!
*/
String getID();
boolean isAvailable();
Configuration getModulesConfig();
/**
* @return true if the module is enabled in the config file of this container.
*/
boolean isModuleEnabled(IForestryModule module);
}
@@ -1,18 +0,0 @@
package forestry.modules;
import java.util.Collection;
import net.minecraft.util.ResourceLocation;
public interface IModuleManager {
default boolean isModuleEnabled(String containerID, String moduleID){
return isModuleEnabled(new ResourceLocation(containerID, moduleID));
}
boolean isModuleEnabled(ResourceLocation id);
void registerContainers(IModuleContainer... container);
Collection<IModuleContainer> getContainers();
}
@@ -46,6 +46,10 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;
import forestry.api.core.ForestryAPI;
import forestry.api.modules.ForestryModule;
import forestry.api.modules.IForestryModule;
import forestry.api.modules.IModuleContainer;
import forestry.api.modules.IModuleManager;
import forestry.core.IPickupHandler;
import forestry.core.IResupplyHandler;
import forestry.core.ISaveEventHandler;
@@ -53,7 +57,7 @@ import forestry.core.config.Constants;
import forestry.core.network.IPacketRegistry;
import forestry.core.utils.Log;
public class ModuleManager implements IModuleManager{
public class ModuleManager implements IModuleManager {
private static final String CONFIG_CATEGORY = "modules";
private static ModuleManager ourInstance = new ModuleManager();
@@ -64,6 +68,7 @@ public class ModuleManager implements IModuleManager{
private static final HashMap<ResourceLocation, IForestryModule> sortedModules = new LinkedHashMap<>();
private static final Set<IForestryModule> loadedModules = new LinkedHashSet<>();
private static final Set<BlankForestryModule> internalModules = new LinkedHashSet<>();
private static final Set<IForestryModule> unloadedModules = new LinkedHashSet<>();
private static final HashMap<String, IModuleContainer> moduleContainers = new HashMap<>();
public static final Set<IForestryModule> configDisabledModules = new HashSet<>();
@@ -113,7 +118,7 @@ public class ModuleManager implements IModuleManager{
return ImmutableSet.copyOf(sortedModules.values());
}
private static void registerHandlers(IForestryModule module, Side side) {
private static void registerHandlers(BlankForestryModule module, Side side) {
Log.debug("Registering Handlers for Module: {}", module);
IPacketRegistry packetRegistry = module.getPacketRegistry();
@@ -256,6 +261,7 @@ public class ModuleManager implements IModuleManager{
}
loadedModules.addAll(sortedModules.values());
sortedModules.values().stream().filter((m)->m instanceof BlankForestryModule).forEach((IForestryModule m)->internalModules.add((BlankForestryModule) m));
unloadedModules.addAll(allModules);
unloadedModules.removeAll(sortedModules.values());
@@ -301,7 +307,10 @@ public class ModuleManager implements IModuleManager{
stage = Stage.PRE_INIT;
for (IForestryModule module : loadedModules) {
Log.debug("Pre-Init Start: {}", module);
registerHandlers(module, side);
if(module instanceof BlankForestryModule) {
BlankForestryModule moduleInternal = (BlankForestryModule) module;
registerHandlers(moduleInternal, side);
}
module.preInit();
if (getInstance().isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.BUILDCRAFT_STATEMENTS)) {
module.registerTriggers();
@@ -359,7 +368,7 @@ public class ModuleManager implements IModuleManager{
public static void processIMCMessages(ImmutableList<FMLInterModComms.IMCMessage> messages) {
for (FMLInterModComms.IMCMessage message : messages) {
for (IForestryModule module : loadedModules) {
for (BlankForestryModule module : internalModules) {
if (module.processIMCMessage(message)) {
break;
}
@@ -368,19 +377,19 @@ public class ModuleManager implements IModuleManager{
}
public static void populateChunk(IChunkGenerator chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
for (IForestryModule module : loadedModules) {
for (BlankForestryModule module : internalModules) {
module.populateChunk(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
}
}
public static void decorateBiome(World world, Random rand, BlockPos pos) {
for (IForestryModule module : loadedModules) {
for (BlankForestryModule module : internalModules) {
module.decorateBiome(world, rand, pos);
}
}
public static void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) {
for (IForestryModule module : loadedModules) {
for (BlankForestryModule module : internalModules) {
module.populateChunkRetroGen(world, rand, chunkX, chunkZ);
}
}
@@ -388,7 +397,7 @@ public class ModuleManager implements IModuleManager{
public static List<ItemStack> getHiddenItems() {
List<ItemStack> hiddenItems = new ArrayList<>();
for (IForestryModule module : loadedModules) {
for (BlankForestryModule module : internalModules) {
module.getHiddenItems(hiddenItems);
}
return hiddenItems;