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.

Featured Replies

Posted

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

  • Author

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

  • Author
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

  • Author

Eh I'll just create an entity for each recipe who cares about efficiency ?

  • Author
1 minute ago, diesieben07 said:

Why on earth are you using Object here? 

 

You can't do this. This will make the entire game wait for that amount of time.

 

 

idk I was trying to store entity specific information

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...

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.