Jump to content

Solved [1.12.2] Custom EntityItem


Whompy

Recommended Posts

How am I supposed to render my entity Items. I have tried extending EntityItem and adding my own properties to it. How would I apply this to an item which I am spawning as of now I can't use itemfloating as an ItemEntity

 

public class ItemFloating extends EntityItem{

    public int lifespan = -1;
	private int health;

	public ItemFloating(World worldIn, double x, double y, double z) {
		 super(worldIn);
	        this.health = 5;
	        this.hoverStart = (float)(Math.random() * Math.PI * 2.0D);
	        this.setSize(0.25F, 0.25F);
	        this.setPosition(x, y, z);
	        this.rotationYaw = (float)(Math.random() * 360.0D);
	        this.motionX = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));
	        this.motionY = 0.20000000298023224D;
	        this.motionZ = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));
	}
	
	
	public ItemFloating(World worldIn, double x, double y, double z, ItemStack stack) {
		this(worldIn, x, y, z);
    	this.setItem(stack);
    	this.lifespan = (stack.getItem() == null ? -1 : stack.getItem().getEntityLifespan(stack, worldIn));
	}
	
	@Override
	public void onUpdate() {
		cannotPickup();
		super.onUpdate();
	}
}

	

I have not written much else besides my other item block and mob code in case you are wondering.

 

 

Edited by Whompy
Link to comment
Share on other sites

Sorry I don't think I was clear, I am trying to render my own untouchable item which will be spawned on top of a block . If I were to say override a block of glass's createEntity/hasCustomEntity functions, wouldn't it also make the entity itself when (obtained through normal means) not be picked up? how would I differentiate between the two possibilities, a boolean?

 

Also, how would I get this to apply to a non modded item's itemEntity. would I need to create another class for modded and nonmodded items?

 

If you know of any example tutorials talking about this or example code, I would appreciate it

Edited by Whompy
Link to comment
Share on other sites

public class EntitySponge extends EntityVex{


	
	private Item purposeItem = Items.PUMPKIN_PIE;	
	private net.minecraft.block.Block purpose = Blocks.GLASS;
	private Object time = 1000;
	private Boolean Item = false;	
	
	public EntitySponge(World worldIn) {
		super(worldIn);

	}
	
	
	public void EntitySpongeadd(World worldIn, Block purpose,Item purposeItem, Object time) {
		
		this.time = time;
		
		//glass
		if(this.time == (Object)1000) {
			this.Item = false;
			this.purpose = ModBlocks.MAGIC_BLOCK;
		}
		//glass
		if(this.time == (Object)5000) {
			this.Item = false;
			this.purposeItem = ModItems.ORB_OF_CHANNELING;	
		}				
}

	@Override
	protected void entityInit() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void readEntityFromNBT(NBTTagCompound compound) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void writeEntityToNBT(NBTTagCompound compound) {
		// TODO Auto-generated method stub
		
	}

	
	@Override
	protected SoundEvent getAmbientSound() {
		return SoundEvents.BLOCK_BREWING_STAND_BREW;

	}
	@Override
	protected SoundEvent getHurtSound(DamageSource source) {
		return SoundEvents.BLOCK_FIRE_AMBIENT;

	}
	@Override
	protected SoundEvent getDeathSound() {
		return SoundEvents.BLOCK_FIRE_EXTINGUISH;

	}	
    @Override
    protected ResourceLocation getLootTable()
    {
        return LootTableList.EMPTY;
    }
	
    public void onLivingUpdate() {
        for (int i = 0; i < 1; ++i)
        {
        timer((int)this.time);
        
        }
}
    
    public void timer(int time) {
    	try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

 

 

the thing is that I am trying to make this entity appear to be a different item/block upon being spawned by the FocusBlock with it's own properties such as purposeItem/purposeblock (the item/block it is supposed to create after sitting on top of the custom block) so that it appears to be an item. i resorted to this method because I was struggling with using an actual item to complete my goal. The entity seems to be registering normally,however upon being spawned a null pointer exception comes up on console and the game doesn't crash. How would I go about using different textures for this entity. Would I use another entity per special crafting recipe?

Edited by Whompy
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.