mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-24 18:24:21 +00:00
Compare commits
1
Commits
master
...
alex/fix-leak
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8238d19597 |
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
package com.gtnh.findit.fx;
|
package com.gtnh.findit.fx;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
@@ -22,13 +23,18 @@ public class SlotHighlighter implements IContainerDrawHandler {
|
|||||||
"textures/gui/slot_highlight.png");
|
"textures/gui/slot_highlight.png");
|
||||||
|
|
||||||
private GuiContainer gui = null;
|
private GuiContainer gui = null;
|
||||||
private HashSet<Slot> slots = new HashSet<>();
|
private Set<Slot> slots = Collections.emptySet();
|
||||||
private float red = 0;
|
private float red = 0;
|
||||||
private float green = 0;
|
private float green = 0;
|
||||||
private float blue = 0;
|
private float blue = 0;
|
||||||
private float alpha = 0;
|
private float alpha = 0;
|
||||||
|
|
||||||
public void highlightSlots(GuiContainer gui, HashSet<Slot> slots, int color) {
|
public void clear() {
|
||||||
|
this.gui = null;
|
||||||
|
this.slots = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void highlightSlots(GuiContainer gui, Set<Slot> slots, int color) {
|
||||||
|
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
this.slots = slots;
|
this.slots = slots;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleResponse(EntityClientPlayerMP player, ItemFoundResponse response) {
|
public void handleResponse(EntityClientPlayerMP player, ItemFoundResponse response) {
|
||||||
this.slotHighlighter.highlightSlots(null, new HashSet<>(), 0xFFFF8726);
|
this.slotHighlighter.clear();
|
||||||
this.foundItem = response.getFoundStack() != null ? new FindItemRequest(response.getFoundStack()) : null;
|
this.foundItem = response.getFoundStack() != null ? new FindItemRequest(response.getFoundStack()) : null;
|
||||||
this.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000L;
|
this.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000L;
|
||||||
|
|
||||||
@@ -92,40 +92,33 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onClientPostTick(TickEvent.ClientTickEvent event) {
|
public void onClientPostTick(TickEvent.ClientTickEvent event) {
|
||||||
|
|
||||||
if (foundItem == null || event.phase != TickEvent.Phase.END) {
|
if (event.phase != TickEvent.Phase.END) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `WorldClient` is only available on the client-side, thus effectively checking if the game is running on
|
// If the expiration time has passed, we reset the found item. This is done to prevent the item from being
|
||||||
// the client. We are only interested in highlighting slots when the player is in a GUI; the operation is
|
// highlighted indefinitely.
|
||||||
// bound client-side.
|
if (foundItem != null && System.currentTimeMillis() > expirationTime) {
|
||||||
if (Minecraft.getMinecraft().theWorld == null) {
|
foundItem = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are only interested in GUIs that contain some kind of inventory.
|
// The highlighter must not keep the last GUI and its slots once highlighting stops, otherwise it retains
|
||||||
final GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
// the player and the whole WorldClient after leaving the world.
|
||||||
if (!(screen instanceof GuiContainer)) {
|
final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
final GuiScreen screen = mc.currentScreen;
|
||||||
|
if (foundItem == null || mc.theWorld == null || !(screen instanceof GuiContainer)) {
|
||||||
|
slotHighlighter.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final GuiContainer gui = (GuiContainer) screen;
|
final GuiContainer gui = (GuiContainer) screen;
|
||||||
final HashSet<Slot> highlightedSlots = new HashSet<>();
|
final HashSet<Slot> highlightedSlots = new HashSet<>();
|
||||||
|
|
||||||
// If the expiration time has passed, we reset the found item. This is done to prevent the item from being
|
|
||||||
// highlighted indefinitely.
|
|
||||||
if (System.currentTimeMillis() > expirationTime) {
|
|
||||||
foundItem = null;
|
|
||||||
}
|
|
||||||
if (foundItem == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We continue to iterate over each slot of the given GUI's inventory and checking if the slot contains the
|
// We continue to iterate over each slot of the given GUI's inventory and checking if the slot contains the
|
||||||
// item that we are looking for.
|
// item that we are looking for.
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Slot> slots = gui.inventorySlots.inventorySlots;
|
List<Slot> slots = gui.inventorySlots.inventorySlots;
|
||||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
EntityPlayer player = mc.thePlayer;
|
||||||
|
|
||||||
for (Slot slot : slots) {
|
for (Slot slot : slots) {
|
||||||
if (!(slot.inventory instanceof InventoryPlayer)
|
if (!(slot.inventory instanceof InventoryPlayer)
|
||||||
|
|||||||
Reference in new issue
Block a user