Skip to content

Commit

Permalink
Merge branch 'maruohon-fabric_1.16_snapshots_temp' into fabric_1.15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Jul 6, 2020
2 parents d12091d + b321141 commit e03c559
Show file tree
Hide file tree
Showing 23 changed files with 318 additions and 323 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
}
dependencies {
classpath 'net.fabricmc:fabric-loom:0.2.6-SNAPSHOT'
classpath 'net.fabricmc:fabric-loom:0.4-SNAPSHOT'
}
}

Expand Down
12 changes: 6 additions & 6 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ mod_file_name = itemscroller-fabric
mod_version = 0.15.0-dev

# Required malilib version
malilib_version = 0.10.0-dev.20+beta.1
malilib_version = 0.10.0-dev.21+arne.1

# Minecraft, Fabric and mappings versions
minecraft_version_out = 1.15.2
minecraft_version = 1.15.2
mappings_version = 1.15.2+build.12
minecraft_version_out = 1.16.1
minecraft_version = 1.16.1
mappings_version = 1.16.1+build.18

fabric_loader_version = 0.7.8+build.184
mod_menu_version = 1.8.5+build.23
fabric_loader_version = 0.8.8+build.202
mod_menu_version = 1.12.2+build.17
6 changes: 3 additions & 3 deletions src/main/java/fi/dy/masa/itemscroller/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import fi.dy.masa.malilib.config.options.ConfigBoolean;
import fi.dy.masa.malilib.util.FileUtils;
import fi.dy.masa.malilib.util.JsonUtils;
import net.minecraft.client.gui.screen.ingame.CraftingTableScreen;
import net.minecraft.client.gui.screen.ingame.CraftingScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.container.CraftingResultSlot;
import net.minecraft.screen.slot.CraftingResultSlot;

public class Configs implements IConfigHandler
{
Expand Down Expand Up @@ -109,7 +109,7 @@ public static void loadFromFile()
CraftingHandler.clearDefinitions();

// "net.minecraft.client.gui.inventory.GuiCrafting,net.minecraft.inventory.SlotCrafting,0,1-9", // vanilla Crafting Table
CraftingHandler.addCraftingGridDefinition(CraftingTableScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 9));
CraftingHandler.addCraftingGridDefinition(CraftingScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 9));
//"net.minecraft.client.gui.inventory.PlayerInventoryScreen,net.minecraft.inventory.SlotCrafting,0,1-4", // vanilla player inventory crafting grid
CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4));
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.lwjgl.glfw.GLFW;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.container.Slot;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.math.MathHelper;
import fi.dy.masa.itemscroller.Reference;
import fi.dy.masa.itemscroller.config.Configs;
Expand Down Expand Up @@ -122,11 +122,11 @@ private boolean handleInput(int keyCode, boolean keyState, double dWheel)
final int mouseX = fi.dy.masa.malilib.util.InputUtils.getMouseX();
final int mouseY = fi.dy.masa.malilib.util.InputUtils.getMouseY();

if (GuiUtils.getCurrentScreen() instanceof ContainerScreen &&
if (GuiUtils.getCurrentScreen() instanceof HandledScreen &&
(GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false &&
Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false)
{
ContainerScreen<?> gui = (ContainerScreen<?>) GuiUtils.getCurrentScreen();
HandledScreen<?> gui = (HandledScreen<?>) GuiUtils.getCurrentScreen();
RecipeStorage recipes = RecipeStorage.getInstance();

if (dWheel != 0)
Expand Down Expand Up @@ -204,14 +204,14 @@ public void onMouseMove(int mouseX, int mouseY)

if (this.callbacks.functionalityEnabled() &&
mc.player != null &&
GuiUtils.getCurrentScreen() instanceof ContainerScreen &&
GuiUtils.getCurrentScreen() instanceof HandledScreen &&
Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false)
{
this.handleDragging((ContainerScreen<?>) GuiUtils.getCurrentScreen(), mc, mouseX, mouseY, false);
this.handleDragging((HandledScreen<?>) GuiUtils.getCurrentScreen(), mc, mouseX, mouseY, false);
}
}

private boolean handleDragging(ContainerScreen<?> gui, MinecraftClient mc, int mouseX, int mouseY, boolean isClick)
private boolean handleDragging(HandledScreen<?> gui, MinecraftClient mc, int mouseX, int mouseY, boolean isClick)
{
MoveAction action = InventoryUtils.getActiveMoveAction();

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

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.container.Slot;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.screen.slot.Slot;
import net.minecraft.sound.SoundEvents;
import fi.dy.masa.itemscroller.ItemScroller;
import fi.dy.masa.itemscroller.config.Configs;
Expand Down Expand Up @@ -81,12 +81,12 @@ else if (key == Hotkeys.KEY_OPEN_CONFIG_GUI.getKeybind())
return true;
}

if (this.disabled || mc == null || mc.player == null || (GuiUtils.getCurrentScreen() instanceof ContainerScreen) == false)
if (this.disabled || mc == null || mc.player == null || (GuiUtils.getCurrentScreen() instanceof HandledScreen) == false)
{
return false;
}

ContainerScreen<?> gui = (ContainerScreen<?>) GuiUtils.getCurrentScreen();
HandledScreen<?> gui = (HandledScreen<?>) GuiUtils.getCurrentScreen();
Slot slot = AccessorUtils.getSlotUnderMouse(gui);
RecipeStorage recipes = RecipeStorage.getInstance();
MoveAction moveAction = InputUtils.getDragMoveAction(key);
Expand Down Expand Up @@ -171,13 +171,13 @@ public void onClientTick(MinecraftClient mc)
if (this.disabled == false &&
mc != null &&
mc.player != null &&
GuiUtils.getCurrentScreen() instanceof ContainerScreen &&
GuiUtils.getCurrentScreen() instanceof HandledScreen &&
(GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false &&
Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false &&
Hotkeys.KEY_MASS_CRAFT.getKeybind().isKeybindHeld())
{
Screen guiScreen = GuiUtils.getCurrentScreen();
ContainerScreen<?> gui = (ContainerScreen<?>) guiScreen;
HandledScreen<?> gui = (HandledScreen<?>) guiScreen;
Slot outputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui);

if (outputSlot != null)
Expand All @@ -189,7 +189,7 @@ public void onClientTick(MinecraftClient mc)

CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe);
if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible
mc.interactionManager.clickRecipe(mc.player.container.syncId, bookRecipe, true);
mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true);
} else {
InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true);
}
Expand All @@ -210,7 +210,7 @@ public void onClientTick(MinecraftClient mc)
InventoryUtils.throwAllCraftingResultsToGround(recipe, gui);
bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe);
if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible
mc.interactionManager.clickRecipe(mc.player.container.syncId, bookRecipe, true);
mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true);
} else {
InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true);
}
Expand Down
43 changes: 23 additions & 20 deletions src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
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;
Expand All @@ -28,6 +29,7 @@ public class 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();
private int recipeListX;
Expand All @@ -45,11 +47,11 @@ public static RenderEventHandler instance()
return INSTANCE;
}

public void onDrawBackgroundPost()
public void onDrawBackgroundPost(MatrixStack matrixStack)
{
if (GuiUtils.getCurrentScreen() instanceof ContainerScreen && InputUtils.isRecipeViewOpen())
if (GuiUtils.getCurrentScreen() instanceof HandledScreen && InputUtils.isRecipeViewOpen())
{
ContainerScreen<?> gui = (ContainerScreen<?>) GuiUtils.getCurrentScreen();
HandledScreen<?> gui = (HandledScreen<?>) GuiUtils.getCurrentScreen();
RecipeStorage recipes = RecipeStorage.getInstance();
final int first = recipes.getFirstVisibleRecipeId();
final int countPerPage = recipes.getRecipeCountPerPage();
Expand All @@ -62,7 +64,7 @@ public void onDrawBackgroundPost()
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(str, 16, -12, 0xC0C0C0C0);
this.mc.textRenderer.draw(matrixStack, str, 16, -12, 0xC0C0C0C0);

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

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

if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
Expand All @@ -91,9 +93,9 @@ public void onDrawBackgroundPost()

public void onDrawScreenPost()
{
if (GuiUtils.getCurrentScreen() instanceof ContainerScreen && InputUtils.isRecipeViewOpen())
if (GuiUtils.getCurrentScreen() instanceof HandledScreen && InputUtils.isRecipeViewOpen())
{
ContainerScreen<?> gui = (ContainerScreen<?>) this.mc.currentScreen;
HandledScreen<?> gui = (HandledScreen<?>) this.mc.currentScreen;
RecipeStorage recipes = RecipeStorage.getInstance();

final int mouseX = fi.dy.masa.malilib.util.InputUtils.getMouseX();
Expand All @@ -107,7 +109,7 @@ public void onDrawScreenPost()
if (recipeId >= 0)
{
RecipePattern recipe = recipes.getRecipe(recipeId);
this.renderHoverTooltip(mouseX, mouseY, recipe, gui);
this.renderHoverTooltip(mouseX, mouseY, recipe, gui, FRESH_MATRIX_STACK);
}
else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
{
Expand All @@ -116,15 +118,15 @@ else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())

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

RenderSystem.popMatrix();
}
}

private void calculateRecipePositions(ContainerScreen<?> gui)
private void calculateRecipePositions(HandledScreen<?> gui)
{
RecipeStorage recipes = RecipeStorage.getInstance();
final int gapHorizontal = 2;
Expand Down Expand Up @@ -155,17 +157,17 @@ private void calculateRecipePositions(ContainerScreen<?> gui)
this.columnWidth = stackBaseHeight + this.numberTextWidth + this.gapColumn;
}

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

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

public int getHoveredRecipeId(int mouseX, int mouseY, RecipeStorage recipes, ContainerScreen<?> gui)
public int getHoveredRecipeId(int mouseX, int mouseY, RecipeStorage recipes, HandledScreen<?> gui)
{
if (InputUtils.isRecipeViewOpen())
{
Expand Down Expand Up @@ -194,7 +196,8 @@ public int getHoveredRecipeId(int mouseX, int mouseY, RecipeStorage recipes, Con
return -1;
}

private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int column, ContainerScreen<?> gui, boolean selected)
private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int column, HandledScreen<?> gui,
boolean selected, MatrixStack matrixStack)
{
final TextRenderer font = this.mc.textRenderer;
final String indexStr = String.valueOf(recipeId + 1);
Expand All @@ -204,19 +207,19 @@ private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int
this.renderStackAt(stack, x, y, selected);

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

RenderSystem.pushMatrix();
RenderSystem.translatef(x, y, 0);
RenderSystem.scaled(scale, scale, 0);

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

RenderSystem.popMatrix();
}

private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, ContainerScreen<?> gui)
private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, HandledScreen<?> gui)
{
ItemStack[] items = recipe.getRecipeItems();
final int recipeDimensions = (int) Math.ceil(Math.sqrt(recipe.getRecipeLength()));
Expand All @@ -235,7 +238,7 @@ private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, Con
}
}

private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePattern recipe, int recipeCountPerPage, ContainerScreen<?> gui)
private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePattern recipe, int recipeCountPerPage, HandledScreen<?> gui)
{
final int recipeDimensions = (int) Math.ceil(Math.sqrt(recipe.getRecipeLength()));
int scaledStackDimensions = (int) (16 * this.scale);
Expand Down Expand Up @@ -296,7 +299,7 @@ private void renderStackAt(ItemStack stack, int x, int y, boolean border)
stack = stack.copy();
InventoryUtils.setStackSize(stack, 1);
this.mc.getItemRenderer().zOffset += 100;
this.mc.getItemRenderer().renderGuiItem(this.mc.player, stack, x, y);
this.mc.getItemRenderer().renderInGui(stack, x, y);
this.mc.getItemRenderer().zOffset -= 100;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.client.gui.screen.ingame.MerchantScreen;

@Mixin(MerchantScreen.class)
@Mixin(net.minecraft.client.gui.screen.ingame.MerchantScreen.class)
public interface IMixinMerchantScreen
{
@Accessor("selectedIndex")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fi.dy.masa.itemscroller.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(net.minecraft.client.gui.screen.ingame.HandledScreen.class)
public interface IMixinScreenWithHandler
{
@Invoker("getSlotAt")
net.minecraft.screen.slot.Slot getSlotAtPositionInvoker(double x, double y);

@Invoker("onMouseClick")
void handleMouseClickInvoker(net.minecraft.screen.slot.Slot slotIn, int slotId, int mouseButton, net.minecraft.screen.slot.SlotActionType type);

@Accessor("focusedSlot")
net.minecraft.screen.slot.Slot getHoveredSlot();

@Accessor("x")
int getGuiLeft();

@Accessor("y")
int getGuiTop();

@Accessor("backgroundWidth")
int getGuiSizeX();

@Accessor("backgroundHeight")
int getGuiSizeY();
}
Loading

0 comments on commit e03c559

Please sign in to comment.