Jump to content

[1.7.10] Problems with ItemExpireEvent


pickaxe_engineer

Recommended Posts

Hi guys

 

I am slightly new to modding in minecraft and may I overlook an important step. But I try to prevent an EntityItem from despawn after the usual five minutes while being collided with a special block (a conveyor belt).

 

The first attempt did not work, I thought somehting like the following would work:

@Override public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity){
if(entity instanceof EntityItem){
//some code to move the item
((EntityItem)entity).ticksExisted = 0;
}
}

 

So ticksExisted is not used to calculate when it despawns?!

 

The second, more promising, attempt was to use the lovely Forge Events:

 

I wrote a little EventHandler:

@Subscribe
public void handleItemExpire(ItemExpireEvent event){
	World world = event.entityItem.worldObj;
	double xPos = event.entityItem.lastTickPosX;
	double yPos = event.entityItem.lastTickPosY;
	double zPos = event.entityItem.lastTickPosZ;

	System.out.println("Item despawn event happend");

	if(world.getBlock((int)xPos, (int)yPos, (int)zPos) != null && world.getBlock((int)xPos, (int)yPos, (int)zPos) instanceof ConveyorBelt){
		event.extraLife = 20 * 60 * 5;//adding another 5min
		System.out.println("prevented item despawn on conveyor belt");
	}
}

 

And registered this event handling class in my main mod file, in the init method:

@EventHandler
public void init(FMLInitializationEvent initEvent) {
	//Event handerls:
	MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
}

 

But as well as the first attempt, the second didn't work and I am a little confused.

 

Maybe some of you could help me? Thanks in advance!

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

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



×
×
  • Create New...

Important Information

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