Jump to content

[1.12.1] [Solved] Cannot interact with custom entity


fcelon

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

×
×
  • Create New...

Important Information

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