Compare commits

..
7 Commits
9 changed files with 147 additions and 34 deletions

No files matched your search

+2 -2
View File
@@ -3,9 +3,9 @@ name: Build and test
on:
pull_request:
branches: [ master, main ]
branches: [ master, main, release/** ]
push:
branches: [ master, main ]
branches: [ master, main, release/** ]
jobs:
build-and-test:
+1
View File
@@ -14,6 +14,7 @@ dependencies {
compileOnly("curse.maven:thaumcraft-nei-plugin-225095:2241913")
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev")
compileOnly("com.github.GTNewHorizons:AspectRecipeIndex:1.1.3:dev")
compileOnly("net.xonich.mc:NoHotbarNeeded:0.0.3:dev")
// For testing in dev environment.
// runtimeOnlyNonPublishable("com.github.GTNewHorizons:StorageDrawers:2.2.28-GTNH")
@@ -10,6 +10,8 @@ import com.gtnh.findit.handler.AdventureBackpackProvider;
import com.gtnh.findit.handler.BackpackProvider;
import com.gtnh.findit.handler.DraconicEvolutionProvider;
import com.gtnh.findit.handler.ForestryStackFilterProvider;
import com.gtnh.findit.handler.GregTechCoverChestProvider;
import com.gtnh.findit.handler.GregTechCoverProvider;
import com.gtnh.findit.handler.MinecraftProvider;
import com.gtnh.findit.handler.ProjectRedExplorationProvider;
import com.gtnh.findit.handler.ThaumcraftProvider;
@@ -95,6 +97,11 @@ public class FindIt {
this.pluginsList.add(new ThaumcraftProvider());
}
if (this.isGregTechLoaded) {
this.pluginsList.add(new GregTechCoverProvider());
this.pluginsList.add(new GregTechCoverChestProvider());
}
this.pluginsList.add(new MinecraftProvider());
}
@@ -1,6 +1,7 @@
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.gui.inventory.GuiContainer;
@@ -22,13 +23,18 @@ public class SlotHighlighter implements IContainerDrawHandler {
"textures/gui/slot_highlight.png");
private GuiContainer gui = null;
private HashSet<Slot> slots = new HashSet<>();
private Set<Slot> slots = Collections.emptySet();
private float red = 0;
private float green = 0;
private float blue = 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.slots = slots;
@@ -0,0 +1,60 @@
package com.gtnh.findit.handler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.forge.IItemHandler;
import com.gtnh.findit.IStackFilter;
import com.gtnh.findit.IStackFilter.IStackFilterProvider;
import com.gtnh.findit.service.itemfinder.FindItemRequest;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.common.covers.Cover;
import gregtech.common.covers.CoverChest;
public class GregTechCoverChestProvider implements IStackFilterProvider {
@Override
public IStackFilter getFilter(EntityPlayer player, TileEntity tileEntity) {
if (!(tileEntity instanceof ICoverable coverable)) {
return null;
}
return request -> {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (!coverable.hasCoverAtSide(side)) {
continue;
}
if (coverChestMatches(player, request, coverable.getCoverAtSide(side))) {
return true;
}
}
return false;
};
}
@Override
public IStackFilter getFilter(EntityPlayer player, ItemStack stack) {
return null;
}
private static boolean coverChestMatches(EntityPlayer player, FindItemRequest request, Cover cover) {
if (!(cover instanceof CoverChest coverChest)) {
return false;
}
IItemHandler items = coverChest.getItems();
for (int slot = 0; slot < items.getSlots(); slot++) {
ItemStack slotItem = items.getStackInSlot(slot);
if (slotItem != null && request.isStackSatisfies(player, slotItem)) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,48 @@
package com.gtnh.findit.handler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnh.findit.IStackFilter;
import com.gtnh.findit.IStackFilter.IStackFilterProvider;
import gregtech.api.covers.CoverRegistry;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.util.GTUtility;
public class GregTechCoverProvider implements IStackFilterProvider {
@Override
public IStackFilter getFilter(EntityPlayer player, TileEntity tileEntity) {
if (!(tileEntity instanceof ICoverable coverable)) {
return null;
}
return request -> {
ItemStack stackToFind = request.getStackToFind();
if (stackToFind == null || !CoverRegistry.isCover(stackToFind)) {
return false;
}
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (!coverable.hasCoverAtSide(side)) {
continue;
}
ItemStack coverStack = coverable.getCoverItemAtSide(side);
if (GTUtility.areStacksEqual(stackToFind, coverStack, true)) {
return true;
}
}
return false;
};
}
@Override
public IStackFilter getFilter(EntityPlayer player, ItemStack stack) {
return null;
}
}
@@ -14,7 +14,6 @@ import com.gtnh.findit.FindItNetwork;
import com.gtnh.findit.util.WorldUtils;
import cpw.mods.fml.relauncher.Side;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
public class BlockFindService {
@@ -37,12 +36,11 @@ public class BlockFindService {
continue;
}
int tileMeta;
if (FindIt.isGregTechLoaded() && tileEntity instanceof IGregTechTileEntity gregTech) {
tileMeta = gregTech.getMetaTileID();
} else {
tileMeta = tileEntity.getBlockMetadata();
}
int tileMeta = tileBlock.getDamageValue(
tileEntity.getWorldObj(),
tileEntity.xCoord,
tileEntity.yCoord,
tileEntity.zCoord);
if (request.getMetaToFind() == tileMeta) {
positions.add(new ChunkPosition(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
@@ -58,7 +58,7 @@ public class ClientItemFindService extends ItemFindService {
}
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.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000L;
@@ -92,40 +92,33 @@ public class ClientItemFindService extends ItemFindService {
@SubscribeEvent
public void onClientPostTick(TickEvent.ClientTickEvent event) {
if (foundItem == null || event.phase != TickEvent.Phase.END) {
if (event.phase != TickEvent.Phase.END) {
return;
}
// `WorldClient` is only available on the client-side, thus effectively checking if the game is running on
// the client. We are only interested in highlighting slots when the player is in a GUI; the operation is
// bound client-side.
if (Minecraft.getMinecraft().theWorld == null) {
return;
// If the expiration time has passed, we reset the found item. This is done to prevent the item from being
// highlighted indefinitely.
if (foundItem != null && System.currentTimeMillis() > expirationTime) {
foundItem = null;
}
// We are only interested in GUIs that contain some kind of inventory.
final GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if (!(screen instanceof GuiContainer)) {
// The highlighter must not keep the last GUI and its slots once highlighting stops, otherwise it retains
// the player and the whole WorldClient after leaving the world.
final Minecraft mc = Minecraft.getMinecraft();
final GuiScreen screen = mc.currentScreen;
if (foundItem == null || mc.theWorld == null || !(screen instanceof GuiContainer)) {
slotHighlighter.clear();
return;
}
final GuiContainer gui = (GuiContainer) screen;
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
// item that we are looking for.
@SuppressWarnings("unchecked")
List<Slot> slots = gui.inventorySlots.inventorySlots;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
EntityPlayer player = mc.thePlayer;
for (Slot slot : slots) {
if (!(slot.inventory instanceof InventoryPlayer)
@@ -16,7 +16,7 @@ public class ProtoUtils {
buf.writeInt(positions.size());
for (ChunkPosition pos : positions) {
buf.writeInt(pos.chunkPosX);
buf.writeByte(pos.chunkPosY);
buf.writeInt(pos.chunkPosY);
buf.writeInt(pos.chunkPosZ);
}
}
@@ -35,7 +35,7 @@ public class ProtoUtils {
List<ChunkPosition> positions = new ArrayList<>();
while (amount > 0) {
final int x = buf.readInt();
final int y = buf.readUnsignedByte();
final int y = buf.readInt();
final int z = buf.readInt();
positions.add(new ChunkPosition(x, y, z));
--amount;