Jump to content

[1.11.2] Custom EntityItem dropped in a random pattern


Raddari

Recommended Posts

Hello,

I have created an Item named "Potassium" which extends the Item class.

I have overridden the methods Item#hasCustomEntity and Item#createEntity in order for it to drop a custom EntityItem. In full, the class appears as below:

Spoiler

public class ItemPotassium extends Item{
	
	public ItemPotassium(){
		setCreativeTab(RaddariTabs.tabRaddariElements);
		
	}
	
	@Override
	public boolean hasCustomEntity(ItemStack stack){
		return true;
	}
	
	@Override
	public Entity createEntity(World world, Entity location, ItemStack itemStack){
		return new EntityItemPotassium(world, location.posX, location.posY, location.posZ, new ItemStack(this));
		
	}
	
}

 

 

This EntityItem will explode and delete itself when it touches water, and the code for the EntityItemPotassium class appears as below:

Spoiler

public class EntityItemPotassium extends EntityItem{
	
	private static int printCount;
	
	public EntityItemPotassium(World worldIn, double x, double y, double z, ItemStack stack){
		super(worldIn, x, y, z, stack);
		setPickupDelay(30);
		
		System.out.printf("(%s, %s, %s) %s", this.motionX, this.motionY, this.motionZ, ++printCount);
		System.out.println();
	}
	
	@Override
	public void onUpdate(){
		super.onUpdate();
		if(this.world.getBlockState(new BlockPos(this)).getMaterial() == Material.WATER){
			world.createExplosion(null, this.posX, this.posY, this.posZ, 0.1F, false);
			this.setDead();
		}
		
	}
	

}

 

 

The item works as intended, and when thrown into water, it explodes and removes itself as required. However, when the item is dropped by pressing 'Q' or dragged and dropped outside of the inventory, it drops randomly around the player as if it were dropped from a block, rather than dropped by the player. I have added lines which print the motion in which the item is dropped, and the results from 20 drops are in the spoiler below:

Spoiler

(-0.037959955632686615, 0.20000000298023224, -0.09124404937028885) 1
(0.04281458258628845, 0.20000000298023224, -0.025239011272788048) 2
(-0.0441775806248188, 0.20000000298023224, -0.08435092866420746) 3
(0.06447163224220276, 0.20000000298023224, -0.07456856220960617) 4
(0.04112672433257103, 0.20000000298023224, -0.012792765162885189) 5
(0.06833070516586304, 0.20000000298023224, 0.014344688504934311) 6
(-0.05937396362423897, 0.20000000298023224, 0.07921340316534042) 7
(-0.0014830060536041856, 0.20000000298023224, 0.032799966633319855) 8
(0.03759485483169556, 0.20000000298023224, 0.016611535102128983) 9
(0.013957034796476364, 0.20000000298023224, 0.0754539743065834) 10
(-0.05888323113322258, 0.20000000298023224, 0.051614634692668915) 11
(0.06293215602636337, 0.20000000298023224, -0.009981697425246239) 12
(0.06436074525117874, 0.20000000298023224, -0.01514304056763649) 13
(0.009490793570876122, 0.20000000298023224, 0.01683310978114605) 14
(0.007202099077403545, 0.20000000298023224, -0.06770595163106918) 15
(-0.07425859570503235, 0.20000000298023224, -0.05302897095680237) 16
(-0.05347992107272148, 0.20000000298023224, 0.009333755820989609) 17
(0.017328904941678047, 0.20000000298023224, 0.0908999890089035) 18
(-0.09394127130508423, 0.20000000298023224, -0.026297228410840034) 19
(-0.021045124158263206, 0.20000000298023224, -0.05310024693608284) 20

 

 

It appears that the item is always dropped as if it were dropped from the block, but I am unable to find reference code that differentiates between a player throwing an item and a block dropping an item within the EntityItem class. I feel like I'm missing something very obvious here, so any help would be gladly appreciated.

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.