Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.

Any specific slot? Players hand? And input would be using a KeyHandler and possibly the KeyInputEvent

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.

  • Author

I've got the input figured out, Mr. Crayfish made an API, all I need to know is if the item is in the players inventory, and then if it is to remove it.

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

Do you have access to a EntityPlayer variable? If so there is a thing called inventory in there.

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.

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.

  • Author

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.

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.

  • Author

Ugh.. Okay. I'll wait and see if Mr. Crayfish implements a way to get the EntityPlayer from the player who is using the PC.

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

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.