Skip to content

Commit

Permalink
commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 committed Jan 19, 2025
1 parent 4b0b197 commit daa1595
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface CraftingMenuExtension {
VirtualPlayerInventory lt$getVirtualPlayerInventory();
VirtualCraftingInventory lt$getVirtualCraftingInventory();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package xyz.violaflower.legacy_tweaks.client.gui.extention;

import net.minecraft.world.inventory.Slot;
import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

public interface VirtualCraftingInventory extends Iterable<Slot> {
int getWidth();
int getHeight();
default int getSize() { return getWidth()*getHeight(); }
Slot getCraftingSlot(int num);
// 0-indexed
default Slot getCraftingSlot(int x, int y) { return getCraftingSlot(x+y*getWidth()); }
Slot getResultSlot();

@Override
default @NotNull Iterator<Slot> iterator() {
return new Iterator<>() {
int i = 0;

@Override
public boolean hasNext() {
return i < getSize();
}

@Override
public Slot next() {
return getCraftingSlot(i++);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.inventory.Slot;
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.util.client.screen.graphics.GraphicsUtil;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;
Expand Down Expand Up @@ -44,6 +45,26 @@ private static <T extends AbstractContainerMenu & CraftingMenuExtension> T arr(T
}
menu.lt$getVirtualPlayerInventory().iterateSlots().forEach(f -> ((SlotExtension)f).lt$setSize(14 + 1 / 3f));
}//554 534
int craXo = 0;
int craYo = 0;
VirtualCraftingInventory slots = menu.lt$getVirtualCraftingInventory();
int width1 = slots.getWidth();
for (Slot slot : slots) {
//58,386
if (!(slot instanceof SlotExtension extension)) continue;
extension.lt$setVisualX(59/3f+craXo*70f/3);
extension.lt$setVisualY(387/3f+craYo*70f/3);
if (++craXo >= width1) {
craXo = 0;
craYo++;
}
extension.lt$setSize(21);
}
if (slots.getResultSlot() instanceof SlotExtension extension) {
extension.lt$setSize(97/3f);//381 437
extension.lt$setVisualX(380/3f);
extension.lt$setVisualY(436/3f);
}
return menu;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.CraftingRecipe;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import xyz.violaflower.legacy_tweaks.client.gui.extention.CraftingMenuExtension;
import xyz.violaflower.legacy_tweaks.client.gui.extention.VirtualCraftingInventory;
import xyz.violaflower.legacy_tweaks.client.gui.extention.VirtualPlayerInventory;

import java.util.Iterator;

@Mixin(CraftingMenu.class)
public abstract class CraftingMenuMixin extends RecipeBookMenu<CraftingInput, CraftingRecipe> implements CraftingMenuExtension {
@Shadow @Final private static int CRAFT_SLOT_START;

@Shadow @Final public static int RESULT_SLOT;

public CraftingMenuMixin(MenuType<?> menuType, int containerId) {
super(menuType, containerId);
}

@Unique
private void assertSlot(int slot, int min, int max) {
if (slot >= min && slot < max) return;
throw new IllegalArgumentException();
}
@Override
public VirtualPlayerInventory lt$getVirtualPlayerInventory() {
return new VirtualPlayerInventory() {
private void assertSlot(int slot, int min, int max) {
if (slot >= min && slot < max) return;
throw new IllegalArgumentException();
}
@Override
public Slot getSlot(int slot) {
assertSlot(slot, 0, 36);
Expand Down Expand Up @@ -107,4 +115,30 @@ public Slot next() {
}
};
}

@Override
public VirtualCraftingInventory lt$getVirtualCraftingInventory() {
return new VirtualCraftingInventory() {
@Override
public int getWidth() {
return CraftingMenuMixin.this.getGridWidth();
}

@Override
public int getHeight() {
return CraftingMenuMixin.this.getGridHeight();
}

@Override
public Slot getCraftingSlot(int num) {
assertSlot(num, 0, getSize());
return CraftingMenuMixin.this.getSlot(CRAFT_SLOT_START+num);
}

@Override
public Slot getResultSlot() {
return CraftingMenuMixin.this.getSlot(RESULT_SLOT);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,35 @@
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.CraftingRecipe;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import xyz.violaflower.legacy_tweaks.client.gui.extention.CraftingMenuExtension;
import xyz.violaflower.legacy_tweaks.client.gui.extention.VirtualCraftingInventory;
import xyz.violaflower.legacy_tweaks.client.gui.extention.VirtualPlayerInventory;

import java.util.Iterator;

@Mixin(InventoryMenu.class)
public abstract class InventoryMenuMixin extends RecipeBookMenu<CraftingInput, CraftingRecipe> implements CraftingMenuExtension {
@Shadow @Final public static int CRAFT_SLOT_START;

@Shadow @Final public static int RESULT_SLOT;

public InventoryMenuMixin(MenuType<?> menuType, int containerId) {
super(menuType, containerId);
}

@Unique
private void assertSlot(int slot, int min, int max) {
if (slot >= min && slot < max) return;
throw new IllegalArgumentException();
}

@Override
public VirtualPlayerInventory lt$getVirtualPlayerInventory() {
return new VirtualPlayerInventory() {
private void assertSlot(int slot, int min, int max) {
if (slot >= min && slot < max) return;
throw new IllegalArgumentException();
}
@Override
public Slot getSlot(int slot) {
assertSlot(slot, 0, 36);
Expand Down Expand Up @@ -110,4 +119,30 @@ public Slot next() {
}
};
}

@Override
public VirtualCraftingInventory lt$getVirtualCraftingInventory() {
return new VirtualCraftingInventory() {
@Override
public int getWidth() {
return InventoryMenuMixin.this.getGridWidth();
}

@Override
public int getHeight() {
return InventoryMenuMixin.this.getGridHeight();
}

@Override
public Slot getCraftingSlot(int num) {
assertSlot(num, 0, getSize());
return InventoryMenuMixin.this.getSlot(CRAFT_SLOT_START+num);
}

@Override
public Slot getResultSlot() {
return InventoryMenuMixin.this.getSlot(RESULT_SLOT);
}
};
}
}

0 comments on commit daa1595

Please sign in to comment.