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



×
×
  • Create New...

Important Information

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