Jump to content

Guichaguri

Members
  • Posts

    12
  • Joined

  • Last visited

Posts posted by Guichaguri

  1. Hello all,

    I wanted to render a line going from a point to another. The problem of GL_LINES is that the texture is rendered 1 pixel wide. The solution that i found is render a quad going from a point to another, but i'm having issues when rendering the quad that needs to face the player

     

    I took this code from "renderParticle", and it works perfectly if you want to draw a textured square.

    private double prevFromX, prevFromY, prevFromZ;
    private double prevToX, prevToY, prevToZ;
    public void render(float partialTicks, double fromX, double fromY, double fromZ, double toX, double toY, double toZ) {
            float rX = ActiveRenderInfo.rotationX;
            float rZ = ActiveRenderInfo.rotationZ;
            float rYZ = ActiveRenderInfo.rotationYZ;
            float rXY = ActiveRenderInfo.rotationXY;
            float rXZ = ActiveRenderInfo.rotationXZ;
    
            float startX = (float)(prevFromX + (fromX - prevFromX) * partialTicks);
            float startY = (float)(prevFromY + (fromY - prevFromY) * partialTicks);
            float startZ = (float)(prevFromZ + (fromZ - prevFromZ) * partialTicks);
    
            float endX = (float)(prevToX + (fromX - prevToX) * partialTicks);
            float endY = (float)(prevToY + (fromY - prevToY) * partialTicks);
            float endZ = (float)(prevToZ + (fromZ - prevToZ) * partialTicks);
    
            t.startDrawingQuads();
    
            t.addVertexWithUV(startX - rX - rYZ, startY - rXZ, startZ - rZ - rXY, 0, 1);
            t.addVertexWithUV(startX - rX + rYZ, startY + rXZ, startZ - rZ + rXY, 1, 1);
            t.addVertexWithUV(startX + rX + rYZ, startY + rXZ, startZ + rZ + rXY, 1, 0);
            t.addVertexWithUV(startX + rX - rYZ, startY - rXZ, startZ + rZ - rXY, 0, 0);
    
            t.draw();
    
            this.prevFromX = fromX;
            this.prevFromY = fromY;
            this.prevFromZ = fromZ;
    
            this.prevToX = toX;
            this.prevToY = toY;
            this.prevToZ = toZ;
    }

    I'm using this method in RenderWorldLastEvent

     

    What should I change in the vertexes to work with endX, endY and endZ?

     

    Thanks for any help and sorry for my bad english :(

  2. To avoid overwriting vanilla particle texture, theres a easy solution:

     

        @Override
        public void func_180434_a(WorldRenderer worldRenderer, Entity e, float f1, float f2, float f3, float f4, float f5, float f6) {
            Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation);
            GlStateManager.enableBlend();
            GlStateManager.blendFunc(770, 771);
            worldRenderer.startDrawingQuads();
            super.func_180434_a(worldRender, e, f1, f2, f3, f4, f5, f6);
            Tessellator.getInstance().draw();
            GlStateManager.disableBlend();
            GlStateManager.enableLighting();
        }
        @Override
        public int getFXLayer() {
            return 3; // THE IMPORTANT PART
        }
    

     

    With getFXLayer returning 3, I can draw the particle by myself.

  3. I did it! Probably it's not the best solution, but it works.

    I took a look at the EffectRenderer (the class where particles were rendered) and as I could see, the custom texture was never used, but I found a method that is used to render the particle after binding the texture: func_180434_a

    This is not the best solution for it, vanilla particles will render with your sprite (i already filled a bug report on github, so particleIcon should work soon)

     

    My working code:

     

     

    @SideOnly(Side.CLIENT)
    public class ParticleTest extends EntityFX {
        private static ResourceLocation loc = new ResourceLocation("MODID", "textures/particle/custom.png");
        public ParticleTest(World w, double x, double y, double z, double offsetX, double offsetY, double offsetZ) {
            super(w, x, y, z, offsetX, offsetY, offsetZ);
            this.particleTextureIndexX = 0;
            this.particleTextureIndexY = 0;
            this.noClip = false;
            this.particleAge = 0;
            this.particleMaxAge = 500;
            this.particleScale *= 1.4F;
            this.particleRed = this.particleGreen = this.particleBlue = 1;
            this.particleAlpha = 1;
        }
    
        @Override
        public void func_180434_a(WorldRenderer w, Entity e, float f1, float f2, float f3, float f4, float f5, float f6) {
            Minecraft.getMinecraft().renderEngine.bindTexture(loc); // THE MAGIC
            super.func_180434_a(w, e, f1, f2, f3, f4, f5, f6);
        }
    
        @Override
        public void onUpdate() {
            // ...
        }
    
    }

     

    *YOU SHOULD KEEP particleIcon NULL FOR THIS TO WORK*

     

    Someone should commit to forge creating a patch to make "particleIcon" work, maybe I do it by myself

     

    Also, sorry for my bad english.

  4. My code:

     

    @SideOnly(Side.CLIENT)
    public class TestParticle extends EntityFX {
    
        public TestParticle(World w, double x, double y, double z, double offsetX, double offsetY, double offsetZ) {
            super(w, x, y, z, offsetX, offsetY, offsetZ);
            this.particleIcon = TestTextureManager.createTexture(new ResourceLocation("MyModID", "textures/particle/custom.png"));
            this.particleTextureIndexX = 0;
            this.particleTextureIndexY = 0;
            this.noClip = false;
            this.particleAge = 0;
            this.particleMaxAge = 500;
            this.particleScale *= 1.4F;
            this.particleRed = this.particleGreen = this.particleBlue = 1;
            this.particleAlpha = 1;
        }
    
        @Override
        public void onUpdate() {
            this.prevPosX = this.posX;
            this.prevPosY = this.posY;
            this.prevPosZ = this.posZ;
            particleAge++;
            if(particleAge > particleMaxAge) {
                this.setDead();
                return;
            }
    
            moveEntity(motionX, motionY, motionZ);
            motionX *= motionX > 0.04 ? 1 : 1.03;
            motionY *= motionY > 0.04 ? 1 : 1.03;
            motionZ *= motionZ > 0.04 ? 1 : 1.03;
        }
    
    }

    PS: "MyModID" have the correct value, i just changed here

     

    TestTextureManager:

     

    public class TestTextureManager extends TextureAtlasSprite {
        public static TextureAtlasSprite createTexture(ResourceLocation loc) {
            return TextureAtlasSprite.makeAtlasSprite(loc);
        }
        private TestTextureManager(String sprite) {
            super(sprite);
        }
    }

     

    If I comment the line of "particleIcon", everything works fine but it uses vanilla texture sprite. I think the problem is with the "createTexture"

  5. Hello all, i became from Bukkit and i'm new to the Forge.

     

    I have little questions about world timing:

     

    Is there a way to get total day duration? (in overworld, total day duration is 24000 ticks)

    If not, it'll be a problem to use 24000 as a raw number?

     

    I know that I can get the current day time by

    (world.getWorldTime() % 24000)

    and I don't know if forge let you change the day duration for a dimension, so I want to make it dynamic

     

    Thanks for any help and sorry for my bad english :'(

×
×
  • Create New...

Important Information

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