Jump to content

Recommended Posts

Posted

Hi everyone,

 

this may be a stupid question but how do you set an itemstack to dead? I havent been able to figure out how to remove my item. I get the item using the item pickup event then I do stuff but I then need to remove the item from the game to clean up. I cant figure it out

Posted

ItemStacks are not entities.  Entities can be dead, ItemStacks are nullified.

 

Dropped items are EntityItem entities that contain an ItemStack.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

In my event the itemstack persists if i do this, dont know why

@SubscribeEvent
public void OnItemPickup(EntityItemPickupEvent e){

	if(e.item.getEntityItem().getItem().equals(CommonProxy.myItem)){
		System.out.println("Event fired");
                       player = e.entityPlayer;
                       ItemStack itemStack = e.item.getEntityItem();
                       if (!player.worldObj.isRemote){
			//my methods
			itemStack = null;
			}
	}

}

Posted

EntityItem is the thing you pick up, it CONTAINS ItemStack which holds some Item.

 

Now, I understand you want to remove item from game when somebody want to pick it up?

So item disappears, but is not picked?

Or maybe you want to not allow player to pick up item?

What exacly you want?

1.7.10 is no longer supported by forge, you are on your own.

Posted

I want the player to pick up my item, this item applies custom data to players IEEP but I want the item to cease to exist after the data has been applied

Posted

I want the player to pick up my item, this item applies custom data to players IEEP but I want the item to cease to exist after the data has been applied

 

Then you need to set the event to canceled and set the EntityItem to dead.

 

OR

 

Remove the item from the player's inventory.  Nulling the local variable doesn't do anything, you need to null the inventory's reference to it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

So basically coins (money).

@SubscribeEvent
public void notifyPickup(ItemPickupEvent event) {
  ItemStack stack = event.pickedUp.getEntityItem();
  if(stack != null) {
   if(stack.getItem() == ITEM) {
    event.player.inventory.consumeInventoryItem(ITEM);
   }
  }
}

You could use this. Note that consume method only eats one item, you will have to make your ItemStack maxSize=1.

Or, use 1st Draco's suggestion.

 

 

PROBLEM

I've got a question [1.8]. Some time ago I've been coding something that checks ItemStack when it's being picked up (like above).

It might have been something in my code, BUT I noticed that My ItemStack couldn't store it's size. Better explanation:

- There is an ItemStack inside EntityItem which stackSize should be e.g 30, yet when I did event.pickedUp.getEntityItem(); the stackSize wasn't 30 (it was, i think default value or simply 1). Could someone explain this?

 

EDIT

I've made code right away:

@SubscribeEvent
public void notifyPickup(ItemPickupEvent event)
{
	ItemStack stack = event.pickedUp.getEntityItem();
	if(stack != null)
	{
		if(stack.getItem() == Items.stick)
		{
			System.out.println(stack);
			System.out.println(stack.stackSize);
		}
	}
}

ItemStack can't hold any NBT (with stackSize=1), can't have stackSize (always 0xitem) and has totally nothing.

0xitem.stick@0   // I picked up 1 stick
0
0xitem.stick@0   // picked up few stick that auto-stacked into one entity in world
0
0xitem.stick@0   // threw on ground full 64 stack and picked it up
0

 

0 - thos are stackSizes

 

How to get data from picked up stack? (there are some DataWatchers thing I can't bypass with my brain for now).

1.7.10 is no longer supported by forge, you are on your own.

Posted

how are you saving your NBT to your itemstack? My item has NBT data associated with it I use this factory method to grab my custom NBT data from my entity and save it to the itemstack

 

public classItemStackFactory {
public static ItemStack generateItemStack(EntityCustom caughtEntity, ItemClass itemType, String playerName){

	ItemStack item = new ItemStack(itemType);
	if(itemstackTagCompound == null){
		item.stackTagCompound = new NBTTagCompound();
	}
	NBTTagCompound entityCustomNBTCompound = new NBTTagCompound();
	caughtEntity.writeToNBT(entityCustomNBTCompound);
	 item.stackTagCompound.setTag("caughtEntity", entityCustomNBTCompound);
	 item.stackTagCompound.setString("playerName", playerName);
	return  item;
}
}

Posted

I get my data from the Itemstack in the following way


public void tryToAddMobToParty(NBTTagCompound caughtEntityNBT){

	PlayerParty ppp = PlayerParty.get(player);

	if(ppp.hasFreeSlot() == true){
	this.displayChatMessage(EnumChatFormatting.GREEN + "Adding Mob To Party Slot: " + (ppp.getNextFreeSlot() + 1));
	ppp.setPartyMember(ppp.getNextFreeSlot(), caughtEntityNBT);	
	ppp.updatePlayerPartyServerToClient();

	}else{
		this.displayChatMessage(EnumChatFormatting.RED + "Your Party Is Currently Full!!");

	}
}

 

then inside the pickup event

if(e.item.getEntityItem().getItem().equals(CommonProxy.myItem)){
		player = e.entityPlayer;
		ItemStack itemStack = e.item.getEntityItem();
		PlayerParty ppp = PlayerParty.get(player);

		if(itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey("caughtEntity")){
			NBTTagCompound caughtEntityNBT = itemStack.stackTagCompound.getCompoundTag("caughtEntity");
			String playerName = itemStack.stackTagCompound.getString("playerName");
			String mobName = caughtEntityNBT.getString("mobName");
			if (!player.worldObj.isRemote){
			tryToAddMobToParty(caughtEntityNBT);
			}
		}
	}

Posted

You don't. Can't. You get it from the event object, like your already doing.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I guess that is my issue Im not sure how to set it to dead, I have the itemstack and its NBT data and I have access to the player and his inventory but that is where I am stuck. I dont actually know how to get the exact item that I picked up and set it to dead (kinda my original question but i guess i worded it poorly up top).

 

the event has three parameters e.Entity, e.EntityLiving and e.EntityPlayer is the entityItem the e.Entity?

Posted

Jesus.

 

Capture.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

that doesnt exist inside EntityItemPickupEvent

... Come on man, learn some Java already. EntityItemPickupEvent has an even more obviously-named field for the EntityItem you need. Or you could switch events.

 

Either way, your problem is NOT related to Minecraft per se, it's your lack of fundamental Java skills.

Posted

Im sorry but what skills might those be, the field is not obvious to me and i apologize for that, i think I have already shown that I know enough java to mod quite successfully. The stuff I am doing is complicated and even the best miss things... which field is the obvious one?

Posted

Really?

 

really.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

this doesnt work... not sure what im missing maybe im not good enough at java to know but if youd like to help and know what the issue is then please do

@SubscribeEvent
public void OnItemPickup(ItemPickupEvent e){

NBTTagCompound caughtEntityNBT = itemStack.stackTagCompound.getCompoundTag("caughtEntity");
			String playerName = itemStack.stackTagCompound.getString("playerName");
			String mobName = caughtEntityNBT.getString("mobName");
			if (!player.worldObj.isRemote){
			tryToAddMobToParty(caughtEntityNBT);
                                e.isCanceled();
			itemStack = null;
			e.pickedUp.setDead();
			}
			}

Posted
public void OnItemPickup(ItemPickupEvent e){

NBTTagCompound caughtEntityNBT = itemStack.stackTagCompound.getCompoundTag("caughtEntity");

 

And what magical itemstack is this?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

that is the itemstack that I generated when my entity impacted my target entity. it exists it has NBT data, the data is added to the player but i cannot set it to dead

Posted

Im sorry but what skills might those be, the field is not obvious to me and i apologize for that, i think I have already shown that I know enough java to mod quite successfully. The stuff I am doing is complicated and even the best miss things... which field is the obvious one?

Skills like seeing what fields a class has - super super basic. Skills like not using non-existent or unrelated objects (Draco already pointed it out - where'd that itemstack come from? why is it stored in some random place? how can you possibly expect it to relate to the event?).

 

Sure you may have made some interesting mods, but that doesn't mean you have sufficient Java skills, especially considering that you think that your current project is 'complicated' - I don't wish to offend you, but it is very simple, and your lack of skill is what is making it difficult for you.

 

Basic Java skills. Learn them. You may think you already know them, but 'basic Java' is way more than knowing the difference between int and String.

Posted

However this does work

@SubscribeEvent
public void OnItemPickup(EntityItemPickupEvent e){
NBTTagCompound caughtEntityNBT = itemStack.stackTagCompound.getCompoundTag("caughtEntity");
			String playerName = itemStack.stackTagCompound.getString("playerName");
			String mobName = caughtEntityNBT.getString("mobName");
			if (!player.worldObj.isRemote){
			tryToAddMobToParty(caughtEntityNBT);
                                e.item.setDead();
			itemStack = null;
			e.setCanceled(true);
			}
			}

 

now why would that be? all other lines of code above this are exactly the same (i omitted some cause this is pretty complicated stuff and there is a lot of lines)... the only difference between this and the other post is I subscribe EntityItemPickupEvent rather than ItemPickupEvent (both are registered to their appropriate buses n both fire) and I do

 

e.item.setDead();

itemStack = null;

e.setCanceled(true);

 

rather than

e.isCanceled();

itemStack = null;

e.pickedUp.setDead();

Posted

I know far more than what the difference is from a basic int and string... but if youre here to harass and insult me then please refrain from commenting. I may not be as good or experienced as you but I have somehow managed to recreate skyrims lockpicking, I have several highly advanced and highly optimized rendering systems, I have a very complex persistent data saving structure where i transfer an entity from log on to player to living entity to tile entity to living entity to item to another entity to holder entity and conditionally create an itemstack based on a complex animation and calculations... I dont really want to go on. There is no secret I am learning JAVA but so are you, hence why you are on these forums. You have more experience and I very much appreciate your advice and help, especially given how helpful you have been for some of the issues I have posted here. I have already complained about people harassing the less experienced on this forum. I have already asked respectfully that people like that refrain from insulting people, and instead if they notice an issue they should direct them to the appropriate source of information. Anyways I simply didnt notice that field you mentioned and now have my class working. So thanks alot, I really do appreciate it.

 

But keep in mind this forums title, "Modder Support" discouraging people from modding just because they have made a mistake (and mistakes happen to everyone) doesnt live up to this forums name.

 

Oh and FYI if I rearrange my ItemPickupEvent to the following - The item persists not sure why it is probably something I am doing up top but both classes have the exact same code above this so I dont know what the issue is but it doesnt matter. I found my solution.

 

@SubscribeEvent
public void OnItemPickup(ItemPickupEvent e){

NBTTagCompound caughtEntityNBT = itemStack.stackTagCompound.getCompoundTag("caughtEntity");
			String playerName = itemStack.stackTagCompound.getString("playerName");
			String mobName = caughtEntityNBT.getString("mobName");
			if (!player.worldObj.isRemote){
			tryToAddMobToParty(caughtEntityNBT);
                               e.pickedUp.setDead();
                                itemStack = null;
                                e.isCanceled();


			}
			}

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.