Jump to content

Recommended Posts

Posted (edited)

Foreword: Sorry if I make any silly mistakes here, I'm not too familiar with how Forge handles Inventories and such...

 

Essentially, I want to make a client-side Forge mod that will be able to extract the contents of any GUI and print it into the logs (for now). I do not wish to use the PlayerContainerEvent because it does not work properly (i.e. just returns a NonNullList<ItemStack> full of air) when getting GUIs from some servers' plugins (perhaps due to Bukkit/Spigot doing some funky stuff backend)

 

Listener Class:

public class Listeners {
	@SubscribeEvent
	public static void onContainerOpen(GuiOpenEvent event) {
		GuiScreen gui = event.getGui();
		if(gui instanceof GuiContainer) {
			GuiContainer gc = (GuiContainer)gui;
			NonNullList<ItemStack> items = gc.inventorySlots.getInventory();
			for(int i = 0; i < items.size(); i++) {
				project.LOGGER.debug("CONTAINER/" + i + ": " + items.get(i).toString());
			}
		}
	}
}

 

Currently, when using this class, even through there are items in the chest being right clicked, this occurs

[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/0: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/1: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/2: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/3: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/4: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/5: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/6: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/7: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/8: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/9: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/10: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/11: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/12: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/13: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/14: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/15: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/16: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/17: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/18: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/19: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/20: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/21: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/22: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/23: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/24: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/25: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/26: 1xblock.minecraft.air
[Client thread/DEBUG] [co.we.au.project/]: CONTAINER/27: 64xblock.minecraft.bedrock

Where indices 0 to 26 are supposed to contain the chest's items (I put sand inside) but it returns air instead? Indices 27 and onwards contains the player's inventory.

 

I think the issue might be that the client is not properly receiving the items from the server, but I'm not sure if that is truly the case, and how to fix it if it is the case...

 

Any assistance would be greatly appreciated. Thanks!

Edited by Wealthyturtle
  • 1 month later...
Posted
On 8/4/2019 at 5:38 PM, diesieben07 said:

I don't think there is an easy way to add a listener. You just have to wait until the inventory is populated. What are you trying to achieve?

Sorry for the late response, but originally I wanted to test if the GuiContainer contained a particular item, e.g. diamond, and if it's true, alert the player. The rest can be settled later, the main issue is the deriving of the container's items.

 

I've tried additional things like Thread.sleep, which just hangs the client and doesn't actually affect the result. I've also tried tried TickEvent.ClientTickEvent, however even when the container is opened for a few seconds, it doesn't register the items at all for some reason...

 

Any advice?

Posted
1 hour ago, FullAuto said:

Don't use anything like Thread.sleep in Minecraft. You will break everything.

 

Maybe you can implement some hotkey, which will print the current GuiContainer to the logs.

Just tried implementing a KeyHandler, it works, but only when the user is not in a GUI Screen, otherwise the keystroke isn't registered

Posted

Check out the net.minecraft.network.play.server.SSetSlotPacket.class

I think, this is the package, that is send by the server to populate the GuiContainer. You could hook to the incoming packages...

 

No idea how to do this exactly. Found some very old thread about it:

 

Posted
15 minutes ago, Wealthyturtle said:

Just tried implementing a KeyHandler, it works, but only when the user is not in a GUI Screen, otherwise the keystroke isn't registered

Subscribe to KeyboardKeyEvent, which is only triggered when keys are pressed when a GUI is opened.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

Thanks for the help, but now I seem to be stuck...

 

From what I can see, the only real solution is to add a custom PacketHandler. The problem is, all the examples I could find were with custom packet sending/recieving (e.g. https://github.com/sinkillerj/ProjectE/blob/c17ff6e1b7151b9ef12396af47a937bb599bf7bf/src/main/java/moze_intel/projecte/network/PacketHandler.java#L23-L52), I couldn't find any examples for vanilla packets, like at all. 

Posted
2 hours ago, DavidM said:

Subscribe to KeyboardKeyEvent, which is only triggered when keys are pressed when a GUI is opened.

KeyInputEvent works, thank you! Successfully extracts inventory content

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.