Skip to content

Commit

Permalink
Start of crafting interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Permdog99 committed Jan 18, 2025
1 parent 935e2fd commit f18312a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import xyz.violaflower.legacy_tweaks.util.client.screen.graphics.GraphicsUtil;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;
import xyz.violaflower.legacy_tweaks.util.common.sound.SoundUtil;
import xyz.violaflower.legacy_tweaks.util.common.sound.Sounds;

public abstract class LegacyAutoCraftingScreen <T extends AbstractContainerMenu> extends LegacyAbstractContainerScreen<T> {
public float leftPos;
public float topPos;
public float imageWidth;
public float imageHeight;

public LegacyAutoCraftingScreen(T menu, Inventory playerInventory, Component title) {
super(menu, playerInventory, title);
if (useSmallCrafting()) {
this.imageWidth = 591f / 2f;
} else {
this.imageWidth = 689f / 2f;
}
this.imageHeight = 424f / 2f;
this.leftPos = ((this.width + this.imageWidth) / 2);
this.topPos = ((this.height + this.imageHeight) / 2) - 20f;
}

@Override
protected void init() {
SoundUtil.playFullPitchSound(Sounds.PRESS, SoundSource.MASTER);
this.leftPos = this.leftPos - (useSmallCrafting() ? 0f : 40f);
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {

}

@Override
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderBg(guiGraphics, partialTick, mouseX, mouseY);
}

@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
this.leftPos = this.leftPos - (useSmallCrafting() ? 0f : 40f);
if (useSmallCrafting()) {
GraphicsUtil.blit(guiGraphics, Sprites.SMALL_CRAFTING_1080, this.leftPos, this.topPos, this.imageWidth, this.imageHeight, 0f, 0f, 591f, 424f, 700f, 440f);
} else {
GraphicsUtil.blit(guiGraphics, Sprites.LARGE_CRAFTING_1080, this.leftPos, this.topPos, this.imageWidth, this.imageHeight, 0f, 0f, 689f, 424f, 700f, 440f);
}
}

public boolean useSmallCrafting() {
return menu instanceof InventoryMenu;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory;

import com.mojang.datafixers.util.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import xyz.violaflower.legacy_tweaks.client.gui.extention.SlotExtension;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.crafting.LegacyRecipeBookCraftingScreen;
import xyz.violaflower.legacy_tweaks.tweaks.Tweaks;
import xyz.violaflower.legacy_tweaks.util.client.screen.ScreenUtil;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;
Expand Down Expand Up @@ -131,11 +133,12 @@ protected void init() {
if (this.leftPos == fjd) this.leftPos = fje;
if (showRecipeBook()) {
this.addRenderableWidget(new ImageButton(this.leftPos + 160 - classicCraftingOffset - noOffhandOffset, this.topPos + 78 - noOffhandAndClassicCraftingOffset, 19, 18, RecipeBookComponent.RECIPE_BUTTON_SPRITES, button -> {
this.recipeBookComponent.toggleVisibility();
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth - 39);
if (this.leftPos == fjd) this.leftPos = fje;
button.setPosition(this.leftPos + 160 - classicCraftingOffset - noOffhandOffset, this.topPos + 78 - noOffhandAndClassicCraftingOffset);
this.buttonClicked = true;
// this.recipeBookComponent.toggleVisibility();
// this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth - 39);
// if (this.leftPos == fjd) this.leftPos = fje;
// button.setPosition(this.leftPos + 160 - classicCraftingOffset - noOffhandOffset, this.topPos + 78 - noOffhandAndClassicCraftingOffset);
// this.buttonClicked = true;
this.minecraft.setScreen(new LegacyRecipeBookCraftingScreen(this.minecraft.player, this));
}));
this.addWidget(this.recipeBookComponent);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.crafting;

import com.mojang.datafixers.util.Pair;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import org.jetbrains.annotations.NotNull;
import xyz.violaflower.legacy_tweaks.client.gui.extention.SlotExtension;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyAutoCraftingScreen;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyInventoryScreen;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;

public class LegacyRecipeBookCraftingScreen extends LegacyAutoCraftingScreen<InventoryMenu> implements RecipeUpdateListener {
private final RecipeBookComponent recipeBookComponent = new RecipeBookComponent();
private final Screen parent;
private static float staticLeftPos;
private static float staticTopPos;
public LegacyRecipeBookCraftingScreen(Player player, Screen parent) {
super(manipulateInventorySlots(player.inventoryMenu), player.getInventory(), Component.translatable("container.crafting"));
this.parent = parent;
staticLeftPos = this.leftPos - (useSmallCrafting() ? 36.5f : 0f);
staticTopPos = this.topPos;
}

@Override
protected void init() {
super.init();

}

@Override
public void recipesUpdated() {
this.recipeBookComponent.recipesUpdated();
}

@Override
public @NotNull RecipeBookComponent getRecipeBookComponent() {
return this.recipeBookComponent;
}

@Override
public void onClose() {
super.onClose();
if (parent instanceof LegacyInventoryScreen) this.minecraft.setScreen(new LegacyInventoryScreen(this.minecraft.player));
}

private static InventoryMenu manipulateInventorySlots(InventoryMenu menu) {
int i = 0;
for (Slot slot : menu.slots) {
if (slot instanceof SlotExtension extension) {
if (i == InventoryMenu.RESULT_SLOT) {
extension.lt$setVisualX(staticLeftPos + 128f);
extension.lt$setVisualY(staticTopPos + 145.45f);
extension.lt$setSize(32);
} else {
// yes, this is painful
if (i >= InventoryMenu.ARMOR_SLOT_START && i < InventoryMenu.ARMOR_SLOT_END) {
extension.lt$setVisualX(staticLeftPos + 10000f);
} else if (i >= InventoryMenu.CRAFT_SLOT_START && i < InventoryMenu.ARMOR_SLOT_END) {
extension.lt$setVisualX(staticLeftPos + slot.x * 21.1559f/16f - 76.9f);
extension.lt$setVisualY(staticTopPos + slot.y * 21.1559f/16f + 115.9f);
extension.lt$setSize(21);
} else if (i == InventoryMenu.SHIELD_SLOT) {
extension.lt$setVisualX(staticLeftPos + 10000f);
} else if (InventoryMenu.INV_SLOT_START <= i) {
extension.lt$setVisualX(staticLeftPos + slot.x * 14.22f/16f + 169.5f);
extension.lt$setVisualY(staticTopPos + slot.y * 14.22f/16f + 55.3f + (InventoryMenu.isHotbarSlot(i) ? 4.5f : 0f));
extension.lt$setSize(14);
}
}
}
i++;
}
return menu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public interface Sprites {
ResourceLocation CHEST_SMALL = ModAsset.guiLocation("container/small_chest.png");
ResourceLocation CHEST_LARGE = ModAsset.guiLocation("container/large_chest.png");

ResourceLocation SMALL_CRAFTING_1080 = ModAsset.guiLocation("container/crafting_interface_small_1080p.png");
ResourceLocation LARGE_CRAFTING_1080 = ModAsset.guiLocation("container/crafting_interface_large_1080p.png");

static ResourceLocation INVENTORY() {
LegacyUI.LegacyInventoryScreenTweak tweak = Tweaks.LEGACY_UI.legacyInventoryScreenTweak;
if (tweak.classicCrafting.isOn()) {
Expand Down
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.

0 comments on commit f18312a

Please sign in to comment.