Skip to content

Commit

Permalink
Backport to 1.16.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
wendavid552 committed Jan 19, 2024
1 parent 7d9f311 commit 4eb87b6
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 106 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ mod_file_name = itemscroller-fabric
mod_version = craftaddon-1.0.0

# Required malilib version
malilib_version = 0.12.0
malilib_version = 0.10.0-dev.21+arne.8

# Minecraft, Fabric and mappings versions
minecraft_version_out = 1.18.2
minecraft_version = 1.18.2
mappings_version = 1.18.2+build.1
minecraft_version_out = 1.16.5
minecraft_version = 1.16.5
mappings_version = 1.16.5+build.10

fabric_loader_version = 0.14.14
mod_menu_version = 3.1.0
fabric_loader_version = 0.11.7
mod_menu_version = 1.16.23
74 changes: 47 additions & 27 deletions src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package fi.dy.masa.itemscroller.event;

import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.util.GlAllocationUtils;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3d;
import fi.dy.masa.itemscroller.config.Configs;
import fi.dy.masa.itemscroller.recipes.RecipePattern;
import fi.dy.masa.itemscroller.recipes.RecipeStorage;
import fi.dy.masa.itemscroller.util.AccessorUtils;
import fi.dy.masa.itemscroller.util.ClickPacketBuffer;
import fi.dy.masa.itemscroller.util.InputUtils;
import fi.dy.masa.itemscroller.util.InventoryUtils;
import fi.dy.masa.malilib.render.InventoryOverlay;
Expand All @@ -21,6 +27,9 @@
public class RenderEventHandler
{
private static final RenderEventHandler INSTANCE = new RenderEventHandler();
private static final Vec3d LIGHT0_POS = (new Vec3d( 0.2D, 1.0D, -0.7D)).normalize();
private static final Vec3d LIGHT1_POS = (new Vec3d(-0.2D, 1.0D, 0.7D)).normalize();
private static final FloatBuffer FLOAT_BUFFER = GlAllocationUtils.allocateFloatBuffer(4);
private static final MatrixStack FRESH_MATRIX_STACK = new MatrixStack();

private final MinecraftClient mc = MinecraftClient.getInstance();
Expand Down Expand Up @@ -51,11 +60,9 @@ public void onDrawBackgroundPost(MatrixStack matrixStack)

this.calculateRecipePositions(gui);

matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(this.recipeListX, this.recipeListY, 0);
matrixStack.scale((float) this.scale, (float) this.scale, 1);
RenderSystem.applyModelViewMatrix();
RenderSystem.pushMatrix();
RenderSystem.translatef(this.recipeListX, this.recipeListY, 0);
RenderSystem.scaled(this.scale, this.scale, 1);

String str = StringUtils.translate("itemscroller.gui.label.recipe_page", (first / countPerPage) + 1, recipes.getTotalRecipeCount() / countPerPage);
this.mc.textRenderer.draw(matrixStack, str, 16, -12, 0xC0C0C0C0);
Expand All @@ -80,8 +87,7 @@ public void onDrawBackgroundPost(MatrixStack matrixStack)
this.renderRecipeItems(recipe, recipes.getRecipeCountPerPage(), gui);
}

matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.popMatrix();
RenderSystem.enableBlend(); // Fixes the crafting book icon rendering
}
}
Expand All @@ -92,6 +98,13 @@ public void onDrawScreenPost(MinecraftClient mc)
{
HandledScreen<?> gui = (HandledScreen<?>) this.mc.currentScreen;

int bufferedCount = ClickPacketBuffer.getBufferedActionsCount();

if (bufferedCount > 0)
{
mc.textRenderer.draw(FRESH_MATRIX_STACK, "Buffered slot clicks: " + bufferedCount, 10, 10, 0xFFD0D0D0);
}

if (InputUtils.isRecipeViewOpen() == false)
{
return;
Expand All @@ -104,9 +117,8 @@ public void onDrawScreenPost(MinecraftClient mc)
final int recipeId = this.getHoveredRecipeId(mouseX, mouseY, recipes, gui);

float offset = 300f;
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(0, 0, offset);
RenderSystem.pushMatrix();
RenderSystem.translatef(0f, 0f, offset);

if (recipeId >= 0)
{
Expand All @@ -124,8 +136,7 @@ else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
}
}

matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.popMatrix();
}
}

Expand Down Expand Up @@ -209,18 +220,17 @@ private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int
int y = row * this.entryHeight;
this.renderStackAt(stack, x, y, selected);

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

matrixStack = FRESH_MATRIX_STACK;
matrixStack.push();
matrixStack.translate(x, y, 0);
matrixStack.scale(scale, scale, 1);
RenderSystem.pushMatrix();
RenderSystem.translatef(x, y, 0);
RenderSystem.scaled(scale, scale, 0);

font.draw(matrixStack, indexStr, 0, 0, 0xFFC0C0C0);
font.draw(matrixStack, indexStr, 0, 0, 0xC0C0C0);

matrixStack.pop();
RenderSystem.popMatrix();
}

private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, HandledScreen<?> gui)
Expand All @@ -232,7 +242,7 @@ private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, Han

for (int i = 0, row = 0; row < recipeDimensions; row++)
{
for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++)
for (int col = 0; col < recipeDimensions; col++, i++)
{
int xOff = col * 17;
int yOff = row * 17;
Expand All @@ -255,7 +265,7 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte
{
for (int i = 0, row = 0; row < recipeDimensions; row++)
{
for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++)
for (int col = 0; col < recipeDimensions; col++, i++)
{
int xOff = col * scaledGridEntry;
int yOff = row * scaledGridEntry;
Expand All @@ -276,15 +286,25 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte

private void renderStackAt(ItemStack stack, int x, int y, boolean border)
{
RenderSystem.pushMatrix();

final int w = 16;

if (border)
{
// Draw a light/white border around the stack
RenderUtils.drawOutline(x - 1, y - 1, w + 2, w + 2, 0xFFFFFFFF);
}
RenderUtils.drawRect(x - 1, y - 1, w + 1, 1 , 0xFFFFFFFF);
RenderUtils.drawRect(x - 1, y , 1 , w + 1, 0xFFFFFFFF);
RenderUtils.drawRect(x + w, y - 1, 1 , w + 1, 0xFFFFFFFF);
RenderUtils.drawRect(x , y + w, w + 1, 1 , 0xFFFFFFFF);

RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item
RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item

}
else
{
RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item
}

if (InventoryUtils.isStackEmpty(stack) == false)
{
Expand All @@ -296,9 +316,10 @@ private void renderStackAt(ItemStack stack, int x, int y, boolean border)
this.mc.getItemRenderer().renderInGui(stack, x, y);
this.mc.getItemRenderer().zOffset -= 100;
}

RenderSystem.popMatrix();
}

/*
public static void enableGUIStandardItemLighting(float scale)
{
RenderSystem.pushMatrix();
Expand Down Expand Up @@ -344,5 +365,4 @@ private static FloatBuffer singletonBuffer(float val1, float val2, float val3, f

return FLOAT_BUFFER;
}
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ private void onSlotChangedCraftingGrid(net.minecraft.inventory.Inventory invento

@Inject(method = "updateResult", at = @At("RETURN"))
private static void onUpdateResult(
ScreenHandler screenHandler,
World world,
PlayerEntity player,
CraftingInventory craftingInv,
CraftingResultInventory resultInv,
CallbackInfo ci)
int syncId, World world, PlayerEntity player, CraftingInventory craftingInventory, CraftingResultInventory resultInventory, CallbackInfo ci)
{
//InventoryUtils.onSlotChangedCraftingGrid(player, craftingInv, resultInv);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fi/dy/masa/itemscroller/util/InputUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static boolean isRecipeViewOpen()

public static boolean canShiftDropItems(HandledScreen<?> gui, MinecraftClient mc, int mouseX, int mouseY)
{
if (InventoryUtils.isStackEmpty(gui.getScreenHandler().getCursorStack()) == false)
if (InventoryUtils.isStackEmpty(mc.player.inventory.getCursorStack()) == false)
{
int left = AccessorUtils.getGuiLeft(gui);
int top = AccessorUtils.getGuiTop(gui);
Expand Down Expand Up @@ -127,16 +127,16 @@ public static MoveAmount getMoveAmount(MoveAction action)

public static boolean isAttack(int keyCode)
{
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.attackKey);
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyAttack);
}

public static boolean isUse(int keyCode)
{
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.useKey);
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyUse);
}

public static boolean isPickBlock(int keyCode)
{
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.pickItemKey);
return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyPickItem);
}
}
Loading

0 comments on commit 4eb87b6

Please sign in to comment.