Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve invsee gui & add support for some modded inventories #185

Merged
merged 10 commits into from
Feb 8, 2025
10 changes: 8 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.6.3:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.25-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.9.2:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.25-GTNH:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:EnderIO:2.9.2:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:Navigator:1.0.15:dev")
compileOnly('org.jetbrains:annotations:25.0.0')
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.0.3:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Battlegear2:1.4.2:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Galacticraft:3.3.4-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:TinkersConstruct:1.13.8-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:AdventureBackpack2:1.3.2-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.5.0-GTNH:dev') {transitive = false}

runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.2:dev")
}
45 changes: 25 additions & 20 deletions src/main/java/serverutils/command/CmdInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;

import org.apache.commons.lang3.StringUtils;

import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;

import serverutils.ServerUtilitiesConfig;
import serverutils.invsee.InvseeContainer;
import serverutils.invsee.inventories.IModdedInventory;
import serverutils.invsee.inventories.InvSeeInventories;
import serverutils.lib.command.CmdBase;
import serverutils.lib.command.CmdTreeBase;
import serverutils.lib.command.CmdTreeHelp;
import serverutils.lib.data.ForgePlayer;
import serverutils.lib.data.Universe;
import serverutils.net.MessageInvseeContainer;

public class CmdInv extends CmdTreeBase {

Expand All @@ -35,7 +40,8 @@ public CmdView() {
@Override
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
if (args.length == 1) {
return Universe.get().getPlayers().stream().map(ForgePlayer::getName).collect(Collectors.toList());
return Universe.get().getPlayers().stream().map(ForgePlayer::getName)
.filter(e -> StringUtils.startsWithIgnoreCase(e, args[0])).collect(Collectors.toList());
}
return super.addTabCompletionOptions(sender, args);
}
Expand All @@ -55,22 +61,21 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
throw new CommandException("commands.generic.player.notFound", args[0]);
}

if (other.isOnline()) {
self.displayGUIChest(new InvSeeInventory(other.getPlayer().inventory, other.getPlayer()));
} else {
NBTTagCompound tag = other.getPlayerNBT();
InventoryPlayer playerInv = new InventoryPlayer(null);
playerInv.readFromNBT(tag.getTagList("Inventory", Constants.NBT.TAG_COMPOUND));
InvSeeInventory invSee = new InvSeeInventory(playerInv, null);
invSee.setSaveCallback(inv -> {
InventoryPlayer invPlayer = inv.getPlayerInv();
NBTTagList invTag = new NBTTagList();
invPlayer.writeToNBT(invTag);
tag.setTag("Inventory", invTag);
other.setPlayerNBT(tag);
});
self.displayGUIChest(invSee);
Map<InvSeeInventories, IInventory> inventories = new LinkedHashMap<>();
for (InvSeeInventories inv : InvSeeInventories.getActiveInventories()) {
IModdedInventory modInv = inv.getInventory();
IInventory inventory = other.isOnline() ? modInv.loadOnlineInventory(other.getPlayer())
: modInv.loadOfflineInventory(other);
if (inventory != null) {
inventories.put(inv, inventory);
}
}

self.getNextWindowId();
new MessageInvseeContainer(other, inventories, self.currentWindowId).sendTo(self);
self.openContainer = new InvseeContainer(inventories, self, other);
self.openContainer.windowId = self.currentWindowId;
self.openContainer.addCraftingToCrafters(self);
}
}

Expand Down
163 changes: 0 additions & 163 deletions src/main/java/serverutils/command/InvSeeInventory.java

This file was deleted.

Loading