Jump to content

Recommended Posts

Posted

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.

Posted

I'm just replying because I need to fix this Problem. It's my main Problem right now and I've been searching for a solution for a month now.

Please Help!

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

Posted

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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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