Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import dev.architectury.platform.Platform;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.entry.type.BuiltinClientEntryTypes;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
Expand All @@ -56,6 +58,7 @@
import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconPaymentCategory;
import me.shedaniel.rei.plugin.client.categories.cooking.DefaultCookingCategory;
import me.shedaniel.rei.plugin.client.categories.crafting.DefaultCraftingCategory;
import me.shedaniel.rei.plugin.client.categories.grindstone.DefaultGrindstoneCategory;
import me.shedaniel.rei.plugin.client.categories.tag.DefaultTagCategory;
import me.shedaniel.rei.plugin.client.displays.ClientsidedCookingDisplay;
import me.shedaniel.rei.plugin.client.displays.ClientsidedCraftingDisplay;
Expand All @@ -72,6 +75,8 @@
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconPaymentDisplay;
import me.shedaniel.rei.plugin.common.displays.brewing.BrewingRecipe;
import me.shedaniel.rei.plugin.common.displays.brewing.DefaultBrewingDisplay;
import me.shedaniel.rei.plugin.common.displays.grindstone.DefaultGrindstoneDisplay;
import me.shedaniel.rei.plugin.common.displays.grindstone.GrindstoneRecipe;
import me.shedaniel.rei.plugin.common.displays.tag.DefaultTagDisplay;
import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -220,6 +225,7 @@ public void registerCategories(CategoryRegistry registry) {
new DefaultStrippingCategory(),
new DefaultSmithingCategory(),
new DefaultAnvilCategory(),
new DefaultGrindstoneCategory(),
new DefaultBeaconBaseCategory(),
new DefaultBeaconPaymentCategory(),
new DefaultTillingCategory(),
Expand All @@ -238,6 +244,7 @@ public void registerCategories(CategoryRegistry registry) {
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(GRINDSTONE, EntryStacks.of(Items.GRINDSTONE));
registry.addWorkstations(STONE_CUTTING, EntryStacks.of(Items.STONECUTTER));
registry.addWorkstations(COMPOSTING, EntryStacks.of(Items.COMPOSTER));
registry.addWorkstations(SMITHING, EntryStacks.of(Items.SMITHING_TABLE));
Expand Down Expand Up @@ -313,6 +320,8 @@ public void registerDisplays(DisplayRegistry registry) {
.fill(ClientsidedCookingDisplay.Blasting::new);
registry.beginFiller(AnvilRecipe.class)
.fill(DefaultAnvilDisplay::new);
registry.beginFiller(GrindstoneRecipe.class)
.fill(DefaultGrindstoneDisplay::new);
registry.beginFiller(BrewingRecipe.class)
.fill(DefaultBrewingDisplay::new);
registry.beginFiller(TagKey.class)
Expand Down Expand Up @@ -446,7 +455,7 @@ public void registerDisplays(DisplayRegistry registry) {
EntryRegistry.getInstance().getEntryStacks().forEach(stack -> {
if (stack.getType() != VanillaEntryTypes.ITEM) return;
ItemStack itemStack = stack.castValue();
if (!itemStack.isEnchantable()) return;
if (!itemStack.isEnchantable() && !itemStack.is(Items.ELYTRA) && !itemStack.is(Items.SHIELD)) return;
for (Pair<EnchantmentInstance, ItemStack> pair : enchantmentBooks) {
if (!pair.getKey().enchantment().value().canEnchant(itemStack)) continue;
Optional<Pair<ItemStack, Integer>> output = DefaultAnvilDisplay.calculateOutput(itemStack, pair.getValue());
Expand All @@ -455,7 +464,45 @@ public void registerDisplays(DisplayRegistry registry) {
Collections.singletonList(EntryIngredients.of(output.get().getLeft())), Optional.empty(), OptionalInt.of(output.get().getRight())));
}
});


// grindstone combining recipes
BuiltInRegistries.ITEM.forEach(item -> {
ItemStack base = item.getDefaultInstance();
if (!base.isDamageableItem() || !item.components().has(DataComponents.REPAIRABLE)) return;
ItemStack a = base.copy();
a.setDamageValue(base.getMaxDamage() - 1);
ItemStack b = a.copy();
Optional<DefaultGrindstoneDisplay.GrindStoneRecipeResult> output = DefaultGrindstoneDisplay.calculateOutput(a, b);
if (output.isEmpty()) return;
Renderer renderer = EntryStack.of(VanillaEntryTypes.ITEM.getDefinition(), output.get().itemStack());
registry.add(new DefaultGrindstoneDisplay(
List.of(EntryIngredients.of(a), EntryIngredients.of(b)),
List.of(EntryIngredient.of(EntryStack.of(BuiltinClientEntryTypes.RENDERING, renderer))),
Optional.empty(),
OptionalDouble.of(output.get().averageExp())
));
});

// grindstone disenchanting recipes
EntryRegistry.getInstance().getEntryStacks().forEach(stack -> {
if (stack.getType() != VanillaEntryTypes.ITEM) return;
ItemStack itemStack = stack.castValue();
if (!itemStack.isEnchantable() && !itemStack.is(Items.ELYTRA) && !itemStack.is(Items.SHIELD)) return;
for (Pair<EnchantmentInstance, ItemStack> pair : enchantmentBooks) {
if (!pair.getKey().enchantment().value().canEnchant(itemStack)) continue;
Optional<Pair<ItemStack, Integer>> input = DefaultAnvilDisplay.calculateOutput(itemStack, pair.getValue());
if (input.isEmpty()) continue;
Optional<DefaultGrindstoneDisplay.GrindStoneRecipeResult> output = DefaultGrindstoneDisplay.calculateOutput(input.get().getLeft(), ItemStack.EMPTY);
if (output.isEmpty()) continue;
Renderer renderer = EntryStack.of(VanillaEntryTypes.ITEM.getDefinition(), output.get().itemStack());
registry.add(new DefaultGrindstoneDisplay(
List.of(EntryIngredients.of(input.get().getLeft()), EntryIngredient.empty()),
List.of(EntryIngredient.of(EntryStack.of(BuiltinClientEntryTypes.RENDERING, renderer))),
Optional.empty(),
OptionalDouble.of(output.get().averageExp())));
}
});

for (Registry<?> reg : BuiltInRegistries.REGISTRY) {
reg.getTags().forEach(tagPair -> tagPair.unwrap().ifLeft(registry::add));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.grindstone;

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.grindstone.DefaultGrindstoneDisplay;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Blocks;

import java.text.DecimalFormat;
import java.util.List;

public class DefaultGrindstoneCategory implements DisplayCategory<DefaultGrindstoneDisplay> {
@Override
public CategoryIdentifier<? extends DefaultGrindstoneDisplay> getCategoryIdentifier() {
return BuiltinPlugin.GRINDSTONE;
}

@Override
public Component getTitle() {
return Component.translatable("block.minecraft.grindstone");
}

@Override
public Renderer getIcon() {
return EntryStacks.of(Blocks.GRINDSTONE);
}

@Override
public List<Widget> setupDisplay(DefaultGrindstoneDisplay display, Rectangle bounds) {
Point startPoint = new Point(bounds.getCenterX() - 31, bounds.getCenterY() - 20);
List<Widget> widgets = Lists.newArrayList();
widgets.add(Widgets.createRecipeBase(bounds));
widgets.add(Widgets.createArrow(new Point(startPoint.x - 6, startPoint.y + 12)));
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 30, startPoint.y + 13)));
widgets.add(Widgets.createSlot(new Point(startPoint.x - 30, startPoint.y + 2)).entries(display.getInputEntries().get(0)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x - 30, startPoint.y + 23)).entries(display.getInputEntries().get(1)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 30, startPoint.y + 13)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
if (display.getAverageXpReward().isPresent()) {
widgets.add(Widgets.createDrawableWidget((graphics, mouseX, mouseY, delta) -> {
Font font = Minecraft.getInstance().font;
DecimalFormat format = new DecimalFormat("0.#");
Component componentXp = Component.translatable("category.rei.grindstone.xp", format.format(display.getAverageXpReward().getAsDouble()));
Component componentAverage = Component.translatable("category.rei.grindstone.average");
int textboxLeftPos = startPoint.x + 102 - font.width(componentXp) - 2;
int textboxTopPos = startPoint.y + 14 - font.lineHeight / 2;
int xpLeftPos = textboxLeftPos - 2;
int xpTopPos = textboxTopPos;
int xpRightPos = startPoint.x + 102;
graphics.drawString(font, componentXp, textboxLeftPos, textboxTopPos + 2, 0x80ff20);
textboxLeftPos += font.width(componentXp) / 2 - font.width(componentAverage) / 2;
textboxTopPos += font.lineHeight + 3;
graphics.fill(
Math.min(xpLeftPos, textboxLeftPos - 2),
xpTopPos - 2,
Math.max(xpRightPos, + font.width(componentAverage)),
textboxTopPos + 12,
0x4f000000);
graphics.drawString(font, componentAverage, textboxLeftPos, textboxTopPos + 2, 0x80ff20);
}));
}
return widgets;
}

@Override
public int getDisplayHeight() {
return 47;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.shedaniel.rei.plugin.common.displays.brewing.DefaultBrewingDisplay;
import me.shedaniel.rei.plugin.common.displays.cooking.CookingDisplay;
import me.shedaniel.rei.plugin.common.displays.crafting.CraftingDisplay;
import me.shedaniel.rei.plugin.common.displays.grindstone.DefaultGrindstoneDisplay;
import me.shedaniel.rei.plugin.common.displays.tag.DefaultTagDisplay;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -47,6 +48,7 @@ public interface BuiltinPlugin {
CategoryIdentifier<DefaultFuelDisplay> FUEL = CategoryIdentifier.of("minecraft", "plugins/fuel");
CategoryIdentifier<SmithingDisplay> SMITHING = CategoryIdentifier.of("minecraft", "plugins/smithing");
CategoryIdentifier<DefaultAnvilDisplay> ANVIL = CategoryIdentifier.of("minecraft", "plugins/anvil");
CategoryIdentifier<DefaultGrindstoneDisplay> GRINDSTONE = CategoryIdentifier.of("minecraft", "plugins/grindstone");
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");
Expand Down
Loading