Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.TheRPGAdventurer.ROTD.client.render;
- import java.util.Random;
- import com.TheRPGAdventurer.ROTD.server.entity.helper.breath.BreathNode;
- import com.TheRPGAdventurer.ROTD.util.breath.EntityMoveAndResizeHelper;
- import com.TheRPGAdventurer.ROTD.util.breath.RotatingQuad;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.BufferBuilder;
- import net.minecraft.client.renderer.texture.TextureAtlasSprite;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.MoverType;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.EnumParticleTypes;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- /**
- * Created by TGG on 21/06/2015.
- * EntityFX that makes up the flame breath weapon; client side.
- *
- * Usage:
- * (1) create a new FlameBreathFX using createFlameBreathFX
- * (2) spawn it as per normal
- *
- */
- public class FlameBreathFX extends Entity {
- private final float SMOKE_CHANCE = 0.1f;
- private final float LARGE_SMOKE_CHANCE = 0.3f;
- private static final float MAX_ALPHA = 0.99F;
- public float particleScale;
- private BreathNode breathNode;
- private FlameBreathFX(World world, double x, double y, double z, Vec3d motion,
- BreathNode i_breathNode) {
- super(world);
- breathNode = i_breathNode;
- this.setPosition(x, y, z);
- this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
- //undo random velocity variation of vanilla EntityFX constructor
- motionX = motion.x;
- motionY = motion.y;
- motionZ = motion.z;
- entityMoveAndResizeHelper = new EntityMoveAndResizeHelper(this);
- }
- /** call once per tick to update the EntityFX size, position, collisions, etc
- */
- @Override
- public void onUpdate() {
- final float YOUNG_AGE = 0.25F;
- final float OLD_AGE = 0.75F;
- float lifetimeFraction = breathNode.getLifetimeFraction();
- final float PARTICLE_SCALE_RELATIVE_TO_SIZE = 5.0F; // factor to convert from particleSize to particleScale
- float currentParticleSize = breathNode.getCurrentRenderDiameter();
- particleScale = PARTICLE_SCALE_RELATIVE_TO_SIZE * currentParticleSize;
- // spawn a smoke trail after some time
- if (SMOKE_CHANCE != 0 && rand.nextFloat() < lifetimeFraction && rand.nextFloat() <= SMOKE_CHANCE) {
- world.spawnParticle(getSmokeParticleID(), posX, posY, posZ, motionX * 0.5, motionY * 0.5, motionZ * 0.5);
- }
- // smoke / steam when hitting water. node is responsible for aging to death
- if (handleWaterMovement()) {
- world.spawnParticle(getSmokeParticleID(), posX, posY, posZ, 0, 0, 0);
- }
- float newAABBDiameter = breathNode.getCurrentAABBcollisionSize();
- prevPosX = posX;
- prevPosY = posY;
- prevPosZ = posZ;
- entityMoveAndResizeHelper.moveAndResizeEntity(motionX, motionY, motionZ, newAABBDiameter, newAABBDiameter);
- if (isCollided && onGround) {
- motionY -= 0.01F; // ensure that we hit the ground next time too
- }
- breathNode.updateAge(this);
- if (breathNode.isDead()) {
- setDead();
- }
- }
- /**
- * creates a single EntityFX from the given parameters. Applies some random spread to direction.
- * @param world
- * @param x world [x,y,z] to spawn at (inates are the centre point of the fireball)
- * @param y
- * @param z
- * @param directionX initial world direction [x,y,z] - will be normalised.
- * @param directionY
- * @param directionZ
- * @param power the power of the ball
- * @param partialTicksHeadStart if spawning multiple EntityFX per tick, use this parameter to spread the starting
- * location in the direction
- * @return the new FlameBreathFX
- */
- public static FlameBreathFX createFlameBreathFX(World world, double x, double y, double z,
- double directionX, double directionY, double directionZ,
- BreathNode.Power power,
- float partialTicksHeadStart) {
- Vec3d direction = new Vec3d(directionX, directionY, directionZ).normalize();
- Random rand = new Random();
- BreathNode breathNode = new BreathNode(power);
- breathNode.randomiseProperties(rand);
- Vec3d actualMotion = breathNode.getRandomisedStartingMotion(direction, rand);
- x += actualMotion.x * partialTicksHeadStart;
- y += actualMotion.y * partialTicksHeadStart;
- z += actualMotion.z * partialTicksHeadStart;
- FlameBreathFX newFlameBreathFX = new FlameBreathFX(world, x, y, z, actualMotion, breathNode);
- return newFlameBreathFX;
- }
- protected EnumParticleTypes getSmokeParticleID() {
- if (LARGE_SMOKE_CHANCE != 0 && rand.nextFloat() <= LARGE_SMOKE_CHANCE) {
- return EnumParticleTypes.SMOKE_LARGE;
- } else {
- return EnumParticleTypes.SMOKE_NORMAL;
- }
- }
- /** Vanilla moveEntity does a pile of unneeded calculations, and also doesn't handle resize around the centre properly,
- * so replace with a custom one
- * @param dx the amount to move the entity in world inates [dx, dy, dz]
- * @param dy
- * @param dz
- */
- @Override
- public void move(MoverType mover, double dx, double dy, double dz) {
- entityMoveAndResizeHelper.moveAndResizeEntity(dx, dy, dz, this.width, this.height);
- }
- private EntityMoveAndResizeHelper entityMoveAndResizeHelper;
- @Override
- protected void entityInit() {
- }
- @Override
- protected void readEntityFromNBT(NBTTagCompound compound) {
- }
- @Override
- protected void writeEntityToNBT(NBTTagCompound compound) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment