aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java11
-rw-r--r--src/main/java/me/shedaniel/rei/api/PluginDisabler.java59
-rw-r--r--src/main/java/me/shedaniel/rei/api/PluginFunction.java14
-rw-r--r--src/main/java/me/shedaniel/rei/api/RecipeHelper.java11
-rw-r--r--src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java9
-rw-r--r--src/main/java/me/shedaniel/rei/client/PluginDisablerImpl.java48
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java22
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java13
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java23
9 files changed, 41 insertions, 169 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 338032d5d..5a2a170c8 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -57,7 +57,6 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
public static final Logger LOGGER;
private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl();
- private static final PluginDisabler PLUGIN_DISABLER = new PluginDisablerImpl();
private static final ItemRegistry ITEM_REGISTRY = new ItemRegistryImpl();
private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl();
private static final Map<Identifier, REIPluginEntry> plugins = Maps.newHashMap();
@@ -72,7 +71,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
return RECIPE_HELPER;
}
- public static me.shedaniel.rei.api.ConfigManager getConfigManager() {
+ public static ConfigManager getConfigManager() {
return configManager;
}
@@ -80,10 +79,6 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
return ITEM_REGISTRY;
}
- public static PluginDisabler getPluginDisabler() {
- return PLUGIN_DISABLER;
- }
-
public static DisplayHelper getDisplayHelper() {
return DISPLAY_HELPER;
}
@@ -189,7 +184,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
throw new IllegalArgumentException("REI plugin is too old!");
registerPlugin(reiPlugin);
if (reiPlugin instanceof REIPluginV0)
- ((REIPluginV0) reiPlugin).onFirstLoad(getPluginDisabler());
+ ((REIPluginV0) reiPlugin).onFirstLoad();
} catch (Exception e) {
e.printStackTrace();
RoughlyEnoughItemsCore.LOGGER.error("[REI] Can't load REI plugins from %s: %s", reiPlugin.getClass(), e.getLocalizedMessage());
@@ -198,7 +193,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
for (REIPluginV0 reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins_v0", REIPluginV0.class)) {
try {
registerPlugin(reiPlugin);
- reiPlugin.onFirstLoad(getPluginDisabler());
+ reiPlugin.onFirstLoad();
} catch (Exception e) {
e.printStackTrace();
RoughlyEnoughItemsCore.LOGGER.error("[REI] Can't load REI plugins from %s: %s", reiPlugin.getClass(), e.getLocalizedMessage());
diff --git a/src/main/java/me/shedaniel/rei/api/PluginDisabler.java b/src/main/java/me/shedaniel/rei/api/PluginDisabler.java
deleted file mode 100644
index e58a0cfd7..000000000
--- a/src/main/java/me/shedaniel/rei/api/PluginDisabler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Roughly Enough Items by Danielshe.
- * Licensed under the MIT License.
- */
-
-package me.shedaniel.rei.api;
-
-import net.minecraft.util.Identifier;
-
-public interface PluginDisabler {
-
- /**
- * Disables multiple functions from a plugin
- *
- * @param plugin the identifier of the plugin
- * @param functions the array of functions to be disabled
- */
- default void disablePluginFunctions(Identifier plugin, PluginFunction... functions) {
- for (PluginFunction function : functions)
- disablePluginFunction(plugin, function);
- }
-
- /**
- * Enables multiple functions from a plugin
- *
- * @param plugin the identifier of the plugin
- * @param functions the array of functions to be enabled
- */
- default void enablePluginFunctions(Identifier plugin, PluginFunction... functions) {
- for (PluginFunction function : functions)
- enablePluginFunction(plugin, function);
- }
-
- /**
- * Disables a function from a plugin
- *
- * @param plugin the identifier of the plugin
- * @param function the function to be disabled
- */
- void disablePluginFunction(Identifier plugin, PluginFunction function);
-
- /**
- * Enables a function from a plugin
- *
- * @param plugin the identifier of the plugin
- * @param function the function to be enabled
- */
- void enablePluginFunction(Identifier plugin, PluginFunction function);
-
- /**
- * Checks if a plugin function has been disabled
- *
- * @param plugin the identifier of the plugin
- * @param function the function to check
- * @return whether if it has been disabled
- */
- boolean isFunctionEnabled(Identifier plugin, PluginFunction function);
-
-}
diff --git a/src/main/java/me/shedaniel/rei/api/PluginFunction.java b/src/main/java/me/shedaniel/rei/api/PluginFunction.java
deleted file mode 100644
index ec20c317a..000000000
--- a/src/main/java/me/shedaniel/rei/api/PluginFunction.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Roughly Enough Items by Danielshe.
- * Licensed under the MIT License.
- */
-
-package me.shedaniel.rei.api;
-
-public enum PluginFunction {
- REGISTER_ITEMS,
- REGISTER_CATEGORIES,
- REGISTER_RECIPE_DISPLAYS,
- REGISTER_BOUNDS,
- REGISTER_OTHERS;
-}
diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
index f70f21669..9deec1c0e 100644
--- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
@@ -6,7 +6,6 @@
package me.shedaniel.rei.api;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.client.RecipeHelperImpl;
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
@@ -215,6 +214,14 @@ public interface RecipeHelper {
<T extends Recipe<?>> void registerRecipes(Identifier category, Function<Recipe, Boolean> recipeFilter, Function<T, RecipeDisplay> mappingFunction);
- List<RecipeHelperImpl.ScreenClickArea> getScreenClickAreas();
+ List<RecipeHelper.ScreenClickArea> getScreenClickAreas();
+
+ interface ScreenClickArea {
+ Class<? extends AbstractContainerScreen> getScreenClass();
+
+ Rectangle getRectangle();
+
+ Identifier[] getCategories();
+ }
}
diff --git a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java
index 6211e0672..3b71a30f5 100644
--- a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java
+++ b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java
@@ -5,7 +5,10 @@
package me.shedaniel.rei.api.plugins;
-import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.api.DisplayHelper;
+import me.shedaniel.rei.api.ItemRegistry;
+import me.shedaniel.rei.api.REIPluginEntry;
+import me.shedaniel.rei.api.RecipeHelper;
import net.fabricmc.loader.api.SemanticVersion;
import net.fabricmc.loader.util.version.VersionParsingException;
@@ -15,10 +18,8 @@ public interface REIPluginV0 extends REIPluginEntry {
/**
* On register of the plugin
- *
- * @param pluginDisabler the helper class to disable other plugins
*/
- default void onFirstLoad(PluginDisabler pluginDisabler) {
+ default void onFirstLoad() {
}
/**
diff --git a/src/main/java/me/shedaniel/rei/client/PluginDisablerImpl.java b/src/main/java/me/shedaniel/rei/client/PluginDisablerImpl.java
deleted file mode 100644
index c68941ab3..000000000
--- a/src/main/java/me/shedaniel/rei/client/PluginDisablerImpl.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Roughly Enough Items by Danielshe.
- * Licensed under the MIT License.
- */
-
-package me.shedaniel.rei.client;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import me.shedaniel.rei.api.PluginDisabler;
-import me.shedaniel.rei.api.PluginFunction;
-import net.minecraft.util.Identifier;
-
-import java.util.List;
-import java.util.Map;
-
-public class PluginDisablerImpl implements PluginDisabler {
-
- private static Map<Identifier, List<PluginFunction>> pluginDisabledFunctions = Maps.newHashMap();
-
- @Override
- public void disablePluginFunction(Identifier plugin, PluginFunction function) {
- List<PluginFunction> list = Lists.newArrayList();
- if (pluginDisabledFunctions.containsKey(plugin))
- list = pluginDisabledFunctions.get(plugin);
- if (!list.contains(function))
- list.add(function);
- pluginDisabledFunctions.put(plugin, list);
- }
-
- @Override
- public void enablePluginFunction(Identifier plugin, PluginFunction function) {
- List<PluginFunction> list = Lists.newArrayList();
- if (pluginDisabledFunctions.containsKey(plugin))
- list = pluginDisabledFunctions.get(plugin);
- if (list.contains(function))
- list.remove(function);
- pluginDisabledFunctions.put(plugin, list);
- if (list.size() == 0)
- pluginDisabledFunctions.remove(plugin);
- }
-
- @Override
- public boolean isFunctionEnabled(Identifier plugin, PluginFunction function) {
- return !pluginDisabledFunctions.containsKey(plugin) || !pluginDisabledFunctions.get(plugin).contains(function);
- }
-
-}
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
index 7592cfe03..74322ce44 100644
--- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
@@ -242,7 +242,6 @@ public class RecipeHelperImpl implements RecipeHelper {
RoughlyEnoughItemsCore.LOGGER.info("[REI] Loading %d plugins: %s", plugins.size(), plugins.stream().map(REIPluginEntry::getPluginIdentifier).map(Identifier::toString).collect(Collectors.joining(", ")));
Collections.reverse(plugins);
RoughlyEnoughItemsCore.getItemRegisterer().getModifiableItemList().clear();
- PluginDisabler pluginDisabler = RoughlyEnoughItemsCore.getPluginDisabler();
Version reiVersion = FabricLoader.getInstance().getModContainer("roughlyenoughitems").get().getMetadata().getVersion();
if (!(reiVersion instanceof SemanticVersion))
RoughlyEnoughItemsCore.LOGGER.warn("[REI] Roughly Enough Items is not using semantic versioning, will be ignoring plugins' minimum versions!");
@@ -254,16 +253,11 @@ public class RecipeHelperImpl implements RecipeHelper {
if (((REIPluginV0) plugin).getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) {
throw new IllegalStateException("Requires " + ((REIPluginV0) plugin).getMinimumVersion().getFriendlyString() + " REI version!");
}
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_CATEGORIES))
- ((REIPluginV0) plugin).registerPluginCategories(this);
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_RECIPE_DISPLAYS))
- ((REIPluginV0) plugin).registerRecipeDisplays(this);
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_BOUNDS))
- ((REIPluginV0) plugin).registerBounds(RoughlyEnoughItemsCore.getDisplayHelper());
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_OTHERS))
- ((REIPluginV0) plugin).registerOthers(this);
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_ITEMS))
- ((REIPluginV0) plugin).registerItems(RoughlyEnoughItemsCore.getItemRegisterer());
+ ((REIPluginV0) plugin).registerPluginCategories(this);
+ ((REIPluginV0) plugin).registerRecipeDisplays(this);
+ ((REIPluginV0) plugin).registerBounds(RoughlyEnoughItemsCore.getDisplayHelper());
+ ((REIPluginV0) plugin).registerOthers(this);
+ ((REIPluginV0) plugin).registerItems(RoughlyEnoughItemsCore.getItemRegisterer());
} else {
throw new IllegalStateException("Invaild Plugin Class!");
}
@@ -381,7 +375,7 @@ public class RecipeHelperImpl implements RecipeHelper {
@Override
public void registerScreenClickArea(Rectangle rectangle, Class<? extends AbstractContainerScreen> screenClass, Identifier... categories) {
- this.screenClickAreas.add(new ScreenClickArea(screenClass, rectangle, categories));
+ this.screenClickAreas.add(new ScreenClickAreaImpl(screenClass, rectangle, categories));
}
@Override
@@ -409,12 +403,12 @@ public class RecipeHelperImpl implements RecipeHelper {
return screenClickAreas;
}
- public class ScreenClickArea {
+ private class ScreenClickAreaImpl implements ScreenClickArea {
Class<? extends AbstractContainerScreen> screenClass;
Rectangle rectangle;
Identifier[] categories;
- private ScreenClickArea(Class<? extends AbstractContainerScreen> screenClass, Rectangle rectangle, Identifier[] categories) {
+ private ScreenClickAreaImpl(Class<? extends AbstractContainerScreen> screenClass, Rectangle rectangle, Identifier[] categories) {
this.screenClass = screenClass;
this.rectangle = rectangle;
this.categories = categories;
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
index a36caf122..d8719c0fa 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
@@ -6,8 +6,6 @@
package me.shedaniel.rei.plugin;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.api.PluginDisabler;
-import me.shedaniel.rei.api.PluginFunction;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
import me.shedaniel.rei.plugin.autocrafting.*;
@@ -30,17 +28,10 @@ public class DefaultAutoCraftingPlugin implements REIPluginV0 {
}
@Override
- public void onFirstLoad(PluginDisabler pluginDisabler) {
+ public void registerOthers(RecipeHelper recipeHelper) {
if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_ITEMS);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_CATEGORIES);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_RECIPE_DISPLAYS);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_OTHERS);
+ return;
}
- }
-
- @Override
- public void registerOthers(RecipeHelper recipeHelper) {
recipeHelper.registerAutoCraftingHandler(new AutoCraftingTableBookHandler());
recipeHelper.registerAutoCraftingHandler(new AutoInventoryBookHandler());
recipeHelper.registerAutoCraftingHandler(new AutoFurnaceBookHandler());
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
index 83a565629..b5b124291 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
@@ -91,17 +91,10 @@ public class DefaultPlugin implements REIPluginV0 {
}
@Override
- public void onFirstLoad(PluginDisabler pluginDisabler) {
+ public void registerItems(ItemRegistry itemRegistry) {
if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_ITEMS);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_CATEGORIES);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_RECIPE_DISPLAYS);
- pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_OTHERS);
+ return;
}
- }
-
- @Override
- public void registerItems(ItemRegistry itemRegistry) {
Registry.ITEM.stream().forEach(item -> {
itemRegistry.registerItemStack(item.getStackForRender());
try {
@@ -122,6 +115,9 @@ public class DefaultPlugin implements REIPluginV0 {
@Override
public void registerPluginCategories(RecipeHelper recipeHelper) {
+ if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
+ return;
+ }
recipeHelper.registerCategory(new DefaultCraftingCategory());
recipeHelper.registerCategory(new DefaultSmeltingCategory());
recipeHelper.registerCategory(new DefaultSmokingCategory());
@@ -135,6 +131,9 @@ public class DefaultPlugin implements REIPluginV0 {
@Override
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
+ if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
+ return;
+ }
recipeHelper.registerRecipes(CRAFTING, ShapelessRecipe.class, DefaultShapelessDisplay::new);
recipeHelper.registerRecipes(CRAFTING, ShapedRecipe.class, DefaultShapedDisplay::new);
recipeHelper.registerRecipes(SMELTING, SmeltingRecipe.class, DefaultSmeltingDisplay::new);
@@ -183,6 +182,9 @@ public class DefaultPlugin implements REIPluginV0 {
@Override
public void registerBounds(DisplayHelper displayHelper) {
+ if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
+ return;
+ }
displayHelper.getBaseBoundsHandler().registerExclusionZones(AbstractInventoryScreen.class, new DefaultPotionEffectExclusionZones());
displayHelper.getBaseBoundsHandler().registerExclusionZones(RecipeBookProvider.class, new DefaultRecipeBookExclusionZones());
displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler<AbstractContainerScreen<?>>() {
@@ -282,6 +284,9 @@ public class DefaultPlugin implements REIPluginV0 {
@Override
public void registerOthers(RecipeHelper recipeHelper) {
+ if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
+ return;
+ }
recipeHelper.registerWorkingStations(CRAFTING, new ItemStack(Items.CRAFTING_TABLE));
recipeHelper.registerWorkingStations(SMELTING, new ItemStack(Items.FURNACE));
recipeHelper.registerWorkingStations(SMOKING, new ItemStack(Items.SMOKER));