Jump to content

Entity moving weirdly?


Busti

Recommended Posts

Hello,

I've made an Entity which should be noclip but instead of being inside of a block it is glitching to the Top of blocks.

My Entity is using a Target system to go to its positions which works like the positioning system of the XP orb.

 

Here is the Code of my Entity:    http://pastebin.com/akYUhRDj

 

package busti2000.technica.entity;

import busti2000.technica.api.PipeAPI;
import busti2000.technica.tileentity.TileEntitySoulContainer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class PipeXPOrb extends Entity {

    /**
     * A constantly increasing value that RenderXPOrb uses to control the color shifting (Green / yellow)
     */
    public int xpColor;
    
    /** This is how much XP this orb has. */
    private int xpValue;
    
    private double tx;
    private double ty;
    private double tz;
    
    public boolean hasReachedTarget;
    
    private double speed = Math.random() * (0.3 - 0.1) + 0.1;

public PipeXPOrb(World par1World, double par2, double par4, double par6, int par8, double tx, double ty, double tz) {
	super(par1World);
	this.setSize(0.5F, 0.5F);
        this.setPosition(par2, par4, par6);
        this.rotationYaw = (float)(Math.random() * 360.0D);
        this.xpValue = par8;
        this.tx = tx;
        this.ty = ty;
        this.tz = tz;
        this.hasReachedTarget = false;
        this.noClip = true;
	}

    /**
     * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
     * prevent them from trampling crops
     */
    protected boolean canTriggerWalking() {
        return false;
    }

public PipeXPOrb(World par1World) {
        super(par1World);
        this.setSize(0.5F, 0.5F);
        this.noClip = true;
        this.hasReachedTarget = false;
}

protected void entityInit() {}

    @SideOnly(Side.CLIENT)
    public int getBrightnessForRender(float par1)
    {
        float f1 = 0.5F;

        if (f1 < 0.0F)
        {
            f1 = 0.0F;
        }

        if (f1 > 1.0F)
        {
            f1 = 1.0F;
        }

        int i = super.getBrightnessForRender(par1);
        int j = i & 255;
        int k = i >> 16 & 255;
        j += (int)(f1 * 15.0F * 16.0F);

        if (j > 240)
        {
            j = 240;
        }

        return j | k << 16;
    }

public void onUpdate() {

	super.onUpdate();

	if (!this.hasReachedTarget) {

		double d0 = 8.0D;
        	double d1 = (this.tx - this.posX) / d0;
        	double d2 = (this.ty - this.posY) / d0;
        	double d3 = (this.tz - this.posZ) / d0;
        	double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
        	double d5 = 1.0D - d4;
        	double d11 = (this.tx - this.posX);
        	double d12 = (this.ty - this.posY);
        	double d13 = (this.tz - this.posZ);
        	double d14 = Math.sqrt(d11 * d11 + d12 * d12 + d13 * d13);
        	
        	if (d5 > 0.0D)
        	{
            	d5 *= d5;
            	this.motionX = d1 / d4 * d5 * this.speed;
            	this.motionY = d2 / d4 * d5 * this.speed;
            	this.motionZ = d3 / d4 * d5 * this.speed;
        	}
        	if (d14 < 0.15D)	{
        		this.hasReachedTarget = true;
        		this.motionX = 0;
        		this.motionY = 0;
        		this.motionZ = 0;
        	}

	}
	        
	this.moveEntity(this.motionX, this.motionY, this.motionZ);

	this.xpColor++;

}

    /**
     * Returns the XP value of this XP orb.
     */
    public int getXpValue()
    {
        return this.xpValue;
    }
    
    @SideOnly(Side.CLIENT)
    
    /**
     * Returns a number from 1 to 10 based on how much XP this orb is worth. This is used by RenderXPOrb to determine
     * what texture to use.
     */
    public int getTextureByXP()
    {
        return this.xpValue >= 2477 ? 10 : (this.xpValue >= 1237 ? 9 : (this.xpValue >= 617 ? 8 : (this.xpValue >= 307 ? 7 : (this.xpValue >= 149 ? 6 : (this.xpValue >= 73 ? 5 : (this.xpValue >= 37 ? 4 : (this.xpValue >= 17 ? 3 : (this.xpValue >= 7 ? 2 : (this.xpValue >= 3 ? 1 : 0)))))))));
    }
    
    /**
     * If returns false, the item will not inflict any damage against entities.
     */
    public boolean canAttackWithItem()
    {
        return false;
    }
    
    /**
     * Sets the Target of the Orb
     */
    public void setTarget(double tx, double ty, double tz) {
        this.tx = tx;
        this.ty = ty;
        this.tz = tz;
        this.hasReachedTarget = false;
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
	this.xpValue = nbttagcompound.getShort("Value");
	this.tx = nbttagcompound.getDouble("tx");
	this.ty = nbttagcompound.getDouble("ty");
	this.tz = nbttagcompound.getDouble("tz");
	this.setDead();
}

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
	nbttagcompound.setShort("Value", (short)this.xpValue);
	nbttagcompound.setDouble("tx", this.tx);
	nbttagcompound.setDouble("ty", this.ty);
	nbttagcompound.setDouble("tz", this.tz);
}

}

 

And this is the Register code:

 

EntityRegistry.registerModEntity(PipeXPOrb.class, "PipeXPOrb", 1, this, 50, 1, true);

 

 

Thank you for any Help.

 

Busti

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

What is your problem? Maybe it is the same as mine.

Mine was a vehicle. I managed to solve the problem (partially) by giving it its own position and velocity variables, similar to the Boat or Minecart code. However, there is still a partial glitch when I ride on it, and there is also a problem with bounding boxes.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

It doesn't work but it actually helped a bit. I've also tried to make the Entity move manual by just doing this:

this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;

this.setPosition(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

but this doesn't work either so the Problem is not caused by noclip. It seems that my Entity is trying to go out of any bounding box but I couldn't find the code that is causing this.

I need to fix this because I need to make an Entity render inside of a Tube. I've already got the system for the tubes working and it is also working fine without the glitch when I don't register the Entity.

 

If you know what is causing this of if you had or still have the same problem please reply to this thread, anything could be helpful.

 

Busti

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

I've tried to override move entity to move it just with position updates but it seems theat this is a render issue. I discoverd that its position is right but it seems that the renderer has a pushOutOf blocks function too.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

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.