aboutsummaryrefslogtreecommitdiff
path: root/default-plugin/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-08-30 04:59:38 +0800
committershedaniel <daniel@shedaniel.me>2021-08-30 05:01:17 +0800
commit73200d3dd65aff8428e33312ce6a14a1dcc0b797 (patch)
treee6a73948e6bada7e84680d8e56163f6cc0399626 /default-plugin/src
parent40f5f139812cf4a02c61fcd493e5857d77e2990d (diff)
downloadRoughlyEnoughItems-73200d3dd65aff8428e33312ce6a14a1dcc0b797.tar.gz
RoughlyEnoughItems-73200d3dd65aff8428e33312ce6a14a1dcc0b797.tar.bz2
RoughlyEnoughItems-73200d3dd65aff8428e33312ce6a14a1dcc0b797.zip
Support anvil recipes
Diffstat (limited to 'default-plugin/src')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java6
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/anvil/DefaultAnvilCategory.java76
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/BuiltinPlugin.java2
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/AnvilRecipe.java23
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/DefaultAnvilDisplay.java62
5 files changed, 168 insertions, 1 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
index 2bb9c0925..e469d078c 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
@@ -50,6 +50,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.plugin.autocrafting.recipebook.DefaultRecipeBookHandler;
import me.shedaniel.rei.plugin.client.categories.*;
+import me.shedaniel.rei.plugin.client.categories.anvil.DefaultAnvilCategory;
import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconBaseCategory;
import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconPaymentCategory;
import me.shedaniel.rei.plugin.client.categories.cooking.DefaultCookingCategory;
@@ -59,6 +60,8 @@ import me.shedaniel.rei.plugin.client.exclusionzones.DefaultRecipeBookExclusionZ
import me.shedaniel.rei.plugin.client.favorites.GameModeFavoriteEntry;
import me.shedaniel.rei.plugin.client.favorites.WeatherFavoriteEntry;
import me.shedaniel.rei.plugin.common.displays.*;
+import me.shedaniel.rei.plugin.common.displays.anvil.AnvilRecipe;
+import me.shedaniel.rei.plugin.common.displays.anvil.DefaultAnvilDisplay;
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconBaseDisplay;
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconPaymentDisplay;
import me.shedaniel.rei.plugin.common.displays.brewing.BrewingRecipe;
@@ -150,6 +153,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
new DefaultCompostingCategory(),
new DefaultStrippingCategory(),
new DefaultSmithingCategory(),
+ new DefaultAnvilCategory(),
new DefaultBeaconBaseCategory(),
new DefaultBeaconPaymentCategory(),
new DefaultTillingCategory(),
@@ -173,6 +177,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
registry.addWorkstations(CAMPFIRE, EntryStacks.of(Items.CAMPFIRE), EntryStacks.of(Items.SOUL_CAMPFIRE));
registry.addWorkstations(FUEL, EntryStacks.of(Items.FURNACE), EntryStacks.of(Items.SMOKER), EntryStacks.of(Items.BLAST_FURNACE));
registry.addWorkstations(BREWING, EntryStacks.of(Items.BREWING_STAND));
+ registry.addWorkstations(ANVIL, EntryStacks.of(Items.ANVIL));
registry.addWorkstations(STONE_CUTTING, EntryStacks.of(Items.STONECUTTER));
registry.addWorkstations(COMPOSTING, EntryStacks.of(Items.COMPOSTER));
registry.addWorkstations(SMITHING, EntryStacks.of(Items.SMITHING_TABLE));
@@ -222,6 +227,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
registry.registerRecipeFiller(CampfireCookingRecipe.class, RecipeType.CAMPFIRE_COOKING, DefaultCampfireDisplay::new);
registry.registerRecipeFiller(StonecutterRecipe.class, RecipeType.STONECUTTING, DefaultStoneCuttingDisplay::new);
registry.registerRecipeFiller(UpgradeRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::new);
+ registry.registerFiller(AnvilRecipe.class, DefaultAnvilDisplay::new);
registry.registerFiller(BrewingRecipe.class, DefaultBrewingDisplay::new);
for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) {
registry.add(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue()));
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/anvil/DefaultAnvilCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/anvil/DefaultAnvilCategory.java
new file mode 100644
index 000000000..c11893ed2
--- /dev/null
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/anvil/DefaultAnvilCategory.java
@@ -0,0 +1,76 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.client.categories.anvil;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.math.Point;
+import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.gui.Renderer;
+import me.shedaniel.rei.api.client.gui.widgets.Widget;
+import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
+import me.shedaniel.rei.api.common.category.CategoryIdentifier;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import me.shedaniel.rei.plugin.common.BuiltinPlugin;
+import me.shedaniel.rei.plugin.common.displays.anvil.DefaultAnvilDisplay;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TranslatableComponent;
+import net.minecraft.world.level.block.Blocks;
+
+import java.util.List;
+
+public class DefaultAnvilCategory implements DisplayCategory<DefaultAnvilDisplay> {
+ @Override
+ public CategoryIdentifier<? extends DefaultAnvilDisplay> getCategoryIdentifier() {
+ return BuiltinPlugin.ANVIL;
+ }
+
+ @Override
+ public Component getTitle() {
+ return new TranslatableComponent("block.minecraft.anvil");
+ }
+
+ @Override
+ public Renderer getIcon() {
+ return EntryStacks.of(Blocks.ANVIL);
+ }
+
+ @Override
+ public List<Widget> setupDisplay(DefaultAnvilDisplay display, Rectangle bounds) {
+ Point startPoint = new Point(bounds.getCenterX() - 31, bounds.getCenterY() - 13);
+ List<Widget> widgets = Lists.newArrayList();
+ widgets.add(Widgets.createRecipeBase(bounds));
+ widgets.add(Widgets.createArrow(new Point(startPoint.x + 27, startPoint.y + 4)));
+ widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 5)));
+ widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 22, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput());
+ widgets.add(Widgets.createSlot(new Point(startPoint.x + 4, startPoint.y + 5)).entries(display.getInputEntries().get(1)).markInput());
+ widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
+ return widgets;
+ }
+
+ @Override
+ public int getDisplayHeight() {
+ return 36;
+ }
+}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/BuiltinPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/BuiltinPlugin.java
index 94617a5a9..b0dfa5be7 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/BuiltinPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/BuiltinPlugin.java
@@ -25,6 +25,7 @@ package me.shedaniel.rei.plugin.common;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.plugin.common.displays.*;
+import me.shedaniel.rei.plugin.common.displays.anvil.DefaultAnvilDisplay;
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconBaseDisplay;
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconPaymentDisplay;
import me.shedaniel.rei.plugin.common.displays.brewing.DefaultBrewingDisplay;
@@ -45,6 +46,7 @@ public interface BuiltinPlugin {
CategoryIdentifier<DefaultCompostingDisplay> COMPOSTING = CategoryIdentifier.of("minecraft", "plugins/composting");
CategoryIdentifier<DefaultFuelDisplay> FUEL = CategoryIdentifier.of("minecraft", "plugins/fuel");
CategoryIdentifier<DefaultSmithingDisplay> SMITHING = CategoryIdentifier.of("minecraft", "plugins/smithing");
+ CategoryIdentifier<DefaultAnvilDisplay> ANVIL = CategoryIdentifier.of("minecraft", "plugins/anvil");
CategoryIdentifier<DefaultBeaconBaseDisplay> BEACON_BASE = CategoryIdentifier.of("minecraft", "plugins/beacon_base");
CategoryIdentifier<DefaultBeaconPaymentDisplay> BEACON_PAYMENT = CategoryIdentifier.of("minecraft", "plugins/beacon_payment");
CategoryIdentifier<DefaultTillingDisplay> TILLING = CategoryIdentifier.of("minecraft", "plugins/tilling");
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/AnvilRecipe.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/AnvilRecipe.java
index 550199a62..8c8543475 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/AnvilRecipe.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/AnvilRecipe.java
@@ -23,18 +23,39 @@
package me.shedaniel.rei.plugin.common.displays.anvil;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
+import org.jetbrains.annotations.Nullable;
import java.util.List;
public class AnvilRecipe {
+ @Nullable
+ private final ResourceLocation id;
private final List<ItemStack> leftInput;
private final List<ItemStack> rightInputs;
private final List<ItemStack> outputs;
- public AnvilRecipe(List<ItemStack> leftInput, List<ItemStack> rightInputs, List<ItemStack> outputs) {
+ public AnvilRecipe(@Nullable ResourceLocation id, List<ItemStack> leftInput, List<ItemStack> rightInputs, List<ItemStack> outputs) {
+ this.id = id;
this.leftInput = leftInput;
this.rightInputs = rightInputs;
this.outputs = outputs;
}
+
+ public ResourceLocation getId() {
+ return id;
+ }
+
+ public List<ItemStack> getLeftInput() {
+ return leftInput;
+ }
+
+ public List<ItemStack> getRightInputs() {
+ return rightInputs;
+ }
+
+ public List<ItemStack> getOutputs() {
+ return outputs;
+ }
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/DefaultAnvilDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/DefaultAnvilDisplay.java
new file mode 100644
index 000000000..654d0bdc2
--- /dev/null
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/anvil/DefaultAnvilDisplay.java
@@ -0,0 +1,62 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.common.displays.anvil;
+
+import me.shedaniel.rei.api.common.category.CategoryIdentifier;
+import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
+import me.shedaniel.rei.api.common.entry.EntryIngredient;
+import me.shedaniel.rei.api.common.util.EntryIngredients;
+import me.shedaniel.rei.plugin.common.BuiltinPlugin;
+import net.minecraft.resources.ResourceLocation;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+public class DefaultAnvilDisplay extends BasicDisplay {
+ public DefaultAnvilDisplay(AnvilRecipe recipe) {
+ this(
+ Arrays.asList(
+ EntryIngredients.ofItemStacks(recipe.getLeftInput()),
+ EntryIngredients.ofItemStacks(recipe.getRightInputs())
+ ),
+ Collections.singletonList(EntryIngredients.ofItemStacks(recipe.getOutputs())),
+ Optional.ofNullable(recipe.getId())
+ );
+ }
+
+ public DefaultAnvilDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<ResourceLocation> location) {
+ super(inputs, outputs, location);
+ }
+
+ @Override
+ public CategoryIdentifier<?> getCategoryIdentifier() {
+ return BuiltinPlugin.ANVIL;
+ }
+
+ public static BasicDisplay.Serializer<DefaultAnvilDisplay> serializer() {
+ return BasicDisplay.Serializer.ofSimple(DefaultAnvilDisplay::new);
+ }
+}