From 73dbbed409a86328144f2c75f460426e7baa6ae1 Mon Sep 17 00:00:00 2001 From: Roman / Nea Date: Thu, 2 Jun 2022 09:59:07 +0200 Subject: Loomerings (#152) --- .../notenoughupdates/miscfeatures/SlotLocking.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 743625f5..9292c0d3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; @@ -200,7 +201,7 @@ public class SlotLocking { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - Slot slot = container.getSlotAtPosition(mouseX, mouseY); + Slot slot = ((AccessorGuiContainer) container).doGetSlotAtPosition(mouseX, mouseY); if (slot != null && slot.getSlotIndex() != 8 && slot.inventory == Minecraft.getMinecraft().thePlayer.inventory) { int slotNum = slot.getSlotIndex(); if (slotNum >= 0 && slotNum <= 39) { @@ -280,7 +281,7 @@ public class SlotLocking { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - Slot slot = container.getSlotAtPosition(mouseX, mouseY); + Slot slot = ((AccessorGuiContainer) container).doGetSlotAtPosition(mouseX, mouseY); if (slot != null && slot.getSlotIndex() != 8 && slot.inventory == Minecraft.getMinecraft().thePlayer.inventory) { int slotNum = slot.getSlotIndex(); if (slotNum >= 0 && slotNum <= 39) { @@ -378,10 +379,10 @@ public class SlotLocking { if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { return; } - GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen; + AccessorGuiContainer container = (AccessorGuiContainer) Minecraft.getMinecraft().currentScreen; - int x1 = container.guiLeft + pairingSlot.xDisplayPosition + 8; - int y1 = container.guiTop + pairingSlot.yDisplayPosition + 8; + int x1 = container.getGuiLeft() + pairingSlot.xDisplayPosition + 8; + int y1 = container.getGuiTop() + pairingSlot.yDisplayPosition + 8; int x2 = event.mouseX; int y2 = event.mouseY; @@ -514,7 +515,7 @@ public class SlotLocking { return; } - boolean hoverOverSlot = container.isMouseOverSlot(slot, mouseX, mouseY); + boolean hoverOverSlot = ((AccessorGuiContainer) container).doIsMouseOverSlot(slot, mouseX, mouseY); if (hoverOverSlot || slot.getSlotIndex() >= 9) { Minecraft.getMinecraft().getTextureManager().bindTexture(BOUND); @@ -545,8 +546,8 @@ public class SlotLocking { ); } } else if (pairingSlot != null && lockKeyHeld && slot.getSlotIndex() < 8) { - int x1 = container.guiLeft + pairingSlot.xDisplayPosition; - int y1 = container.guiTop + pairingSlot.yDisplayPosition; + int x1 = ((AccessorGuiContainer)container).getGuiLeft() + pairingSlot.xDisplayPosition; + int y1 = ((AccessorGuiContainer)container).getGuiTop() + pairingSlot.yDisplayPosition; if (mouseX <= x1 || mouseX >= x1 + 16 || mouseY <= y1 || mouseY >= y1 + 16) { @@ -634,8 +635,8 @@ public class SlotLocking { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - int x1 = container.guiLeft + pairingSlot.xDisplayPosition; - int y1 = container.guiTop + pairingSlot.yDisplayPosition; + int x1 = ((AccessorGuiContainer)container).getGuiLeft() + pairingSlot.xDisplayPosition; + int y1 = ((AccessorGuiContainer)container).getGuiTop() + pairingSlot.yDisplayPosition; if (mouseX <= x1 || mouseX >= x1 + 16 || mouseY <= y1 || mouseY >= y1 + 16) { -- cgit From 50dc2122462642a0c3a00b3a3ae6389825dc04df Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 9 Jun 2022 18:04:22 -0400 Subject: Re-license project as LGPL (#157) * add licence files & a few misc chores * add license notices & run auto formatter --- .../notenoughupdates/miscfeatures/SlotLocking.java | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 9292c0d3..3955c363 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.gson.Gson; @@ -30,7 +49,13 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector2f; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.function.Consumer; @@ -546,8 +571,8 @@ public class SlotLocking { ); } } else if (pairingSlot != null && lockKeyHeld && slot.getSlotIndex() < 8) { - int x1 = ((AccessorGuiContainer)container).getGuiLeft() + pairingSlot.xDisplayPosition; - int y1 = ((AccessorGuiContainer)container).getGuiTop() + pairingSlot.yDisplayPosition; + int x1 = ((AccessorGuiContainer) container).getGuiLeft() + pairingSlot.xDisplayPosition; + int y1 = ((AccessorGuiContainer) container).getGuiTop() + pairingSlot.yDisplayPosition; if (mouseX <= x1 || mouseX >= x1 + 16 || mouseY <= y1 || mouseY >= y1 + 16) { @@ -635,8 +660,8 @@ public class SlotLocking { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - int x1 = ((AccessorGuiContainer)container).getGuiLeft() + pairingSlot.xDisplayPosition; - int y1 = ((AccessorGuiContainer)container).getGuiTop() + pairingSlot.yDisplayPosition; + int x1 = ((AccessorGuiContainer) container).getGuiLeft() + pairingSlot.xDisplayPosition; + int y1 = ((AccessorGuiContainer) container).getGuiTop() + pairingSlot.yDisplayPosition; if (mouseX <= x1 || mouseX >= x1 + 16 || mouseY <= y1 || mouseY >= y1 + 16) { -- cgit From 61513e20063d8997ba8a6d0cd7f34ef4ca29cdb6 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Wed, 5 Oct 2022 04:46:26 +0200 Subject: EnchantingSolvers.java (#341) * EnchantingSolvers.java * remove println * register bin overlay Co-authored-by: nopo --- .../notenoughupdates/miscfeatures/SlotLocking.java | 66 ++++++++++++---------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 3955c363..24183f9a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -24,6 +24,7 @@ import com.google.gson.GsonBuilder; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; @@ -43,7 +44,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.apache.commons.lang3.tuple.Triple; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -58,7 +58,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.function.Consumer; public class SlotLocking { private static final SlotLocking INSTANCE = new SlotLocking(); @@ -455,22 +454,21 @@ public class SlotLocking { } } - public void onWindowClick( - Slot slotIn, - int slotId, - int clickedButton, - int clickType, - Consumer> consumer - ) { - LockedSlot locked = getLockedSlot(slotIn); + @SubscribeEvent + public void onWindowClick(SlotClickEvent slotClickEvent) { + LockedSlot locked = getLockedSlot(slotClickEvent.slot); if (locked == null) { return; - } else if (locked.locked || (clickType == 2 && SlotLocking.getInstance().isSlotIndexLocked(clickedButton))) { - consumer.accept(null); - } else if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding && clickType == 1 && + } + if (locked.locked || + (slotClickEvent.clickType == 2 && SlotLocking.getInstance().isSlotIndexLocked(slotClickEvent.clickedButton))) { + slotClickEvent.setCanceled(true); + return; + } + if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding + && slotClickEvent.clickType == 1 && locked.boundTo != -1) { - GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen; - Slot boundSlot = container.inventorySlots.getSlotFromInventory( + Slot boundSlot = slotClickEvent.guiContainer.inventorySlots.getSlotFromInventory( Minecraft.getMinecraft().thePlayer.inventory, locked.boundTo ); @@ -481,29 +479,37 @@ public class SlotLocking { LockedSlot boundLocked = getLockedSlot(boundSlot); - int id = slotIn.getSlotIndex(); - if (id >= 9 && locked.boundTo >= 0 && locked.boundTo < 8) { - if (!boundLocked.locked) { - consumer.accept(Triple.of(slotId, locked.boundTo, 2)); - if (boundLocked == DEFAULT_LOCKED_SLOT) { - LockedSlot[] lockedSlots = getDataForProfile(); - lockedSlots[locked.boundTo] = new LockedSlot(); - lockedSlots[locked.boundTo].boundTo = id; - } else { - boundLocked.boundTo = id; - } + int from, to; + int id = slotClickEvent.slot.getSlotIndex(); + if (id >= 9 && 0 <= locked.boundTo && locked.boundTo < 8 && !boundLocked.locked) { + from = id; + to = locked.boundTo; + if (boundLocked == DEFAULT_LOCKED_SLOT) { + LockedSlot[] lockedSlots = getDataForProfile(); + lockedSlots[locked.boundTo] = new LockedSlot(); + lockedSlots[locked.boundTo].boundTo = id; + } else { + boundLocked.boundTo = id; } - } else if (id >= 0 && id < 8 && locked.boundTo >= 9 && locked.boundTo <= 39) { + } else if (0 <= id && id < 8 && locked.boundTo >= 9 && locked.boundTo <= 39) { if (boundLocked.locked || boundLocked.boundTo != id) { locked.boundTo = -1; + return; } else { - int boundTo = boundSlot.slotNumber; - consumer.accept(Triple.of(boundTo, id, 2)); + from = boundSlot.slotNumber; + to = id; } + } else { + return; } + Minecraft.getMinecraft().playerController.windowClick( + slotClickEvent.guiContainer.inventorySlots.windowId, + from, to, 2, Minecraft.getMinecraft().thePlayer + ); + slotClickEvent.setCanceled(true); } else if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding && locked.boundTo != -1 && NotEnoughUpdates.INSTANCE.config.slotLocking.bindingAlsoLocks) { - consumer.accept(null); + slotClickEvent.setCanceled(true); } } -- cgit From 036d00a64e89ce50574c2cc85965ae10ea00e1cc Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Fri, 7 Oct 2022 06:07:11 +1100 Subject: Fix slot binding not working from armour slots (#343) i love minecraft forge for minecraft version 1.8 minor version 9 --- .../github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 24183f9a..8a487739 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -502,6 +502,10 @@ public class SlotLocking { } else { return; } + if (from == 39) from = 5; + if (from == 38) from = 6; + if (from == 37) from = 7; + if (from == 36) from = 8; Minecraft.getMinecraft().playerController.windowClick( slotClickEvent.guiContainer.inventorySlots.windowId, from, to, 2, Minecraft.getMinecraft().thePlayer -- cgit