diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/plugin')
6 files changed, 113 insertions, 33 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java index beeaf6bbd..b2881f9f7 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java @@ -53,7 +53,7 @@ public class DefaultBlastingCategory implements IRecipeCategory<DefaultBlastingD int height = MathHelper.ceil((System.currentTimeMillis() / 250 % 14d) / 1f); drawTexturedRect(startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height); int width = MathHelper.ceil((System.currentTimeMillis() / 250 % 24d) / 1f); - drawTexturedRect(startPoint.x + 24, startPoint.y + 19, 82, 92, width, 17); + drawTexturedRect(startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17); } })); List<List<ItemStack>> input = recipeDisplay.getInput(); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultCampfireCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultCampfireCategory.java index 0003cd4a0..db681d863 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultCampfireCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultCampfireCategory.java @@ -52,10 +52,10 @@ public class DefaultCampfireCategory implements IRecipeCategory<DefaultCampfireD int height = MathHelper.ceil((System.currentTimeMillis() / 250 % 14d) / 1f); drawTexturedRect(startPoint.x + 2, startPoint.y + 31 + (14 - height), 82, 77 + (14 - height), 14, height); int width = MathHelper.ceil((System.currentTimeMillis() / 250 % 24d) / 1f); - drawTexturedRect(startPoint.x + 24, startPoint.y + 19, 82, 92, width, 17); + drawTexturedRect(startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17); String text = I18n.translate("category.rei.campfire.time", MathHelper.floor(recipeDisplaySupplier.get().getCookTime() / 20d)); int length = MinecraftClient.getInstance().fontRenderer.getStringWidth(text); - MinecraftClient.getInstance().fontRenderer.draw(text, bounds.x + bounds.width - length - 5, startPoint.y + 54 - 8, -1); + MinecraftClient.getInstance().fontRenderer.draw(text, bounds.x + bounds.width - length - 5, startPoint.y + 54 - 8, 4210752); } })); widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 11, recipeDisplaySupplier.get().getInput().get(0), true, true, true)); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index a88c5c9bb..3720f1026 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -2,8 +2,8 @@ package me.shedaniel.rei.plugin; import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.IRecipePlugin; -import me.shedaniel.rei.api.SpeedCraftFunctional; +import me.shedaniel.rei.api.*; +import me.shedaniel.rei.client.RecipeHelper; import me.shedaniel.rei.listeners.IMixinRecipeBookGui; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Screen; @@ -12,6 +12,10 @@ import net.minecraft.client.gui.container.CraftingTableScreen; import net.minecraft.client.gui.container.FurnaceScreen; import net.minecraft.client.gui.container.SmokerScreen; import net.minecraft.client.gui.ingame.PlayerInventoryScreen; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.recipe.cooking.BlastingRecipe; @@ -21,8 +25,11 @@ import net.minecraft.recipe.cooking.SmokingRecipe; import net.minecraft.recipe.crafting.ShapedRecipe; import net.minecraft.recipe.crafting.ShapelessRecipe; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class DefaultPlugin implements IRecipePlugin { @@ -41,42 +48,72 @@ public class DefaultPlugin implements IRecipePlugin { } @Override - public void registerPluginCategories() { - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultCraftingCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultSmeltingCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultSmokingCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultBlastingCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultCampfireCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultStoneCuttingCategory()); - RoughlyEnoughItemsCore.getRecipeHelper().registerCategory(new DefaultBrewingCategory()); + public void onFirstLoad(IPluginDisabler pluginDisabler) { + if (!RoughlyEnoughItemsCore.getConfigHelper().isLoadingDefaultPlugin()) { + pluginDisabler.disablePluginFunction(new Identifier("roughlyenoughitems", "default_plugin"), PluginFunction.REGISTER_ITEMS); + pluginDisabler.disablePluginFunction(new Identifier("roughlyenoughitems", "default_plugin"), PluginFunction.REGISTER_CATEGORIES); + pluginDisabler.disablePluginFunction(new Identifier("roughlyenoughitems", "default_plugin"), PluginFunction.REGISTER_RECIPE_DISPLAYS); + pluginDisabler.disablePluginFunction(new Identifier("roughlyenoughitems", "default_plugin"), PluginFunction.REGISTER_SPEED_CRAFT); + } } @Override - public void registerRecipes() { - for(Recipe recipe : RoughlyEnoughItemsCore.getRecipeHelper().getRecipeManager().values()) + public void registerItems(IItemRegisterer itemRegisterer) { + Registry.ITEM.stream().forEach(item -> { + itemRegisterer.registerItemStack(item.getDefaultStack()); + try { + itemRegisterer.registerItemStack(itemRegisterer.getAllStacksFromItem(item)); + } catch (Exception e) { + } + }); + Registry.ENCHANTMENT.forEach(enchantment -> { + for(int i = enchantment.getMinimumLevel(); i < enchantment.getMaximumLevel(); i++) { + Map<Enchantment, Integer> map = new HashMap<>(); + map.put(enchantment, i); + ItemStack itemStack = new ItemStack(Items.ENCHANTED_BOOK); + EnchantmentHelper.set(map, itemStack); + itemRegisterer.registerItemStack(Items.ENCHANTED_BOOK, itemStack); + } + }); + } + + @Override + public void registerPluginCategories(RecipeHelper recipeHelper) { + recipeHelper.registerCategory(new DefaultCraftingCategory()); + recipeHelper.registerCategory(new DefaultSmeltingCategory()); + recipeHelper.registerCategory(new DefaultSmokingCategory()); + recipeHelper.registerCategory(new DefaultBlastingCategory()); + recipeHelper.registerCategory(new DefaultCampfireCategory()); + recipeHelper.registerCategory(new DefaultStoneCuttingCategory()); + recipeHelper.registerCategory(new DefaultBrewingCategory()); + } + + @Override + public void registerRecipeDisplays(RecipeHelper recipeHelper) { + for(Recipe recipe : recipeHelper.getRecipeManager().values()) if (recipe instanceof ShapelessRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(CRAFTING, new DefaultShapelessDisplay((ShapelessRecipe) recipe)); + recipeHelper.registerDisplay(CRAFTING, new DefaultShapelessDisplay((ShapelessRecipe) recipe)); else if (recipe instanceof ShapedRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(CRAFTING, new DefaultShapedDisplay((ShapedRecipe) recipe)); + recipeHelper.registerDisplay(CRAFTING, new DefaultShapedDisplay((ShapedRecipe) recipe)); else if (recipe instanceof SmeltingRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(SMELTING, new DefaultSmeltingDisplay((SmeltingRecipe) recipe)); + recipeHelper.registerDisplay(SMELTING, new DefaultSmeltingDisplay((SmeltingRecipe) recipe)); else if (recipe instanceof SmokingRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(SMOKING, new DefaultSmokingDisplay((SmokingRecipe) recipe)); + recipeHelper.registerDisplay(SMOKING, new DefaultSmokingDisplay((SmokingRecipe) recipe)); else if (recipe instanceof BlastingRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(BLASTING, new DefaultBlastingDisplay((BlastingRecipe) recipe)); + recipeHelper.registerDisplay(BLASTING, new DefaultBlastingDisplay((BlastingRecipe) recipe)); else if (recipe instanceof CampfireCookingRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(CAMPFIRE, new DefaultCampfireDisplay((CampfireCookingRecipe) recipe)); + recipeHelper.registerDisplay(CAMPFIRE, new DefaultCampfireDisplay((CampfireCookingRecipe) recipe)); else if (recipe instanceof StonecuttingRecipe) - RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(STONE_CUTTING, new DefaultStoneCuttingDisplay((StonecuttingRecipe) recipe)); - BREWING_DISPLAYS.stream().forEachOrdered(display -> RoughlyEnoughItemsCore.getRecipeHelper().registerRecipe(BREWING, display)); + recipeHelper.registerDisplay(STONE_CUTTING, new DefaultStoneCuttingDisplay((StonecuttingRecipe) recipe)); + BREWING_DISPLAYS.stream().forEachOrdered(display -> recipeHelper.registerDisplay(BREWING, display)); } @Override - public void registerSpeedCraft() { - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftButtonArea(DefaultPlugin.CAMPFIRE, null); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftButtonArea(DefaultPlugin.STONE_CUTTING, null); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftButtonArea(DefaultPlugin.BREWING, null); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftFunctional(DefaultPlugin.CRAFTING, new SpeedCraftFunctional<DefaultCraftingDisplay>() { + public void registerSpeedCraft(RecipeHelper recipeHelper) { + recipeHelper.registerSpeedCraftButtonArea(DefaultPlugin.CAMPFIRE, null); + recipeHelper.registerSpeedCraftButtonArea(DefaultPlugin.STONE_CUTTING, null); + recipeHelper.registerSpeedCraftButtonArea(DefaultPlugin.BREWING, null); + recipeHelper.registerSpeedCraftFunctional(DefaultPlugin.CRAFTING, new SpeedCraftFunctional<DefaultCraftingDisplay>() { @Override public Class[] getFunctioningFor() { return new Class[]{PlayerInventoryScreen.class, CraftingTableScreen.class}; @@ -99,7 +136,7 @@ public class DefaultPlugin implements IRecipePlugin { return screen instanceof CraftingTableScreen || (screen instanceof PlayerInventoryScreen && recipe.getHeight() < 3 && recipe.getWidth() < 3); } }); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftFunctional(DefaultPlugin.SMELTING, new SpeedCraftFunctional<DefaultSmeltingDisplay>() { + recipeHelper.registerSpeedCraftFunctional(DefaultPlugin.SMELTING, new SpeedCraftFunctional<DefaultSmeltingDisplay>() { @Override public Class[] getFunctioningFor() { return new Class[]{FurnaceScreen.class}; @@ -120,7 +157,7 @@ public class DefaultPlugin implements IRecipePlugin { return screen instanceof FurnaceScreen; } }); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftFunctional(DefaultPlugin.SMOKING, new SpeedCraftFunctional<DefaultSmokingDisplay>() { + recipeHelper.registerSpeedCraftFunctional(DefaultPlugin.SMOKING, new SpeedCraftFunctional<DefaultSmokingDisplay>() { @Override public Class[] getFunctioningFor() { return new Class[]{SmokerScreen.class}; @@ -141,7 +178,7 @@ public class DefaultPlugin implements IRecipePlugin { return screen instanceof SmokerScreen; } }); - RoughlyEnoughItemsCore.getRecipeHelper().registerSpeedCraftFunctional(DefaultPlugin.BLASTING, new SpeedCraftFunctional<DefaultBlastingDisplay>() { + recipeHelper.registerSpeedCraftFunctional(DefaultPlugin.BLASTING, new SpeedCraftFunctional<DefaultBlastingDisplay>() { @Override public Class[] getFunctioningFor() { return new Class[]{BlastFurnaceScreen.class}; diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java index e88c5a9f3..119c6abb6 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java @@ -52,7 +52,7 @@ public class DefaultSmeltingCategory implements IRecipeCategory<DefaultSmeltingD int height = MathHelper.ceil((System.currentTimeMillis() / 250 % 14d) / 1f); drawTexturedRect(startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height); int width = MathHelper.ceil((System.currentTimeMillis() / 250 % 24d) / 1f); - drawTexturedRect(startPoint.x + 24, startPoint.y + 19, 82, 92, width, 17); + drawTexturedRect(startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17); } })); List<List<ItemStack>> input = recipeDisplaySupplier.get().getInput(); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java index d83ee3a7d..cc21ac649 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java @@ -52,7 +52,7 @@ public class DefaultSmokingCategory implements IRecipeCategory<DefaultSmokingDis int height = MathHelper.ceil((System.currentTimeMillis() / 250 % 14d) / 1f); drawTexturedRect(startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height); int width = MathHelper.ceil((System.currentTimeMillis() / 250 % 24d) / 1f); - drawTexturedRect(startPoint.x + 24, startPoint.y + 19, 82, 92, width, 17); + drawTexturedRect(startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17); } })); List<List<ItemStack>> input = recipeDisplaySupplier.get().getInput(); diff --git a/src/main/java/me/shedaniel/rei/plugin/PluginManager.java b/src/main/java/me/shedaniel/rei/plugin/PluginManager.java new file mode 100644 index 000000000..ccc6e7e67 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/plugin/PluginManager.java @@ -0,0 +1,43 @@ +package me.shedaniel.rei.plugin; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import me.shedaniel.rei.api.IPluginDisabler; +import me.shedaniel.rei.api.PluginFunction; +import net.minecraft.util.Identifier; + +import java.util.List; +import java.util.Map; + +public class PluginManager implements IPluginDisabler { + + 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); + } + +} |
