Jump to content

[Paused] [1.8.9] How to detect if item is in inventory, then remove it?


Recommended Posts

Posted

Title really says all, I'm developing an addon for MrCray's Device Mod, and I want it to give the player 'money' when they press a button. By doing that, I need to figure out how to detected if an item is in the players inventory.

I am on my journey of making a remake of matmos, as explained here.

Posted

I have access to the EntityPlayerSP variable. What for inventory would I use to search for an item?

First EntityPlayerSP is not a variable you can use, you will need to send packets. This is a link to Diesieben07's tutorial on Packets.

http://www.minecraftforge.net/forum/index.php?topic=20135.0

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

is there a reason why I'd have to do this? I am very easily able to get the itemstack on the inventory using this...

 

Minecraft.getMinecraft().thePlayer.inventory.mainInventory

 

That is an item stack list

 

EDIT:

When I do print System.out.println(player.inventory.mainInventory[5]); to console, it outputs ...

 

1xtile.lightgem@0

 

When I print out ItemStack testItem = new ItemStack(Blocks.glowstone);, it outputs ...

 

1xtile.lightgem@0

 

Yet the if-statment I have given it doesn't work?

 

	final EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;

	ItemStack testItem = new ItemStack(Blocks.glowstone);

	System.out.println(player.inventory.mainInventory[5]);
	System.out.println(testItem);

	if (player.inventory.mainInventory[5] == testItem) {
		System.out.println("HE HAS IT");
	} else {
		System.out.println("It ain't glowstone");
	}

 

Full Output:

[19:25:30] [Client thread/INFO] [sTDOUT]: [com.fire.cdmbloxread.apps.ApplicationBloxRead:init:36]: 1xtile.lightgem@0
[19:25:30] [Client thread/INFO] [sTDOUT]: [com.fire.cdmbloxread.apps.ApplicationBloxRead:init:37]: 1xtile.lightgem@0
[19:25:30] [Client thread/INFO] [sTDOUT]: [com.fire.cdmbloxread.apps.ApplicationBloxRead:init:42]: It ain't glowstone

I am on my journey of making a remake of matmos, as explained here.

Posted

is there a reason why I'd have to do this? I am very easily able to get the itemstack on the inventory using this...

 

Minecraft.getMinecraft().thePlayer.inventory.mainInventory

That is client side you can grab what there is client side and modify it, but since all data is saved and should be modified on the server. It will just be overriden by the server. Thus a packet is required.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Also check the worldsave / serverconfig folder If there is no such file, make a test without this mod  
    • Hi, I've been having trouble trying to use forge as it shows a black screen when I open the game, but I can still interact with it and hear the music.  I've done all of the step by steps and most common fixes like updating drivers, keeping up to date with Java, deleting and reinstalling minecraft, restarting my computer MANY times, even smaller things like splash.properties (I didn't have that file so I added it and set it to false thinking it would do something, definitely not) and making sure to prioritize my rtx 3070 in the settings but with no luck. Minecraft works as intended when I uninstall forge and I also don't have any mods currently, it just gives me this issue when I install forge. I also increased the ram usage, made sure my hardware isn't full or anything, and even changed the resolution in hopes it would fix things. I checked my antivirus and firewall but that isn't the issue either. Trust me, I've done everything I can think of. For some reason the black screen does flicker a little into the main menu, but obviously unplayable. I couldn't even make my way to the settings with how little it flickered. I'm not sure if it flickered randomly or if it was because I was messing around moving and clicking a bunch, I didn't really test it that much.  
    • I've had a really weird issue recently,  I wanted to add the Depper and Darker mod on my dedicated server (MC 1.21 with Fabric 0.16.9, hosted on nitroserv.com) but whenever I do add the mod the sever stops doing anything after listing the mods, and I get no crash or error or anything, just a stuck server. Here's a normal log of the server booting up: https://pastebin.com/JipFF2Eh and here's the log of the server doing the weird thing: https://pastebin.com/W4JBh3eX I just don't understand it. I've tried removing other mods (somewhat randomly) but deeper and darker still breaks my server whenever I add it. NitroServ support staff is about as confused as I am and I've had no response from the Deeper and Darker support staff... Now I know this is the Forge support not the Fabric support but I'm just trying to know if anyone has any kind of idea to fix this (aside from not using the mod obviously) Also I still have a bunch of errors and warnings whenever the server does start properly, are there any of them I should be worried about?
  • Topics

×
×
  • Create New...

Important Information

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