Jump to content

Entity teleports upwards whenever something collides with it


Recommended Posts

Posted

My entity (not entity living ) keeps teleporting when anything touches it. It teleports up about 10 blocks (the actual entity does, not just the model). When I try to go under it, I can't. I seems to have an invisible barrier beneath it, and whenever I touch that barrier, the screen shakes and I get stuck in the barrier. This is not the bounding box, because the bounding box is where the entity is (using F3+B). After a little while, the entity will come back down. Then it starts all over again.

 

code:

 

package com.apmods.creeps.entity;

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

public class EntitySlotMachine extends Entity{

public EntitySlotMachine(World worldIn) {
	super(worldIn);
	this.setSize(2, 3);
}

@Override
protected void entityInit() {
	this.dataWatcher.addObject(14, new Integer(0));
	this.dataWatcher.addObject(15, new Integer(0));
	this.dataWatcher.addObject(16, new Integer(0));
}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
	this.setSlot(0, tagCompund.getInteger("slot1"));
	this.setSlot(1, tagCompund.getInteger("slot2"));
	this.setSlot(2, tagCompund.getInteger("slot3"));

}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
	tagCompound.setInteger("slot1", this.getSlot(0));
	tagCompound.setInteger("slot2", this.getSlot(1));
	tagCompound.setInteger("slot3", this.getSlot(2));
}

public void setSlot(int slot, int state){
	this.dataWatcher.updateObject(14 + slot, state);
}

public int getSlot(int slot){
	return this.dataWatcher.getWatchableObjectInt(14 + slot);
}

@Override
public void onUpdate() {
	// TODO Auto-generated method stub
	super.onUpdate();
	this.prevPosX = posX;
	this.prevPosY = posY;
	this.prevPosZ = posZ;
	if(!this.onGround){
		this.moveEntity(0, -0.5, 0);
	}
}

@Override
public boolean interactFirst(EntityPlayer playerIn) {

	if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != playerIn)
        {
            return true;
        }
        else
        {
            if (!this.worldObj.isRemote)
            {
                playerIn.mountEntity(this);
            }

            return true;
        }
}

@Override
public AxisAlignedBB getBoundingBox() {
	// TODO Auto-generated method stub
	return this.getEntityBoundingBox();
}

@Override
public AxisAlignedBB getCollisionBox(Entity entityIn) {
	// TODO Auto-generated method stub
	return this.getEntityBoundingBox();
}

@Override
public boolean canBeCollidedWith() {
	// TODO Auto-generated method stub
	return !this.isDead;
}

@Override
public boolean canBePushed() {
	// TODO Auto-generated method stub
	return !this.isDead;
}

@Override
public double getMountedYOffset() {
	// TODO Auto-generated method stub
	return this.height * 0.4;
}

}

 

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

I agree with coolAlias, many problems I've encountered with entities have stemmed from not calling the supers in each method I override.  ;D

 

If that doesn't work, try slowly removing each method you override to see which one is causing the issue.

Kain

Posted

The problematic method is Entity.func_180426_a(), which is called whenever the entity receives a position packet from the server.

 

By default that method moves entities up if they're colliding with something, just override the method so it doesnt do that.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

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.