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

Hello,

I have created my own entity, but I can't interact with it. When I spawn it into the world, I can see it's hitbox, but clicking on it does nothing and I can even place blocks right into it. This is my entity code. What should I do to make the hitbox work?

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;

public class EntityBallista extends Entity {
	
	public EntityBallista(World worldIn) {
		super(worldIn);
		this.setSize(3, 2);
		this.entityCollisionReduction = 1;
		System.out.println(this.getEntityBoundingBox());
		System.out.println(this.getCollisionBox(this));
	}
	
	@Override
	public AxisAlignedBB getCollisionBox(Entity entityIn) {
		return entityIn.getEntityBoundingBox();
	}
	
	public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
    {
		System.out.println("Interacting");
        if (player.isSneaking())
        {
            return false;
        }
        else if (this.isBeingRidden())
        {
            return true;
        }
        else
        {
            if (!this.world.isRemote)
            {
                player.startRiding(this);
            }

            return true;
        }
    }

	@Override
	protected void entityInit() {
		
	}

	@Override
	protected void readEntityFromNBT(NBTTagCompound compound) {
		//super.readFromNBT(compound);
		
	}

	@Override
	protected void writeEntityToNBT(NBTTagCompound compound) {
		//super.writeToNBT(compound);
		
	}

}

Thanks for any help.

Edited by fcelon
Solved

Without the readEntityFromNBT and writeEntityToNBT methods calling super, your entity on the client can't be synchronized with the copy on the server.

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.

  • Author

With the readEntityFromNBT and writeEntityToNBT methods calling super, an infinite loop will be created (readFromNBT calls readEntityFromNBT). I have already tried this and the entity could not be summoned.

Then you need to not override the method. Overriding a method to do nothing is almost never the correct thing to do.

 

That or call the correct super method...super.readEntityFromNBT

Edited by Draco18s

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.

  • Author

Even without the @Override annotation calling the super.readFromNBT still causes the infinite loop.

Jesus christ on a crutch

24 minutes ago, Draco18s said:

That or call the correct super method...super.readEntityFromNBT

 

18 minutes ago, fcelon said:

Even without the @Override annotation calling the super.readFromNBT still causes the infinite loop.

@Override is just an IDE directive, it isn't actually compiled to bytecode

Edited by Draco18s

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.

  • Author

super.readEntityFromNBT doesn't work.

Cannot directly invoke the abstract method readEntityFromNBT(NBTTagCompound) for the type Entity

Oh, you're extending Entity directly. I missed that.


Not sure what's preventing you from interacting with it then.

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.

  • Author

I just found it.

@Override
	public boolean canBeCollidedWith() {
		return true;
	}

After adding this to the code the entity works fine.

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.