Skip to content

Commit

Permalink
Merge branch 'pre-rewrite/fabric/1.20.x' of https://github.com/maruoh…
Browse files Browse the repository at this point in the history
…on/itemscroller into fabric_1.20.x
  • Loading branch information
Andrews54757 committed Jun 18, 2023
2 parents 57da52a + 55ed22b commit d92b874
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 93 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ mod_file_name = itemscroller-fabric
mod_version = craftfix-1.2.7

# Required malilib version
malilib_version = 0.15.3
malilib_version = 0.16.0

# Minecraft, Fabric and mappings versions
minecraft_version_out = 1.19.4
minecraft_version = 1.19.4
mappings_version = 1.19.4+build.1
minecraft_version_out = 1.20.1
minecraft_version = 1.20.1
mappings_version = 1.20.1+build.2

fabric_loader_version = 0.14.17
mod_menu_version = 6.1.0-rc.4
fabric_loader_version = 0.14.21
mod_menu_version = 7.0.1
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Aug 22 17:36:22 EDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
47 changes: 26 additions & 21 deletions src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -21,7 +22,6 @@
public class RenderEventHandler
{
private static final RenderEventHandler INSTANCE = new RenderEventHandler();
private static final MatrixStack FRESH_MATRIX_STACK = new MatrixStack();

private final MinecraftClient mc = MinecraftClient.getInstance();
private int recipeListX;
Expand All @@ -39,7 +39,7 @@ public static RenderEventHandler instance()
return INSTANCE;
}

public void renderRecipeView()
public void renderRecipeView(DrawContext drawContext)
{
if (GuiUtils.getCurrentScreen() instanceof HandledScreen && InputUtils.isRecipeViewOpen())
{
Expand All @@ -55,10 +55,10 @@ public void renderRecipeView()
matrixStack.push();
matrixStack.translate(this.recipeListX, this.recipeListY, 0);
matrixStack.scale((float) this.scale, (float) this.scale, 1);
RenderSystem.applyModelViewMatrix();

String str = StringUtils.translate("itemscroller.gui.label.recipe_page", (first / countPerPage) + 1, recipes.getTotalRecipeCount() / countPerPage);
this.mc.textRenderer.draw(matrixStack, str, 16, -12, 0xC0C0C0C0);

drawContext.drawText(this.mc.textRenderer, str, 16, -12, 0xC0C0C0C0, false);

for (int i = 0, recipeId = first; recipeId <= lastOnPage; ++i, ++recipeId)
{
Expand All @@ -67,7 +67,7 @@ public void renderRecipeView()
int row = i % this.recipesPerColumn;
int column = i / this.recipesPerColumn;

this.renderStoredRecipeStack(stack, recipeId, row, column, gui, selected, matrixStack);
this.renderStoredRecipeStack(stack, recipeId, row, column, gui, selected, drawContext);
}

if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
Expand All @@ -77,7 +77,7 @@ public void renderRecipeView()
final int recipeId = this.getHoveredRecipeId(mouseX, mouseY, recipes, gui);
RecipePattern recipe = recipeId >= 0 ? recipes.getRecipe(recipeId) : recipes.getSelectedRecipe();

this.renderRecipeItems(recipe, recipes.getRecipeCountPerPage(), gui);
this.renderRecipeItems(recipe, recipes.getRecipeCountPerPage(), gui, drawContext);
}

matrixStack.pop();
Expand All @@ -86,9 +86,9 @@ public void renderRecipeView()
}
}

public void onDrawScreenPost(MinecraftClient mc)
public void onDrawScreenPost(MinecraftClient mc, DrawContext drawContext)
{
this.renderRecipeView();
this.renderRecipeView(drawContext);

if (GuiUtils.getCurrentScreen() instanceof HandledScreen)
{
Expand All @@ -113,7 +113,7 @@ public void onDrawScreenPost(MinecraftClient mc)
if (recipeId >= 0)
{
RecipePattern recipe = recipes.getRecipe(recipeId);
this.renderHoverTooltip(mouseX, mouseY, recipe, gui, FRESH_MATRIX_STACK);
this.renderHoverTooltip(mouseX, mouseY, recipe, gui, drawContext);
}
else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
{
Expand All @@ -122,7 +122,7 @@ else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())

if (InventoryUtils.isStackEmpty(stack) == false)
{
InventoryOverlay.renderStackToolTip(mouseX, mouseY, stack, this.mc, FRESH_MATRIX_STACK);
InventoryOverlay.renderStackToolTip(mouseX, mouseY, stack, this.mc, drawContext);
}
}

Expand Down Expand Up @@ -162,13 +162,13 @@ private void calculateRecipePositions(HandledScreen<?> gui)
this.columnWidth = stackBaseHeight + this.numberTextWidth + this.gapColumn;
}

private void renderHoverTooltip(int mouseX, int mouseY, RecipePattern recipe, HandledScreen<?> gui, MatrixStack matrixStack)
private void renderHoverTooltip(int mouseX, int mouseY, RecipePattern recipe, HandledScreen<?> gui, DrawContext drawContext)
{
ItemStack stack = recipe.getResult();

if (InventoryUtils.isStackEmpty(stack) == false)
{
InventoryOverlay.renderStackToolTip(mouseX, mouseY, stack, this.mc, matrixStack);
InventoryOverlay.renderStackToolTip(mouseX, mouseY, stack, this.mc, drawContext);
}
}

Expand Down Expand Up @@ -202,30 +202,30 @@ public int getHoveredRecipeId(int mouseX, int mouseY, RecipeStorage recipes, Han
}

private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int column, HandledScreen<?> gui,
boolean selected, MatrixStack matrixStack)
boolean selected, DrawContext drawContext)
{
final TextRenderer font = this.mc.textRenderer;
final String indexStr = String.valueOf(recipeId + 1);

int x = column * this.columnWidth + this.gapColumn + this.numberTextWidth;
int y = row * this.entryHeight;
this.renderStackAt(stack, x, y, selected);
this.renderStackAt(stack, x, y, selected, drawContext);

float scale = 0.75F;
x = x - (int) (font.getWidth(indexStr) * scale) - 2;
y = row * this.entryHeight + this.entryHeight / 2 - font.fontHeight / 2;

matrixStack = FRESH_MATRIX_STACK;
MatrixStack matrixStack = drawContext.getMatrices();
matrixStack.push();
matrixStack.translate(x, y, 0);
matrixStack.scale(scale, scale, 1);

font.draw(matrixStack, indexStr, 0, 0, 0xFFC0C0C0);
drawContext.drawText(font, indexStr, 0, 0, 0xFFC0C0C0, false);

matrixStack.pop();
}

private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, HandledScreen<?> gui)
private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, HandledScreen<?> gui, DrawContext drawContext)
{
ItemStack[] items = recipe.getRecipeItems();
final int recipeDimensions = (int) Math.ceil(Math.sqrt(recipe.getRecipeLength()));
Expand All @@ -239,7 +239,7 @@ private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, Han
int xOff = col * 17;
int yOff = row * 17;

this.renderStackAt(items[i], x + xOff, y + yOff, false);
this.renderStackAt(items[i], x + xOff, y + yOff, false, drawContext);
}
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte
return ItemStack.EMPTY;
}

private void renderStackAt(ItemStack stack, int x, int y, boolean border)
private void renderStackAt(ItemStack stack, int x, int y, boolean border, DrawContext drawContext)
{
final int w = 16;

Expand All @@ -294,9 +294,14 @@ private void renderStackAt(ItemStack stack, int x, int y, boolean border)

stack = stack.copy();
InventoryUtils.setStackSize(stack, 1);
MatrixStack matrixStack = new MatrixStack();

MatrixStack matrixStack = drawContext.getMatrices();
matrixStack.push();
matrixStack.translate(0, 0, 100.f);
this.mc.getItemRenderer().renderInGui(matrixStack, stack, x, y);

drawContext.drawItem(stack, x, y);

matrixStack.pop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.screen.slot.CraftingResultSlot;

@Mixin(CraftingResultSlot.class)
public interface IMixinCraftingResultSlot
{
@Accessor("input")
CraftingInventory itemscroller_getCraftingInventory();
RecipeInputInventory itemscroller_getCraftingInventory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.world.World;

@Mixin(net.minecraft.screen.CraftingScreenHandler.class)
public abstract class MixinCraftingScreenHandler
{
@Shadow @Final private net.minecraft.inventory.CraftingInventory input;
@Shadow @Final private RecipeInputInventory input;
@Shadow @Final private net.minecraft.inventory.CraftingResultInventory result;
@Shadow @Final private net.minecraft.entity.player.PlayerEntity player;

Expand All @@ -27,10 +27,10 @@ private void onSlotChangedCraftingGrid(net.minecraft.inventory.Inventory invento

@Inject(method = "updateResult", at = @At("RETURN"))
private static void onUpdateResult(
ScreenHandler screenHandler,
ScreenHandler handler,
World world,
PlayerEntity player,
CraftingInventory craftingInv,
RecipeInputInventory craftingInventory,
CraftingResultInventory resultInv,
CallbackInfo ci)
{
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/fi/dy/masa/itemscroller/mixin/MixinGameRenderer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.MerchantScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.MerchantScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.village.TradeOffer;

import fi.dy.masa.itemscroller.config.Configs;
import fi.dy.masa.itemscroller.config.Hotkeys;
import fi.dy.masa.itemscroller.gui.ItemScrollerIcons;
Expand Down Expand Up @@ -138,7 +140,7 @@ private void fixRecipeIndex(CallbackInfo ci)

@Inject(method = "render", at = @At(value = "FIELD",
target = "Lnet/minecraft/client/gui/screen/ingame/MerchantScreen;offers:[Lnet/minecraft/client/gui/screen/ingame/MerchantScreen$WidgetButtonPage;"))
private void renderFavoriteMarker(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci)
private void renderFavoriteMarker(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci)
{
if (Configs.Toggles.VILLAGER_TRADE_FEATURES.getBooleanValue())
{
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/fi/dy/masa/itemscroller/mixin/MixinScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fi.dy.masa.itemscroller.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;

import fi.dy.masa.itemscroller.event.RenderEventHandler;

@Mixin(Screen.class)
public abstract class MixinScreen
{
@Inject(method = "renderWithTooltip", at = @At(value = "RETURN"))
private void onDrawScreenPost(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci)
{
RenderEventHandler.instance().onDrawScreenPost(MinecraftClient.getInstance(), context);
}
}
27 changes: 14 additions & 13 deletions src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import net.minecraft.client.gui.screen.ingame.MerchantScreen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeManager;
Expand Down Expand Up @@ -582,8 +582,8 @@ public static void checkForItemPickup(HandledScreen<?> gui) {
// Picked up or swapped items to the cursor, grab a reference to the slot that
// the items came from
// Note that we are only checking the item here!
if (isStackEmpty(stackCursor) == false && stackCursor.isItemEqual(stackInCursorLast) == false
&& sourceSlotCandidate != null) {
if (isStackEmpty(stackCursor) == false && ItemStack.areItemsEqual(stackCursor, stackInCursorLast) == false && sourceSlotCandidate != null)
{
sourceSlot = new WeakReference<>(sourceSlotCandidate.get());
}
}
Expand Down Expand Up @@ -706,9 +706,8 @@ private static boolean tryMoveSingleItemToOtherInventory(Slot slot,

ItemStack[] originalStacks = getOriginalStacks(container);

// Try to move the temporary single-item stack via the shift-click handler
// method
slot.setStack(stack);
// Try to move the temporary single-item stack via the shift-click handler method
slot.setStackNoCallbacks(stack);
container.quickMove(mc.player, slot.id);

// Successfully moved the item somewhere, now we want to check where it went
Expand All @@ -729,7 +728,7 @@ private static boolean tryMoveSingleItemToOtherInventory(Slot slot,
}

// Restore the original stack to the slot under the cursor (on the client side)
slot.setStack(stackOrig);
slot.setStackNoCallbacks(stackOrig);

return false;
}
Expand Down Expand Up @@ -1781,8 +1780,9 @@ private static IntArrayList getSlotNumbersOfEmptySlotsInPlayerInventory(ScreenHa
return slots;
}

public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2) {
return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areNbtEqual(stack1, stack2);
public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2)
{
return ItemStack.canCombine(stack1, stack2);
}

private static boolean areSlotsInSameInventory(Slot slot1, Slot slot2) {
Expand Down Expand Up @@ -1818,9 +1818,10 @@ private static void restoreOriginalStacks(ScreenHandler container, ItemStack[] o
for (int i = 0; i < originalStacks.length; i++) {
ItemStack stackSlot = container.getSlot(i).getStack();

if (areStacksEqual(stackSlot, originalStacks[i]) == false || (isStackEmpty(stackSlot) == false
&& getStackSize(stackSlot) != getStackSize(originalStacks[i]))) {
container.getSlot(i).setStack(originalStacks[i]);
if (areStacksEqual(stackSlot, originalStacks[i]) == false ||
(isStackEmpty(stackSlot) == false && getStackSize(stackSlot) != getStackSize(originalStacks[i])))
{
container.getSlot(i).setStackNoCallbacks(originalStacks[i]);
}
}
}
Expand Down
Loading

0 comments on commit d92b874

Please sign in to comment.