diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-06-19 15:12:37 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-06-19 15:12:37 +0800 |
| commit | 463197999f1711ffd453b7246bdc580f9dde3390 (patch) | |
| tree | 2fb28fcb7460465bfa5c230a0628bd26e6ca19b6 /src | |
| parent | 83b53bec070bd595ea8118b6a68979c0b5a180ed (diff) | |
| download | RoughlyEnoughItems-463197999f1711ffd453b7246bdc580f9dde3390.tar.gz RoughlyEnoughItems-463197999f1711ffd453b7246bdc580f9dde3390.tar.bz2 RoughlyEnoughItems-463197999f1711ffd453b7246bdc580f9dde3390.zip | |
Add smithing recipes, close #352
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src')
6 files changed, 119 insertions, 4 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index c251d56da..2ec911944 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -57,6 +57,8 @@ 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; @@ -100,6 +102,7 @@ public class DefaultPlugin implements REIPluginV0 { 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"); @@ -199,6 +202,7 @@ public class DefaultPlugin implements REIPluginV0 { recipeHelper.registerCategory(new DefaultBrewingCategory()); recipeHelper.registerCategory(new DefaultCompostingCategory()); recipeHelper.registerCategory(new DefaultStrippingCategory()); + recipeHelper.registerCategory(new DefaultSmithingCategory()); recipeHelper.registerCategory(new DefaultBeaconBaseCategory()); recipeHelper.registerCategory(new DefaultInformationCategory()); } @@ -215,6 +219,7 @@ public class DefaultPlugin implements REIPluginV0 { 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 (DefaultBrewingDisplay display : BREWING_DISPLAYS) { recipeHelper.registerDisplay(display); } @@ -245,7 +250,7 @@ public class DefaultPlugin implements REIPluginV0 { map.put(entry.getKey(), entry.getFloatValue()); } List<ItemConvertible> stacks = new LinkedList<>(map.keySet()); - stacks.sort((first, second) -> (int) ((map.get(first) - map.get(second)) * 100)); + stacks.sort(Comparator.comparing(map::get)); for (int i = 0; i < stacks.size(); i += MathHelper.clamp(48, 1, stacks.size() - i)) { List<ItemConvertible> thisStacks = Lists.newArrayList(); for (int j = i; j < i + 48; j++) @@ -254,7 +259,7 @@ public class DefaultPlugin implements REIPluginV0 { recipeHelper.registerDisplay(new DefaultCompostingDisplay(MathHelper.floor(i / 48f), thisStacks, map, Lists.newArrayList(map.keySet()), new ItemStack[]{new ItemStack(Items.BONE_MEAL)})); } DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getId(b.getKey()))).forEach(set -> { - recipeHelper.registerDisplay(new DefaultStrippingDisplay(new ItemStack(set.getKey()), new ItemStack(set.getValue()))); + 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))); } @@ -263,6 +268,7 @@ public class DefaultPlugin implements REIPluginV0 { 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(); for (EntryStack stack : EntryRegistry.getInstance().getStacksList()) @@ -381,6 +387,7 @@ public class DefaultPlugin implements REIPluginV0 { 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<Item> axes = MinecraftClient.getInstance().getNetworkHandler().getTagManager().items().get(new Identifier("fabric", "axes")); if (axes != null) { diff --git a/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingCategory.java b/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingCategory.java new file mode 100644 index 000000000..377cfcfab --- /dev/null +++ b/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingCategory.java @@ -0,0 +1,50 @@ +package me.shedaniel.rei.plugin.smithing; + +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.RecipeCategory; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.minecraft.block.Blocks; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.util.Identifier; + +import java.util.List; + +public class DefaultSmithingCategory implements RecipeCategory<DefaultSmithingDisplay> { + @Override + public Identifier getIdentifier() { + return DefaultPlugin.SMITHING; + } + + @Override + public String getCategoryName() { + return I18n.translate("category.rei.smithing"); + } + + @Override + public EntryStack getLogo() { + return EntryStack.create(Blocks.SMITHING_TABLE); + } + + @Override + public List<Widget> setupDisplay(DefaultSmithingDisplay 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()).disableBackground().markOutput()); + return widgets; + } + + @Override + public int getDisplayHeight() { + return 36; + } +} diff --git a/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java new file mode 100644 index 000000000..0fff256f6 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java @@ -0,0 +1,51 @@ +package me.shedaniel.rei.plugin.smithing; + +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 me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.recipe.SmithingRecipe; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class DefaultSmithingDisplay implements RecipeDisplay { + @NotNull + private List<List<EntryStack>> input; + @NotNull + private List<EntryStack> output; + + public DefaultSmithingDisplay(@NotNull SmithingRecipe recipe) { + this( + Lists.newArrayList( + CollectionUtils.map(recipe.base.getMatchingStacksClient(), EntryStack::create), + CollectionUtils.map(recipe.addition.getMatchingStacksClient(), EntryStack::create) + ), + Collections.singletonList(EntryStack.create(recipe.getOutput())) + ); + } + + public DefaultSmithingDisplay(@NotNull List<List<EntryStack>> input, @NotNull List<EntryStack> output) { + this.input = input; + this.output = output; + if (this.input.size() != 2) throw new IllegalArgumentException("input must have 2 entries."); + } + + @Override + public List<List<EntryStack>> getInputEntries() { + return input; + } + + @Override + public List<EntryStack> getOutputEntries() { + return output; + } + + @Override + public Identifier getRecipeCategory() { + return DefaultPlugin.SMITHING; + } +} diff --git a/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java index bcf091338..046d5eb5f 100644 --- a/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java @@ -33,9 +33,13 @@ import java.util.Collections; import java.util.List; public class DefaultStrippingDisplay implements RecipeDisplay { - private EntryStack in, out; + public DefaultStrippingDisplay(EntryStack in, EntryStack out) { + this.in = in; + this.out = out; + } + public DefaultStrippingDisplay(ItemStack in, ItemStack out) { this.in = EntryStack.create(in); this.out = EntryStack.create(out); diff --git a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index f90985f88..b4eda390e 100755 --- a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -28,6 +28,7 @@ "category.rei.brewing.result": "Resulted Potion", "category.rei.composting": "Composting", "category.rei.stripping": "Stripping", + "category.rei.smithing": "Smithing", "category.rei.beacon_base": "Beacon Base", "category.rei.information": "Information", "text.rei.composting.chance": "§e%d%% Chance", diff --git a/src/main/resources/rei.aw b/src/main/resources/rei.aw index aab46636c..9b89ab08c 100644 --- a/src/main/resources/rei.aw +++ b/src/main/resources/rei.aw @@ -10,4 +10,6 @@ accessible field net/minecraft/client/gui/screen/ingame/ContainerScreen containe accessible field net/minecraft/client/gui/screen/ingame/ContainerScreen containerHeight I accessible field net/minecraft/client/gui/screen/ingame/ContainerScreen focusedSlot Lnet/minecraft/screen/slot/Slot; accessible field net/minecraft/client/gui/widget/TexturedButtonWidget texture Lnet/minecraft/util/Identifier; -accessible method net/minecraft/client/gui/DrawableHelper drawTexturedQuad (Lnet/minecraft/util/math/Matrix4f;IIIIIFFFF)V
\ No newline at end of file +accessible method net/minecraft/client/gui/DrawableHelper drawTexturedQuad (Lnet/minecraft/util/math/Matrix4f;IIIIIFFFF)V +accessible field net/minecraft/recipe/SmithingRecipe base Lnet/minecraft/recipe/Ingredient; +accessible field net/minecraft/recipe/SmithingRecipe addition Lnet/minecraft/recipe/Ingredient; |
