From e52abcf704333a43eb77f62102d6896523447855 Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Thu, 30 Apr 2015 13:18:48 +0100 Subject: [PATCH] Add pixie trail particle --- .../api/particle/BOPParticleTypes.java | 6 + .../client/particle/EntityPixieTrailFX.java | 106 ++++++++++++++++++ .../common/entities/EntityPixie.java | 6 +- .../java/biomesoplenty/core/ClientProxy.java | 28 ++++- .../java/biomesoplenty/core/CommonProxy.java | 3 +- .../textures/particles/pixietrail.png | Bin 0 -> 756 bytes 6 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 src/main/java/biomesoplenty/api/particle/BOPParticleTypes.java create mode 100644 src/main/java/biomesoplenty/client/particle/EntityPixieTrailFX.java create mode 100644 src/main/resources/assets/biomesoplenty/textures/particles/pixietrail.png diff --git a/src/main/java/biomesoplenty/api/particle/BOPParticleTypes.java b/src/main/java/biomesoplenty/api/particle/BOPParticleTypes.java new file mode 100644 index 000000000..70b035cd6 --- /dev/null +++ b/src/main/java/biomesoplenty/api/particle/BOPParticleTypes.java @@ -0,0 +1,6 @@ +package biomesoplenty.api.particle; + +public enum BOPParticleTypes +{ + PIXIETRAIL; +} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/client/particle/EntityPixieTrailFX.java b/src/main/java/biomesoplenty/client/particle/EntityPixieTrailFX.java new file mode 100644 index 000000000..c10c9aace --- /dev/null +++ b/src/main/java/biomesoplenty/client/particle/EntityPixieTrailFX.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.client.particle; + +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.texture.SimpleTexture; +import net.minecraft.entity.Entity; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +public class EntityPixieTrailFX extends EntityFX +{ + + public static ResourceLocation textureLocation = new ResourceLocation("biomesoplenty:textures/particles/pixietrail.png"); + public static SimpleTexture texture; + float pixieTrailParticleScale; + + public EntityPixieTrailFX(World world, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn) + { + this(world, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, 1.0F); + } + + public EntityPixieTrailFX(World world, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, float par14) + { + super(world, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D); + + this.motionX *= 0.10000000149011612D; + this.motionY *= 0.10000000149011612D; + this.motionZ *= 0.10000000149011612D; + this.motionX += xSpeedIn; + this.motionY += ySpeedIn; + this.motionZ += zSpeedIn; + this.particleScale *= 0.75F; + this.particleScale *= par14; + this.pixieTrailParticleScale = this.particleScale; + this.particleMaxAge = (int)((8.0D / (Math.random() * 0.8D + 0.2D)) * 8); + this.particleMaxAge = (int)((float)this.particleMaxAge * par14); + this.particleAge = (particleMaxAge / 2) + (int)((particleMaxAge / 2) * world.rand.nextInt(7)); + this.particleAlpha = 1.0F; + this.noClip = false; + } + + @Override + public void renderParticle(WorldRenderer worldRendererIn, Entity entity, float partialTicks, float p_180434_4_, float p_180434_5_, float p_180434_6_, float p_180434_7_, float p_180434_8_) + { + + // EffectRenderer will by default bind the vanilla particles texture, override with our own (this is loaded and initialized in ClientProxy) + GlStateManager.bindTexture(texture.getGlTextureId()); + + float scaleMultiplier = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F; + scaleMultiplier = MathHelper.clamp_float(scaleMultiplier, 0.0F, 1.0F); + this.particleScale = this.particleScale * scaleMultiplier; + + GlStateManager.depthMask(false); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 1); + + super.renderParticle(worldRendererIn, entity, partialTicks, p_180434_4_, p_180434_5_, p_180434_6_, p_180434_7_, p_180434_8_); + + GlStateManager.disableBlend(); + GlStateManager.depthMask(true); + } + + @Override + public void onUpdate() + { + prevPosX = posX; + prevPosY = posY; + prevPosZ = posZ; + + if (particleAge++ >= particleMaxAge) + { + this.setDead(); + } + + this.setParticleTextureIndex(7 - particleAge * 8 / particleMaxAge); + this.moveEntity(motionX, motionY, motionZ); + + if (posY == prevPosY) + { + motionX *= 1.1D; + motionZ *= 1.1D; + } + + motionX *= 0.9599999785423279D; + motionY *= 0.9599999785423279D; + motionZ *= 0.9599999785423279D; + + if (onGround) + { + motionX *= 0.699999988079071D; + motionZ *= 0.699999988079071D; + } + } + + +} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/entities/EntityPixie.java b/src/main/java/biomesoplenty/common/entities/EntityPixie.java index 83ae23e49..cdca661fc 100644 --- a/src/main/java/biomesoplenty/common/entities/EntityPixie.java +++ b/src/main/java/biomesoplenty/common/entities/EntityPixie.java @@ -14,6 +14,8 @@ import java.util.List; import java.util.Random; import biomesoplenty.api.item.BOPItems; +import biomesoplenty.api.particle.BOPParticleTypes; +import biomesoplenty.core.BiomesOPlenty; import net.minecraft.entity.EntityFlying; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.EntityMoveHelper; @@ -22,7 +24,6 @@ import net.minecraft.item.Item; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.MathHelper; import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.World; @@ -60,8 +61,7 @@ public class EntityPixie extends EntityFlying implements IMob { { if (this.rand.nextInt(2)==0) { - // TODO: add pixie particle BiomesOPlenty.proxy.spawnParticle("pixietrail", this.posX + (this.rand.nextDouble()) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height - (double)this.yOffset, this.posZ + (this.rand.nextDouble()) * (double)this.width); - this.worldObj.spawnParticle(EnumParticleTypes.PORTAL, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height - 0.25D, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D, new int[0]); + BiomesOPlenty.proxy.spawnParticle(BOPParticleTypes.PIXIETRAIL, this.posX + (this.rand.nextDouble()) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height - 0.25D, this.posZ + (this.rand.nextDouble()) * (double)this.width); } } } diff --git a/src/main/java/biomesoplenty/core/ClientProxy.java b/src/main/java/biomesoplenty/core/ClientProxy.java index 73f7d64f2..7a79ae3ee 100644 --- a/src/main/java/biomesoplenty/core/ClientProxy.java +++ b/src/main/java/biomesoplenty/core/ClientProxy.java @@ -12,15 +12,21 @@ import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.block.statemap.IStateMapper; import net.minecraft.client.renderer.block.statemap.StateMap; +import net.minecraft.client.renderer.texture.SimpleTexture; +import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.client.registry.RenderingRegistry; import biomesoplenty.api.block.IBOPBlock; +import biomesoplenty.api.particle.BOPParticleTypes; +import biomesoplenty.client.particle.EntityPixieTrailFX; import biomesoplenty.common.config.MiscConfigurationHandler; import biomesoplenty.common.entities.EntityPixie; import biomesoplenty.common.entities.EntityWasp; @@ -29,7 +35,6 @@ import biomesoplenty.common.entities.RenderWasp; import biomesoplenty.common.entities.projectiles.EntityDart; import biomesoplenty.common.entities.projectiles.RenderDart; - public class ClientProxy extends CommonProxy { public static ResourceLocation[] bopTitlePanoramaPaths = new ResourceLocation[] {new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_0.png"), new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_1.png"), new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_2.png"), new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_3.png"), new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_4.png"), new ResourceLocation("biomesoplenty:textures/gui/title/background/panorama_5.png")}; @@ -38,6 +43,7 @@ public class ClientProxy extends CommonProxy public void registerRenderers() { Minecraft minecraft = Minecraft.getMinecraft(); + TextureManager textureManager = minecraft.renderEngine; if (MiscConfigurationHandler.overrideTitlePanorama) GuiMainMenu.titlePanoramaPaths = bopTitlePanoramaPaths; @@ -46,6 +52,11 @@ public class ClientProxy extends CommonProxy RenderingRegistry.registerEntityRenderingHandler(EntityDart.class, new RenderDart(minecraft.getRenderManager())); RenderingRegistry.registerEntityRenderingHandler(EntityWasp.class, new RenderWasp(minecraft.getRenderManager())); RenderingRegistry.registerEntityRenderingHandler(EntityPixie.class, new RenderPixie(minecraft.getRenderManager())); + + + // load the texture for EntityPixieTrailFX + EntityPixieTrailFX.texture = new SimpleTexture(EntityPixieTrailFX.textureLocation); + textureManager.loadTexture(EntityPixieTrailFX.textureLocation, EntityPixieTrailFX.texture); } @@ -75,4 +86,19 @@ public class ClientProxy extends CommonProxy } } } + + @Override + public void spawnParticle(BOPParticleTypes type, double x, double y, double z) + { + Minecraft minecraft = Minecraft.getMinecraft(); + EntityFX entityFx = null; + switch (type) + { + case PIXIETRAIL: + entityFx = new EntityPixieTrailFX(minecraft.theWorld, x, y, z, MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.03, 0.03), -0.02D, MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.03, 0.03)); + } + + if (entityFx != null) {minecraft.effectRenderer.addEffect(entityFx);} + } + } diff --git a/src/main/java/biomesoplenty/core/CommonProxy.java b/src/main/java/biomesoplenty/core/CommonProxy.java index 8bf004fea..502a1bc25 100644 --- a/src/main/java/biomesoplenty/core/CommonProxy.java +++ b/src/main/java/biomesoplenty/core/CommonProxy.java @@ -8,6 +8,7 @@ package biomesoplenty.core; +import biomesoplenty.api.particle.BOPParticleTypes; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -15,7 +16,7 @@ import net.minecraft.item.Item; public class CommonProxy { public void registerRenderers() {} - public void registerItemVariantModel(Item item, String name, int metadata) {} public void registerNonRenderingProperties(Block block) {} + public void spawnParticle(BOPParticleTypes type, double x, double y, double z) {} } \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/textures/particles/pixietrail.png b/src/main/resources/assets/biomesoplenty/textures/particles/pixietrail.png new file mode 100644 index 0000000000000000000000000000000000000000..0e13c50fc36651d43e2939fa875d67f4a67635d0 GIT binary patch literal 756 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSEa{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+K$tP>S|=w^P^!c=q9iy!t)x7$D3u`~F*C13&(AePq0Cs%RL{`R{j-xf0|Qfm zr;B4qMcmtK8+|_qh&UulwIy&)Tad<(rM6&6GSjLJOhT;E7YrG6g%@~aDlPS%*!_O< ze1nh5(}I>fn4>NGcOvsY!SB_4=}T_zeVbJA^3V0o_8B^s@9Nhbjdigpwe{P7&hlc8 zo!Qy=x>&C}Tc!)2|NHgr@3K#IcfNV+o|e_!eR}O=hEH-oP1g#?FqFJMo*mwF;`-wGJLmn`@n*gJul*Y)_n&x}TKsI< zjQN|_KD~1CsLU^&bC+*g9eld)>y-C@d3JuddVN*>`=qM>T&o#Q^*229d^D%x6z7{$ zsl3zcd?SnWRx)2`3cGi@y5#>hfvLjr{{J`Kegy%o;m%qtAsh@0bvH4QG!4i>~gJP=3^;L U^