From ba446965dad004cb38679f0f0e1a526151d84213 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 29 Jul 2020 12:25:47 +0800 Subject: 5.x - 20w30a Signed-off-by: shedaniel --- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 336 +++++++++++++++++++++ .../plugin/DefaultPotionEffectExclusionZones.java | 64 ++++ .../plugin/DefaultRecipeBookExclusionZones.java | 58 ++++ .../rei/plugin/DefaultServerContainerPlugin.java | 40 +++ .../autocrafting/DefaultRecipeBookHandler.java | 102 +++++++ .../plugin/beacon/DefaultBeaconBaseCategory.java | 182 +++++++++++ .../plugin/beacon/DefaultBeaconBaseDisplay.java | 64 ++++ .../plugin/blasting/DefaultBlastingDisplay.java | 44 +++ .../rei/plugin/brewing/BrewingRecipe.java | 41 +++ .../rei/plugin/brewing/DefaultBrewingCategory.java | 84 ++++++ .../rei/plugin/brewing/DefaultBrewingDisplay.java | 90 ++++++ .../plugin/brewing/RegisteredBrewingRecipe.java | 41 +++ .../plugin/campfire/DefaultCampfireCategory.java | 80 +++++ .../plugin/campfire/DefaultCampfireDisplay.java | 90 ++++++ .../composting/DefaultCompostingCategory.java | 118 ++++++++ .../composting/DefaultCompostingDisplay.java | 81 +++++ .../containers/CraftingContainerInfoWrapper.java | 77 +++++ .../rei/plugin/cooking/DefaultCookingCategory.java | 109 +++++++ .../rei/plugin/cooking/DefaultCookingDisplay.java | 119 ++++++++ .../plugin/crafting/DefaultCraftingCategory.java | 113 +++++++ .../plugin/crafting/DefaultCraftingDisplay.java | 73 +++++ .../rei/plugin/crafting/DefaultCustomDisplay.java | 111 +++++++ .../rei/plugin/crafting/DefaultShapedDisplay.java | 85 ++++++ .../plugin/crafting/DefaultShapelessDisplay.java | 89 ++++++ .../rei/plugin/fuel/DefaultFuelCategory.java | 117 +++++++ .../rei/plugin/fuel/DefaultFuelDisplay.java | 64 ++++ .../information/DefaultInformationCategory.java | 221 ++++++++++++++ .../information/DefaultInformationDisplay.java | 101 +++++++ .../plugin/mixin/MixinBrewingRecipeRegistry.java | 87 ++++++ .../plugin/smelting/DefaultSmeltingDisplay.java | 44 +++ .../plugin/smithing/DefaultSmithingCategory.java | 73 +++++ .../plugin/smithing/DefaultSmithingDisplay.java | 92 ++++++ .../rei/plugin/smoking/DefaultSmokingDisplay.java | 41 +++ .../stonecutting/DefaultStoneCuttingCategory.java | 74 +++++ .../stonecutting/DefaultStoneCuttingDisplay.java | 83 +++++ .../plugin/stripping/DefaultStrippingCategory.java | 74 +++++ .../plugin/stripping/DefaultStrippingDisplay.java | 78 +++++ .../rei/plugin/stripping/DummyAxeItem.java | 40 +++ 38 files changed, 3480 insertions(+) create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultServerContainerPlugin.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/BrewingRecipe.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/containers/CraftingContainerInfoWrapper.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapedDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapelessDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/fuel/DefaultFuelCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/fuel/DefaultFuelDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/mixin/MixinBrewingRecipeRegistry.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DummyAxeItem.java (limited to 'RoughlyEnoughItems-default-plugin/src/main/java') diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java new file mode 100644 index 000000000..d7a231a3b --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -0,0 +1,336 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import it.unimi.dsi.fastutil.objects.Object2FloatMap; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.plugins.REIPluginV0; +import me.shedaniel.rei.plugin.autocrafting.DefaultRecipeBookHandler; +import me.shedaniel.rei.plugin.beacon.DefaultBeaconBaseCategory; +import me.shedaniel.rei.plugin.beacon.DefaultBeaconBaseDisplay; +import me.shedaniel.rei.plugin.blasting.DefaultBlastingDisplay; +import me.shedaniel.rei.plugin.brewing.DefaultBrewingCategory; +import me.shedaniel.rei.plugin.brewing.DefaultBrewingDisplay; +import me.shedaniel.rei.plugin.brewing.RegisteredBrewingRecipe; +import me.shedaniel.rei.plugin.campfire.DefaultCampfireCategory; +import me.shedaniel.rei.plugin.campfire.DefaultCampfireDisplay; +import me.shedaniel.rei.plugin.composting.DefaultCompostingCategory; +import me.shedaniel.rei.plugin.composting.DefaultCompostingDisplay; +import me.shedaniel.rei.plugin.cooking.DefaultCookingCategory; +import me.shedaniel.rei.plugin.crafting.DefaultCraftingCategory; +import me.shedaniel.rei.plugin.crafting.DefaultCustomDisplay; +import me.shedaniel.rei.plugin.crafting.DefaultShapedDisplay; +import me.shedaniel.rei.plugin.crafting.DefaultShapelessDisplay; +import me.shedaniel.rei.plugin.fuel.DefaultFuelCategory; +import me.shedaniel.rei.plugin.fuel.DefaultFuelDisplay; +import me.shedaniel.rei.plugin.information.DefaultInformationCategory; +import me.shedaniel.rei.plugin.information.DefaultInformationDisplay; +import me.shedaniel.rei.plugin.smelting.DefaultSmeltingDisplay; +import me.shedaniel.rei.plugin.smithing.DefaultSmithingCategory; +import me.shedaniel.rei.plugin.smithing.DefaultSmithingDisplay; +import me.shedaniel.rei.plugin.smoking.DefaultSmokingDisplay; +import me.shedaniel.rei.plugin.stonecutting.DefaultStoneCuttingCategory; +import me.shedaniel.rei.plugin.stonecutting.DefaultStoneCuttingDisplay; +import me.shedaniel.rei.plugin.stripping.DefaultStrippingCategory; +import me.shedaniel.rei.plugin.stripping.DefaultStrippingDisplay; +import me.shedaniel.rei.plugin.stripping.DummyAxeItem; +import me.shedaniel.rei.utils.CollectionUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.ComposterBlock; +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.*; +import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.*; +import net.minecraft.potion.PotionUtil; +import net.minecraft.recipe.*; +import net.minecraft.tag.BlockTags; +import net.minecraft.tag.Tag; +import net.minecraft.util.Identifier; +import net.minecraft.util.Lazy; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.registry.Registry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +@Environment(EnvType.CLIENT) +public class DefaultPlugin implements REIPluginV0 { + private static final Logger LOGGER = LogManager.getFormatterLogger("REI/DefaultPlugin"); + public static final Identifier CRAFTING = new Identifier("minecraft", "plugins/crafting"); + public static final Identifier SMELTING = new Identifier("minecraft", "plugins/smelting"); + public static final Identifier SMOKING = new Identifier("minecraft", "plugins/smoking"); + public static final Identifier BLASTING = new Identifier("minecraft", "plugins/blasting"); + public static final Identifier CAMPFIRE = new Identifier("minecraft", "plugins/campfire"); + public static final Identifier STONE_CUTTING = new Identifier("minecraft", "plugins/stone_cutting"); + public static final Identifier STRIPPING = new Identifier("minecraft", "plugins/stripping"); + public static final Identifier BREWING = new Identifier("minecraft", "plugins/brewing"); + public static final Identifier PLUGIN = new Identifier("roughlyenoughitems", "default_plugin"); + public static final Identifier COMPOSTING = new Identifier("minecraft", "plugins/composting"); + public static final Identifier FUEL = new Identifier("minecraft", "plugins/fuel"); + public static final Identifier SMITHING = new Identifier("minecraft", "plugins/smithing"); + public static final Identifier BEACON = new Identifier("minecraft", "plugins/beacon"); + public static final Identifier INFO = new Identifier("roughlyenoughitems", "plugins/information"); + private static final Identifier DISPLAY_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/display.png"); + private static final Identifier DISPLAY_TEXTURE_DARK = new Identifier("roughlyenoughitems", "textures/gui/display_dark.png"); + private static final List> BREWING_DISPLAYS = Lists.newArrayList(); + private static final List INFO_DISPLAYS = Lists.newArrayList(); + + public static Identifier getDisplayTexture() { + return REIHelper.getInstance().getDefaultDisplayTexture(); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + public static void registerBrewingDisplay(DefaultBrewingDisplay recipe) { + BREWING_DISPLAYS.add(new Lazy<>(() -> recipe)); + } + + public static void registerBrewingRecipe(RegisteredBrewingRecipe recipe) { + BREWING_DISPLAYS.add(new Lazy<>(() -> new DefaultBrewingDisplay(recipe.input, recipe.ingredient, recipe.output))); + } + + public static void registerInfoDisplay(DefaultInformationDisplay display) { + INFO_DISPLAYS.add(display); + } + + @Override + public Identifier getPluginIdentifier() { + return PLUGIN; + } + + @Override + public void preRegister() { + INFO_DISPLAYS.clear(); + } + + @Override + public void registerEntries(EntryRegistry entryRegistry) { + for (Item item : Registry.ITEM) { + List stacks = null; + try { + stacks = entryRegistry.appendStacksForItem(item); + } catch (Exception ignored) { + } + if (stacks != null) { + for (ItemStack stack : entryRegistry.appendStacksForItem(item)) { + entryRegistry.registerEntry(EntryStack.create(stack)); + } + } else + entryRegistry.registerEntry(EntryStack.create(item)); + } + EntryStack stack = EntryStack.create(Items.ENCHANTED_BOOK); + List enchantments = new ArrayList<>(); + for (Enchantment enchantment : Registry.ENCHANTMENT) { + for (int i = enchantment.getMinimumLevel(); i <= enchantment.getMaximumLevel(); i++) { + Map map = new HashMap<>(); + map.put(enchantment, i); + ItemStack itemStack = new ItemStack(Items.ENCHANTED_BOOK); + EnchantmentHelper.set(map, itemStack); + enchantments.add(EntryStack.create(itemStack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + } + } + entryRegistry.registerEntriesAfter(stack, enchantments); + for (Fluid fluid : Registry.FLUID) { + if (!fluid.getDefaultState().isEmpty() && fluid.getDefaultState().isStill()) + entryRegistry.registerEntry(EntryStack.create(fluid)); + } + } + + @Override + public void registerPluginCategories(RecipeHelper recipeHelper) { + recipeHelper.registerCategories( + new DefaultCraftingCategory(), + new DefaultCookingCategory(SMELTING, EntryStack.create(Items.FURNACE), "category.rei.smelting"), + new DefaultCookingCategory(SMOKING, EntryStack.create(Items.SMOKER), "category.rei.smoking"), + new DefaultCookingCategory(BLASTING, EntryStack.create(Items.BLAST_FURNACE), "category.rei.blasting"), new DefaultCampfireCategory(), + new DefaultStoneCuttingCategory(), + new DefaultFuelCategory(), + new DefaultBrewingCategory(), + new DefaultCompostingCategory(), + new DefaultStrippingCategory(), + new DefaultSmithingCategory(), + new DefaultBeaconBaseCategory(), + new DefaultInformationCategory() + ); + } + + @Override + public void registerRecipeDisplays(RecipeHelper recipeHelper) { + recipeHelper.registerRecipes(CRAFTING, ShapelessRecipe.class, DefaultShapelessDisplay::new); + recipeHelper.registerRecipes(CRAFTING, ShapedRecipe.class, DefaultShapedDisplay::new); + recipeHelper.registerRecipes(SMELTING, SmeltingRecipe.class, DefaultSmeltingDisplay::new); + recipeHelper.registerRecipes(SMOKING, SmokingRecipe.class, DefaultSmokingDisplay::new); + recipeHelper.registerRecipes(BLASTING, BlastingRecipe.class, DefaultBlastingDisplay::new); + recipeHelper.registerRecipes(CAMPFIRE, CampfireCookingRecipe.class, DefaultCampfireDisplay::new); + recipeHelper.registerRecipes(STONE_CUTTING, StonecuttingRecipe.class, DefaultStoneCuttingDisplay::new); + recipeHelper.registerRecipes(SMITHING, SmithingRecipe.class, DefaultSmithingDisplay::new); + for (Lazy display : BREWING_DISPLAYS) { + recipeHelper.registerDisplay(display.get()); + } + for (Map.Entry entry : AbstractFurnaceBlockEntity.createFuelTimeMap().entrySet()) { + recipeHelper.registerDisplay(new DefaultFuelDisplay(EntryStack.create(entry.getKey()), entry.getValue())); + } + List arrowStack = Collections.singletonList(EntryStack.create(Items.ARROW)); + EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getItem() == Items.LINGERING_POTION).forEach(entry -> { + List> input = new ArrayList<>(); + for (int i = 0; i < 4; i++) + input.add(arrowStack); + input.add(Collections.singletonList(EntryStack.create(entry.getItemStack()))); + for (int i = 0; i < 4; i++) + input.add(arrowStack); + ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8); + PotionUtil.setPotion(outputStack, PotionUtil.getPotion(entry.getItemStack())); + PotionUtil.setCustomPotionEffects(outputStack, PotionUtil.getCustomPotionEffects(entry.getItemStack())); + List output = Collections.singletonList(EntryStack.create(outputStack).addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + recipeHelper.registerDisplay(new DefaultCustomDisplay(null, input, output)); + }); + Map map = Maps.newLinkedHashMap(); + if (ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.isEmpty()) + ComposterBlock.registerDefaultCompostableItems(); + for (Object2FloatMap.Entry entry : ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.object2FloatEntrySet()) { + if (entry.getFloatValue() > 0) + map.put(entry.getKey(), entry.getFloatValue()); + } + List stacks = Lists.newArrayList(map.keySet()); + stacks.sort(Comparator.comparing(map::get)); + for (int i = 0; i < stacks.size(); i += MathHelper.clamp(48, 1, stacks.size() - i)) { + List thisStacks = Lists.newArrayList(); + for (int j = i; j < i + 48; j++) + if (j < stacks.size()) + thisStacks.add(stacks.get(j)); + recipeHelper.registerDisplay(new DefaultCompostingDisplay(MathHelper.floor(i / 48f), thisStacks, map, new ItemStack(Items.BONE_MEAL))); + } + DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getId(b.getKey()))).forEach(set -> { + recipeHelper.registerDisplay(new DefaultStrippingDisplay(EntryStack.create(set.getKey()), EntryStack.create(set.getValue()))); + }); + recipeHelper.registerDisplay(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.values()), ItemStack::new))); + } + + @Override + public void postRegister() { + for (DefaultInformationDisplay display : INFO_DISPLAYS) + RecipeHelper.getInstance().registerDisplay(display); + // TODO Turn this into an API + // Sit tight! This will be a fast journey! + long time = System.currentTimeMillis(); + EntryRegistry.getInstance().getEntryStacks().forEach(this::applyPotionTransformer); + for (List displays : RecipeHelper.getInstance().getAllRecipesNoHandlers().values()) { + for (RecipeDisplay display : displays) { + for (List entries : display.getInputEntries()) + for (EntryStack stack : entries) + applyPotionTransformer(stack); + for (EntryStack stack : display.getOutputEntries()) + applyPotionTransformer(stack); + } + } + time = System.currentTimeMillis() - time; + LOGGER.info("Applied Check Tags for potion in %dms.", time); + } + + private void applyPotionTransformer(EntryStack stack) { + if (stack.getItem() instanceof PotionItem) + stack.addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); + } + + @Override + public void registerBounds(DisplayHelper displayHelper) { + BaseBoundsHandler baseBoundsHandler = BaseBoundsHandler.getInstance(); + baseBoundsHandler.registerExclusionZones(AbstractInventoryScreen.class, new DefaultPotionEffectExclusionZones()); + baseBoundsHandler.registerExclusionZones(RecipeBookProvider.class, new DefaultRecipeBookExclusionZones()); + displayHelper.registerProvider(new DisplayHelper.DisplayBoundsProvider>() { + @Override + public Rectangle getScreenBounds(ContainerScreen screen) { + return new Rectangle(screen.x, screen.y, screen.containerWidth, screen.containerHeight); + } + + @Override + public Class getBaseSupportedClass() { + return ContainerScreen.class; + } + }); + } + + @Override + public void registerOthers(RecipeHelper recipeHelper) { + recipeHelper.registerAutoCraftingHandler(new DefaultRecipeBookHandler()); + + recipeHelper.registerWorkingStations(CRAFTING, EntryStack.create(Items.CRAFTING_TABLE)); + recipeHelper.registerWorkingStations(SMELTING, EntryStack.create(Items.FURNACE)); + recipeHelper.registerWorkingStations(SMOKING, EntryStack.create(Items.SMOKER)); + recipeHelper.registerWorkingStations(BLASTING, EntryStack.create(Items.BLAST_FURNACE)); + recipeHelper.registerWorkingStations(CAMPFIRE, EntryStack.create(Items.CAMPFIRE)); + recipeHelper.registerWorkingStations(FUEL, EntryStack.create(Items.FURNACE), EntryStack.create(Items.SMOKER), EntryStack.create(Items.BLAST_FURNACE)); + recipeHelper.registerWorkingStations(BREWING, EntryStack.create(Items.BREWING_STAND)); + recipeHelper.registerWorkingStations(STONE_CUTTING, EntryStack.create(Items.STONECUTTER)); + recipeHelper.registerWorkingStations(COMPOSTING, EntryStack.create(Items.COMPOSTER)); + recipeHelper.registerWorkingStations(SMITHING, EntryStack.create(Items.SMITHING_TABLE)); + recipeHelper.registerWorkingStations(BEACON, EntryStack.create(Items.BEACON)); + Tag axes = MinecraftClient.getInstance().getNetworkHandler().getTagManager().getItems().getTag(new Identifier("fabric", "axes")); + if (axes != null) { + for (Item item : axes.values()) { + recipeHelper.registerWorkingStations(STRIPPING, EntryStack.create(item)); + } + } + recipeHelper.removeAutoCraftButton(FUEL); + recipeHelper.removeAutoCraftButton(COMPOSTING); + recipeHelper.removeAutoCraftButton(BEACON); + recipeHelper.removeAutoCraftButton(INFO); + recipeHelper.registerScreenClickArea(new Rectangle(88, 32, 28, 23), CraftingTableScreen.class, CRAFTING); + recipeHelper.registerScreenClickArea(new Rectangle(137, 29, 10, 13), InventoryScreen.class, CRAFTING); + recipeHelper.registerScreenClickArea(new Rectangle(97, 16, 14, 30), BrewingStandScreen.class, BREWING); + recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), FurnaceScreen.class, SMELTING); + recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), SmokerScreen.class, SMOKING); + recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), BlastFurnaceScreen.class, BLASTING); + FluidSupportProvider.getInstance().registerFluidProvider(new FluidSupportProvider.FluidProvider() { + @Override + public @NotNull EntryStack itemToFluid(@NotNull EntryStack itemStack) { + Item item = itemStack.getItem(); + if (item instanceof BucketItem) + return EntryStack.create(((BucketItem) item).fluid, 1000); + return EntryStack.empty(); + } + }); +// SubsetsRegistry subsetsRegistry = SubsetsRegistry.INSTANCE; +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food", EntryStack.create(Items.MILK_BUCKET)); +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food/roughlyenoughitems:cookies", EntryStack.create(Items.COOKIE)); + } + + @Override + public int getPriority() { + return -1; + } + +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java new file mode 100644 index 000000000..79116da14 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java @@ -0,0 +1,64 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin; + +import com.google.common.collect.Ordering; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.REIHelper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; +import net.minecraft.entity.effect.StatusEffectInstance; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class DefaultPotionEffectExclusionZones implements Supplier> { + @Override + public List get() { + if (!(REIHelper.getInstance().getPreviousContainerScreen() instanceof AbstractInventoryScreen) || !((AbstractInventoryScreen) REIHelper.getInstance().getPreviousContainerScreen()).offsetGuiForEffects) + return Collections.emptyList(); + Collection activePotionEffects = MinecraftClient.getInstance().player.getStatusEffects(); + if (activePotionEffects.isEmpty()) + return Collections.emptyList(); + ContainerScreen containerScreen = REIHelper.getInstance().getPreviousContainerScreen(); + List list = new ArrayList<>(); + int x = containerScreen.x - 124; + int y = containerScreen.y; + int height = 33; + if (activePotionEffects.size() > 5) + height = 132 / (activePotionEffects.size() - 1); + for (StatusEffectInstance instance : Ordering.natural().sortedCopy(activePotionEffects)) { + list.add(new Rectangle(x, y, 166, height)); + y += height; + } + return list; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java new file mode 100644 index 000000000..099bd1161 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java @@ -0,0 +1,58 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.REIHelper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; +import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; +import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; +import net.minecraft.container.CraftingContainer; + +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class DefaultRecipeBookExclusionZones implements Supplier> { + + @Override + public List get() { + if (!(MinecraftClient.getInstance().currentScreen instanceof RecipeBookProvider) || !(REIHelper.getInstance().getPreviousContainerScreen().getContainer() instanceof CraftingContainer) || + !MinecraftClient.getInstance().player.getRecipeBook().isGuiOpen(((CraftingContainer) REIHelper.getInstance().getPreviousContainerScreen().getContainer()).getCategory())) + return Collections.emptyList(); + RecipeBookWidget recipeBookWidget = ((RecipeBookProvider) MinecraftClient.getInstance().currentScreen).getRecipeBookWidget(); + ContainerScreen containerScreen = REIHelper.getInstance().getPreviousContainerScreen(); + List l = Lists.newArrayList(new Rectangle(containerScreen.x - 4 - 145, containerScreen.y, 4 + 145 + 30, containerScreen.containerHeight)); + int size = recipeBookWidget.tabButtons.size(); + if (size > 0) + l.add(new Rectangle(containerScreen.x - 4 - 145 - 30, containerScreen.y, 30, size * 27)); + return l; + } + +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultServerContainerPlugin.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultServerContainerPlugin.java new file mode 100644 index 000000000..cdbfa789b --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultServerContainerPlugin.java @@ -0,0 +1,40 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin; + +import me.shedaniel.rei.plugin.containers.CraftingContainerInfoWrapper; +import me.shedaniel.rei.server.ContainerInfoHandler; +import net.minecraft.container.*; +import net.minecraft.util.Identifier; + +public class DefaultServerContainerPlugin implements Runnable { + @Override + public void run() { + ContainerInfoHandler.registerContainerInfo(new Identifier("minecraft", "plugins/crafting"), CraftingContainerInfoWrapper.create(CraftingTableContainer.class)); + ContainerInfoHandler.registerContainerInfo(new Identifier("minecraft", "plugins/crafting"), CraftingContainerInfoWrapper.create(PlayerContainer.class)); + ContainerInfoHandler.registerContainerInfo(new Identifier("minecraft", "plugins/smelting"), CraftingContainerInfoWrapper.create(FurnaceContainer.class)); + ContainerInfoHandler.registerContainerInfo(new Identifier("minecraft", "plugins/smoking"), CraftingContainerInfoWrapper.create(SmokerContainer.class)); + ContainerInfoHandler.registerContainerInfo(new Identifier("minecraft", "plugins/blasting"), CraftingContainerInfoWrapper.create(BlastFurnaceContainer.class)); + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java new file mode 100644 index 000000000..f7106c04d --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java @@ -0,0 +1,102 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.autocrafting; + +import me.shedaniel.rei.api.AutoTransferHandler; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.TransferRecipeDisplay; +import me.shedaniel.rei.plugin.cooking.DefaultCookingDisplay; +import me.shedaniel.rei.plugin.crafting.DefaultCraftingDisplay; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.container.CraftingContainer; +import net.minecraft.container.CraftingTableContainer; +import net.minecraft.container.PlayerContainer; +import net.minecraft.recipe.Recipe; +import org.jetbrains.annotations.NotNull; + +@Environment(EnvType.CLIENT) +public class DefaultRecipeBookHandler implements AutoTransferHandler { + @NotNull + @Override + public Result handle(@NotNull Context context) { + if (context.getRecipe() instanceof TransferRecipeDisplay && ClientHelper.getInstance().canUseMovePackets()) + return Result.createNotApplicable(); + RecipeDisplay display = context.getRecipe(); + if (!(context.getContainer() instanceof CraftingContainer)) + return Result.createNotApplicable(); + CraftingContainer container = (CraftingContainer) context.getContainer(); + if (display instanceof DefaultCraftingDisplay) { + DefaultCraftingDisplay craftingDisplay = (DefaultCraftingDisplay) display; + if (craftingDisplay.getOptionalRecipe().isPresent()) { + int h = -1, w = -1; + if (container instanceof CraftingTableContainer) { + h = 3; + w = 3; + } else if (container instanceof PlayerContainer) { + h = 2; + w = 2; + } + if (h == -1 || w == -1) + return Result.createNotApplicable(); + Recipe recipe = (craftingDisplay).getOptionalRecipe().get(); + if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w) + return Result.createFailed(I18n.translate("error.rei.transfer.too_small", h, w)); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().openScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeBookProvider) + ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookWidget().ghostSlots.reset(); + context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } else if (display instanceof DefaultCookingDisplay) { + DefaultCookingDisplay defaultDisplay = (DefaultCookingDisplay) display; + if (defaultDisplay.getOptionalRecipe().isPresent()) { + Recipe recipe = (defaultDisplay).getOptionalRecipe().get(); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().openScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeBookProvider) + ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookWidget().ghostSlots.reset(); + context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } + return Result.createNotApplicable(); + } + + @Override + public double getPriority() { + return -20; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java new file mode 100644 index 000000000..df9a19a4a --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java @@ -0,0 +1,182 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.beacon; + +import com.google.common.collect.Lists; +import me.shedaniel.clothconfig2.ClothConfigInitializer; +import me.shedaniel.clothconfig2.api.ScissorsHandler; +import me.shedaniel.clothconfig2.api.ScrollingContainer; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.widgets.Slot; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.entries.RecipeEntry; +import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.shedaniel.rei.plugin.DefaultPlugin; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Element; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Objects; + +public class DefaultBeaconBaseCategory implements RecipeCategory { + @Override + public Identifier getIdentifier() { + return DefaultPlugin.BEACON; + } + + @Override + public String getCategoryName() { + return I18n.translate("category.rei.beacon_base"); + } + + @Override + public EntryStack getLogo() { + return EntryStack.create(Blocks.BEACON); + } + + @Override + public RecipeEntry getSimpleRenderer(DefaultBeaconBaseDisplay recipe) { + String name = getCategoryName(); + return new RecipeEntry() { + @Override + public int getHeight() { + return 10 + MinecraftClient.getInstance().textRenderer.fontHeight; + } + + @Override + public void render(MatrixStack matrices, Rectangle rectangle, int mouseX, int mouseY, float delta) { + MinecraftClient.getInstance().textRenderer.draw(matrices, name, rectangle.x + 5, rectangle.y + 6, -1); + } + }; + } + + @Override + public List setupDisplay(DefaultBeaconBaseDisplay display, Rectangle bounds) { + List widgets = Lists.newArrayList(); + widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 8, bounds.y + 3)).entry(getLogo())); + Rectangle rectangle = new Rectangle(bounds.getCenterX() - (bounds.width / 2) - 1, bounds.y + 23, bounds.width + 2, bounds.height - 28); + widgets.add(Widgets.createSlotBase(rectangle)); + widgets.add(new ScrollableSlotsWidget(rectangle, CollectionUtils.map(display.getEntries(), t -> Widgets.createSlot(new Point(0, 0)).disableBackground().entry(t)))); + return widgets; + } + + @Override + public int getDisplayHeight() { + return 140; + } + + @Override + public int getFixedRecipesPerPage() { + return 1; + } + + private static class ScrollableSlotsWidget extends WidgetWithBounds { + private Rectangle bounds; + private List widgets; + private final ScrollingContainer scrolling = new ScrollingContainer() { + @Override + public Rectangle getBounds() { + Rectangle bounds = ScrollableSlotsWidget.this.getBounds(); + return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); + } + + @Override + public int getMaxScrollHeight() { + return MathHelper.ceil(widgets.size() / 8f) * 18; + } + }; + + public ScrollableSlotsWidget(Rectangle bounds, List widgets) { + this.bounds = Objects.requireNonNull(bounds); + this.widgets = Lists.newArrayList(widgets); + } + + @Override + public boolean mouseScrolled(double double_1, double double_2, double double_3) { + if (containsMouse(double_1, double_2)) { + scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); + return true; + } + return false; + } + + @NotNull + @Override + public Rectangle getBounds() { + return bounds; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (scrolling.updateDraggingState(mouseX, mouseY, button)) + return true; + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) + return true; + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + scrolling.updatePosition(delta); + Rectangle innerBounds = scrolling.getScissorBounds(); + ScissorsHandler.INSTANCE.scissor(innerBounds); + for (int y = 0; y < MathHelper.ceil(widgets.size() / 8f); y++) { + for (int x = 0; x < 8; x++) { + int index = y * 8 + x; + if (widgets.size() <= index) + break; + Slot widget = widgets.get(index); + widget.getBounds().setLocation(bounds.x + 1 + x * 18, (int) (bounds.y + 1 + y * 18 - scrolling.scrollAmount)); + widget.render(matrices, mouseX, mouseY, delta); + } + } + ScissorsHandler.INSTANCE.removeLastScissor(); + ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); + scrolling.renderScrollBar(0xff000000, 1, REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); + ScissorsHandler.INSTANCE.removeLastScissor(); + } + + @Override + public List children() { + return widgets; + } + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java new file mode 100644 index 000000000..6749a9f4a --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java @@ -0,0 +1,64 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.beacon; + +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +import java.util.Collections; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class DefaultBeaconBaseDisplay implements RecipeDisplay { + + private List entries; + + public DefaultBeaconBaseDisplay(List entries) { + this.entries = EntryStack.ofItemStacks(entries); + } + + @Override + public List> getInputEntries() { + return Collections.singletonList(entries); + } + + public List getEntries() { + return entries; + } + + @Override + public List getOutputEntries() { + return Collections.emptyList(); + } + + @Override + public Identifier getRecipeCategory() { + return DefaultPlugin.BEACON; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java new file mode 100644 index 000000000..e34d580a7 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java @@ -0,0 +1,44 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.blasting; + +import me.shedaniel.rei.plugin.DefaultPlugin; +import me.shedaniel.rei.plugin.cooking.DefaultCookingDisplay; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.recipe.BlastingRecipe; +import net.minecraft.util.Identifier; + +@Environment(EnvType.CLIENT) +public class DefaultBlastingDisplay extends DefaultCookingDisplay { + + public DefaultBlastingDisplay(BlastingRecipe recipe) { + super(recipe); + } + + @Override + public Identifier getRecipeCategory() { + return DefaultPlugin.BLASTING; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/BrewingRecipe.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/BrewingRecipe.java new file mode 100644 index 000000000..5f4a0a12f --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/BrewingRecipe.java @@ -0,0 +1,41 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.brewing; + +import net.minecraft.item.Item; +import net.minecraft.recipe.Ingredient; + +public class BrewingRecipe { + + public final Item input; + public final Ingredient ingredient; + public final Item output; + + public BrewingRecipe(Item input, Ingredient ingredient, Item output) { + this.input = input; + this.ingredient = ingredient; + this.output = output; + } + +} \ No newline at end of file diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java new file mode 100644 index 000000000..671c70cb3 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java @@ -0,0 +1,84 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.brewing; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.item.Items; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; + +import java.util.List; + +@Environment(EnvType.CLIENT) +public class DefaultBrewingCategory implements RecipeCategory { + + @Override + public Identifier getIdentifier() { + return DefaultPlugin.BREWING; + } + + @Override + public EntryStack getLogo() { + return EntryStack.create(Blocks.BREWING_STAND); + } + + @Override + public String getCategoryName() { + return I18n.translate("category.rei.brewing"); + } + + @Override + public List setupDisplay(DefaultBrewingDisplay display, Rectangle bounds) { + Point startPoint = new Point(bounds.getCenterX() - 52, bounds.getCenterY() - 29); + List widgets = Lists.newArrayList(); + widgets.add(Widgets.createRecipeBase(bounds)); + widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + MinecraftClient.getInstance().getTextureManager().bindTexture(REIHelper.getInstance().getDefaultDisplayTexture()); + helper.drawTexture(matrices, startPoint.x, startPoint.y, 0, 108, 103, 59); + int width = MathHelper.ceil(System.currentTimeMillis() / 250d % 18d); + helper.drawTexture(matrices, startPoint.x + 44, startPoint.y + 28, 103, 163, width, 4); + })); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entry(EntryStack.create(Items.BLAZE_POWDER)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 40, startPoint.y + 1)).entries(display.getInputEntries().get(0)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 63, startPoint.y + 1)).entries(display.getInputEntries().get(1)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 40, startPoint.y + 35)).entries(display.getOutput(0)).disableBackground().markOutput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 63, startPoint.y + 42)).entries(display.getOutput(1)).disableBackground().markOutput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 86, startPoint.y + 35)).entries(display.getOutput(2)).disableBackground().markOutput()); + return widgets; + } + +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java new file mode 100644 index 000000000..1d52b3571 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java @@ -0,0 +1,90 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.brewing; + +import com.google.common.collect.Lists; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment;