Jump to content

[1.8] Trying to make a particle with a custom texture


The_SlayerMC

Recommended Posts

So I'm trying to make my custom particle have a custom texture, and that doesn't seem to be working... Here is my particle class:

package net.industrial_magic.client.particle;

import net.industrial_magic.event.TextureMagicParticle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.renderer.texture.TextureClock;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.slayer.api.SlayerAPI;

@SideOnly(Side.CLIENT)
public class EntityMagicFX extends EntityFX {

    private float scale;
    private double x;
    private double y;
    private double z;

    public EntityMagicFX(World worldIn, double p_i1204_2_, double p_i1204_4_, double p_i1204_6_, double p_i1204_8_, double p_i1204_10_, double p_i1204_12_) {
        super(worldIn, p_i1204_2_, p_i1204_4_, p_i1204_6_, p_i1204_8_, p_i1204_10_, p_i1204_12_);
        this.motionX = p_i1204_8_;
        this.motionY = p_i1204_10_;
        this.motionZ = p_i1204_12_;
        this.x = p_i1204_2_;
        this.y = p_i1204_4_;
        this.z = p_i1204_6_;
        this.posX = this.prevPosX = p_i1204_2_ + p_i1204_8_;
        this.posY = this.prevPosY = p_i1204_4_ + p_i1204_10_;
        this.posZ = this.prevPosZ = p_i1204_6_ + p_i1204_12_;
        float f = this.rand.nextFloat() * 0.6F + 0.4F;
        this.scale = this.particleScale = this.rand.nextFloat() * 0.5F + 0.2F;
        this.particleRed = this.particleGreen = this.particleBlue = 1.0F * f;
        this.particleGreen *= 0.9F;
        this.particleRed *= 0.9F;
        this.particleMaxAge = (int)(Math.random() * 10.0D) + 30;
        this.noClip = true;
        func_180435_a(new TextureMagicParticle("builtin/particles"));
        //this.setParticleTextureIndex(rand.nextInt(3));
    }
    
    @Override
    public int getFXLayer() {
    	return 1;
    }

    @Override
    public int getBrightnessForRender(float f) {   
        return 100;
    }

    @Override
    public float getBrightness(float p_70013_1_) {
        return 100F;
    }

    @Override
    public void onUpdate() {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        float f = (float)this.particleAge / (float)this.particleMaxAge;
        f = 1.0F - f;
        float f1 = 1.0F - f;
        f1 *= f1;
        f1 *= f1;
        this.posX = this.x + this.motionX * (double)f;
        this.posY = this.y + this.motionY * (double)f - (double)(f1 * 1.2F);
        this.posZ = this.z + this.motionZ * (double)f;
        if(this.particleAge++ >= this.particleMaxAge) this.setDead();
    }
}

 

And here is my TextureMagicParticle:

package net.industrial_magic.event;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.slayer.api.SlayerAPI;

public class TextureMagicParticle extends TextureAtlasSprite {

public TextureMagicParticle(String spriteName) {
	super(spriteName);
	makeAtlasSprite(new ResourceLocation(SlayerAPI.PREFIX + "textures/misc/particles.png"));
}

@Override
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
	return true;
}
}

 

Now with the 1.8 update, it seems difficult making custom a texture

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Link to comment
Share on other sites

  • 2 weeks later...

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"

Link to comment
Share on other sites

When I poked at custom particles last, I had to manually bind a new texture (and then rebind the vanilla one).

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/client/AntibuilderParticle.java#L59

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

I'm assuming from this you want to create your own particle shape.

 

If, you want to use one of the standard shapes, you can just extend them and then change the color to match what you want.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

When I poked at custom particles last, I had to manually bind a new texture (and then rebind the vanilla one).

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/client/AntibuilderParticle.java#L59

 

1.8 don't have "renderParticle" anymore.. :/

 

Well shucks.

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

  • 3 weeks later...

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.

Link to comment
Share on other sites

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
    • I removed all related embeddium and oculus mods, i just tested it by disconnecting and the error happened again. heres the report https://pastebin.com/1kcR5wAt   EDIT: i tried removing xaeros and also smoothboot thinking there may be an issue there, nothing, heres that report too. https://pastebin.com/zQS7i9rM
    • Hi, I need suggestions. I am a beginner in Minecraft Modding. I would like to apply custom effects to some armors, something like: more chance to drop seeds, change zombie awareness, drop more pieces of wood when chopping logs, and things like that. How would you recommend me to do it, is there any library that has something similar and which ones would you recommend me?.
    • "downloading minecraft server failed, invalid Checksum. try again, or manually place server.jar to skip download"    
    • You have to create an Entity class called PlayerPart and use multiple of them to make the different parts of the player. See EnderDragonPart.java source code. The green hitboxes of the dragon are all EnderDragonParts
  • Topics

×
×
  • Create New...

Important Information

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