Skip to content

Commit

Permalink
oev
Browse files Browse the repository at this point in the history
Jab125 committed Jan 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent daa1595 commit 22d1605
Showing 8 changed files with 105 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.crafting;

import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeBookPage;
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.RecipeBookMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.Recipe;
import xyz.violaflower.legacy_tweaks.client.gui.extention.CraftingMenuExtension;
import xyz.violaflower.legacy_tweaks.client.gui.extention.SlotExtension;
import xyz.violaflower.legacy_tweaks.client.gui.extention.VirtualCraftingInventory;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyAbstractContainerScreen;
import xyz.violaflower.legacy_tweaks.mixin.client.tweak.legacy_ui.screen.container.RecipeBookComponentAccessor;
import xyz.violaflower.legacy_tweaks.mixin.client.tweak.legacy_ui.screen.container.RecipeBookPageAccessor;
import xyz.violaflower.legacy_tweaks.util.client.screen.graphics.GraphicsUtil;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;

import java.util.List;

/// @see net.minecraft.client.gui.screens.inventory.CraftingScreen
public class LegacyQuickCraftingScreen<T extends AbstractContainerMenu & CraftingMenuExtension> extends LegacyAbstractContainerScreen<T> {
private final RecipeBookComponent recipeBookComponent = new RecipeBookComponent();
public <R extends AbstractContainerMenu> LegacyQuickCraftingScreen(R menu, Inventory playerInventory, Component title) {
super(arr((T) menu), playerInventory, title);
// 1035x635 aka 517.5x317.5
@@ -68,6 +84,14 @@ private static <T extends AbstractContainerMenu & CraftingMenuExtension> T arr(T
return menu;
}

@Override
protected void init() {
super.init();
this.recipeBookComponent.init(this.width, this.height, this.minecraft, false, (RecipeBookMenu) this.menu);
//((RecipeBookComponentAccessor) this.recipeBookComponent).callUpdateCollections(true);
this.recipeBookComponent.initVisuals();
}

protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
float trueHeight = 211.66667f;
int xPos = (this.width - this.imageWidth) / 2;
@@ -86,5 +110,48 @@ protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX,
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
super.render(guiGraphics, mouseX, mouseY, partialTick);
this.renderTooltip(guiGraphics, mouseX, mouseY);
List<RecipeCollection> recipeCollections = ((RecipeBookPageAccessor) ((RecipeBookComponentAccessor) this.recipeBookComponent).getRecipeBookPage()).getRecipeCollections();
int i = 0;
for (RecipeCollection recipeCollection : recipeCollections) {
Recipe<CraftingInput> value = (Recipe<CraftingInput>) (Object) recipeCollection.getRecipes().get(0).value();
if (value instanceof CraftingRecipe recipe) {
ItemStack resultItem = value.getResultItem(minecraft.level.registryAccess());
//resultItem = Items.RED_STAINED_GLASS_PANE.getDefaultInstance();
//System.out.println(resultItem);
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(this.leftPos+ 29/3f+i*82/3f, this.topPos+ 116/3f, 0);
if (selected == i) {
guiGraphics.pose().pushPose();;
guiGraphics.blit(Sprites.CRAFTING_SELECTED, 0-6, 0-6, 0, 0, 36, 36, 36, 36);
guiGraphics.pose().popPose();
}
GraphicsUtil.renderItem(guiGraphics, 73/3f, null, minecraft.level, resultItem, 0, 0, 0, 0);
//guiGraphics.pose().scale(73/16f/3f*0.85f, 73/16f/3f*0.85f, 73/16f/3f*0.85f);
//guiGraphics.renderItem(resultItem, 0, 0);
guiGraphics.pose().popPose();

}
if(++i >= 12)break;
}
}

private int selected = 0;

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == InputConstants.KEY_LEFT) {
if (--selected <= 0) selected = 0;
//RecipeBookPage recipeBookPage = ((RecipeBookComponentAccessor) this.recipeBookComponent).getRecipeBookPage();
return true;
} else if (keyCode == InputConstants.KEY_RIGHT) {
if (++selected >= ((RecipeBookPageAccessor) ((RecipeBookComponentAccessor) this.recipeBookComponent).getRecipeBookPage()).getRecipeCollections().size()-1) selected = ((RecipeBookPageAccessor) ((RecipeBookComponentAccessor) this.recipeBookComponent).getRecipeBookPage()).getRecipeCollections().size() - 1;
return true;
} else return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
protected void containerTick() {
super.containerTick();
this.recipeBookComponent.tick();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xyz.violaflower.legacy_tweaks.mixin.client.tweak.legacy_ui.screen.container;

import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeBookPage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(RecipeBookComponent.class)
public interface RecipeBookComponentAccessor {
@Accessor
RecipeBookPage getRecipeBookPage();
@Invoker
void callUpdateCollections(boolean resetPage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.violaflower.legacy_tweaks.mixin.client.tweak.legacy_ui.screen.container;

import net.minecraft.client.gui.screens.recipebook.RecipeBookPage;
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(RecipeBookPage.class)
public interface RecipeBookPageAccessor {
@Accessor
List<RecipeCollection> getRecipeCollections();
}
Original file line number Diff line number Diff line change
@@ -184,9 +184,13 @@ public static void renderItem(GuiGraphics guiGraphics, SlotExtension slot, @Null
}

static void renderItem(GuiGraphics guiGraphics, SlotExtension slot, @Nullable LivingEntity entity, @Nullable Level level, ItemStack stack, int x, int y, int seed, int guiOffset) {
renderItem(guiGraphics, slot.lt$getSize(), entity, level, stack, x, y, seed, guiOffset);
}

public static void renderItem(GuiGraphics guiGraphics, float scale_, @Nullable LivingEntity entity, @Nullable Level level, ItemStack stack, int x, int y, int seed, int guiOffset) {
if (!stack.isEmpty()) {
float scale = (slot.lt$getSize() * (Tweaks.LEGACY_UI.legacyContainerScreenTweak.smallerItemSizes.isOn() ? 0.85f : 1f));
float normalizedScale = slot.lt$getSize() / 16;
float scale = (scale_ * (Tweaks.LEGACY_UI.legacyContainerScreenTweak.smallerItemSizes.isOn() ? 0.85f : 1f));
float normalizedScale = scale_ / 16;
BakedModel bakedmodel = minecraft.getItemRenderer().getModel(stack, level, entity, seed);
PoseStack pose = guiGraphics.pose();
pose.pushPose();
@@ -217,7 +221,6 @@ static void renderItem(GuiGraphics guiGraphics, SlotExtension slot, @Nullable Li

pose.popPose();
}

}

public static void renderFloatingItem(AbstractContainerScreen screen, float scale, GuiGraphics guiGraphics, ItemStack stack, int x, int y, String text) {
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ public interface Sprites {
ResourceLocation SMALL_CRAFTING_1080 = ModAsset.guiLocation("container/crafting_interface_small_1080p.png");
ResourceLocation LARGE_CRAFTING_1080 = ModAsset.guiLocation("container/crafting_interface_large_1080p.png");
ResourceLocation CRAFTING_BASIS = ModAsset.guiLocation("container/crafting3x3basis.png");
ResourceLocation CRAFTING_SELECTED = ModAsset.guiLocation("container/crafting_highlight_l_small.png");

ResourceLocation CRAFTING_TAB_CENTER = ModAsset.getResourceLocation("container/crafting_tab_center");
ResourceLocation CRAFTING_TAB_LEFT_SIDE = ModAsset.getResourceLocation("container/crafting_tab_left_side");
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/resources/legacy_tweaks.mixins.json
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@
"client.tweak.legacy_ui.hud.scoreboard.GuiMixin",
"client.tweak.legacy_ui.hud.vignette.GuiMixin",
"client.tweak.legacy_ui.screen.container.AbstractContainerScreenMixin",
"client.tweak.legacy_ui.screen.container.RecipeBookComponentAccessor",
"client.tweak.legacy_ui.screen.container.RecipeBookPageAccessor",
"client.tweak.legacy_ui.screen.container.container_screen.MenuScreenMixin",
"client.tweak.legacy_ui.screen.container.inventory_screen.MinecraftMixin",
"client.tweak.legacy_ui.screen.pause_screen.MinecraftMixin",

0 comments on commit 22d1605

Please sign in to comment.