Jump to content

[Semi-Solved] [1.13.2] Getting items stored in GuiContainer


Wealthyturtle

Recommended Posts

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
Link to comment
Share on other sites

  • 1 month later...
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

    • Ngamenslot adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Ngamenslot: Kombinasi Slot & Bola Kami menyajikan kombinasi terbaik antara permainan slot yang seru dan taruhan bola yang menegangkan. Dengan pilihan permainan yang beragam, setiap pemain dapat menikmati pengalaman bermain yang unik dan menyenangkan. Transaksi Mudah melalui Bank Ekonomi Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank Ekonomi. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan. Terpercaya dan Terjamin Ngamenslot telah terbukti sebagai situs terpercaya dengan ribuan pemain yang puas. Kami mengutamakan keamanan dan kenyamanan para pemain, sehingga Anda dapat bermain dengan tenang dan fokus pada permainan.  
    • Tambang88 adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Sinarmas. Berikut adalah beberapa alasan mengapa Anda harus memilih Tambang88: Raja Slot Gacor Kami merupakan raja slot gacor dengan koleksi permainan terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Sinarmas Kami menyediakan layanan transaksi mudah melalui Bank Sinarmas untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Profesional dan Menguntungkan Tambang88 mengutamakan profesionalitas dalam memberikan layanan kepada para pemainnya. Kami juga menawarkan kesempatan untuk meraih keuntungan yang besar dengan jackpot dan hadiah-hadiah menarik lainnya.    
    • TRIK POLA SL0T GAC0R MAHJONG WAYS 1 DAN 2 HARI INI Sekarang Anda dapat meningkatkan peluang Bermain dengan langsung menggunakan situs resmi dari permainan Mahjong (PG SOFT). Cukup daftar dan siapkan hanya mulai dari 50K hingga 200K, Anda sudah memiliki peluang untuk memenangkan hadiah besar. Jika tidak memiliki dana sebanyak itu, Anda dapat mencoba dengan dana 50K dan memanfaatkan bonus member baru untuk menambah modal. Berikut adalah Situs Resmi Mahjong yang dapat Anda kunjungi: >> SITUS RESMI MAHJONG YANG TERBUKTI << >> SITUS RESMI MAHJONG YANG TERBUKTI << Setelah mendaftar, Anda dapat menggunakan pola yang sering saya gunakan: 🔥 25 Manual TURBO OFF 🔥 15 Manual TURBO ON 🔥 30 Auto TURBO OFF 🔥 10 Manual TURBO ON Pola ini biasanya memberikan hasil yang konsisten.
    • OLO4D adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Bukopin. Berikut adalah beberapa alasan mengapa Anda harus memilih OLO4D: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Bukopin Kami menyediakan layanan transaksi mudah melalui Bank Bukopin untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Pasti Jackpot OLO4D memberikan jaminan bahwa setiap pemain pasti mendapatkan jackpot. Dengan peluang kemenangan yang tinggi, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.  
    • Balon168: Gampang Banjir Scatter Hitam Malam Ini Balon168 telah menjadi sorotan dalam dunia perjudian online, dan ada alasan kuat mengapa pemain semakin tertarik. Salah satu permainan unggulannya, yang dikenal dengan tingkat kemenangan yang tinggi, adalah varian "Gampang Banjir Scatter Hitam Malam Ini". Mari kita selami lebih dalam mengenai fenomena ini. Balon168: Destinasi Utama bagi Pecinta Slot     DAFTAR SEKARANG LINK VIP MAXWIN  
  • Topics

×
×
  • Create New...

Important Information

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