Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Spawns particle of a given type in a given direction*/
- @OnlyIn(Dist.CLIENT)
- public static void createLinearParticles(IParticleData particleType, World worldIn, Vec3d pos, Vec3d direction,
- double speed, double acceleration, int count, double distanceIn, double distanceMax) {
- double upper = 0.1;
- double lower = -0.1;
- double upperVelocity = 0.03;
- double lowerVelocity = -0.03;
- int lifetime;
- for(int i = 0; i <= count; ++i) {
- double velocity = speed + (acceleration * i);
- if(distanceIn == distanceMax) {
- lifetime = (int) (distanceIn / velocity) - 1;
- //System.out.println("dist" + distanceIn);
- //System.out.println("vel" + velocity);
- }
- else {
- lifetime = (int) (distanceIn / velocity);
- //System.out.println("dist" + distanceIn);
- //System.out.println("vel" + velocity);
- }
- GraphicHelper.addParticle(particleType, worldIn,
- pos.x + ((Math.random() * (upper - lower) + lower)),
- pos.y + ((Math.random() * (upper - lower) + lower)),
- pos.z + ((Math.random() * (upper - lower) + lower)),
- (direction.x + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
- (direction.y + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
- (direction.z + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
- lifetime);
- //System.out.println(speed * (1 + acceleration*i));
- }
- }
- /** Adds a particle with a custom lifetime to the world*/
- @OnlyIn(Dist.CLIENT)
- public static void addParticle(IParticleData particleData, World worldIn, double x, double y, double z, double xSpeed,
- double ySpeed, double zSpeed, int lifetime) {
- Minecraft mc = Minecraft.getInstance();
- ActiveRenderInfo activerenderinfo = mc.gameRenderer.getActiveRenderInfo();
- Particle particle;
- if (activerenderinfo.isValid() && mc.particles != null) {
- ParticleStatus particlestatus = getParticleStatus(false, mc, worldIn);
- if (particleData.getType().getAlwaysShow()) {
- particle = mc.particles.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
- assert particle != null;
- particle.setMaxAge(lifetime);
- } else if (activerenderinfo.getProjectedView().squareDistanceTo(x, y, z) > 1024.0D) {
- System.out.println("out of render range");
- } else {
- if (particlestatus == ParticleStatus.MINIMAL) System.out.println("minimal status");
- else {
- particle = mc.particles.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
- assert particle != null;
- particle.setMaxAge(lifetime);
- }
- }
- } else {
- System.out.println("null particle");
- }
- }
- /** Gets particle status with custom implementation*/
- @OnlyIn(Dist.CLIENT)
- private static ParticleStatus getParticleStatus(boolean render, Minecraft mc, World worldIn) {
- ParticleStatus particlestatus = mc.gameSettings.particles;
- if (render && particlestatus == ParticleStatus.MINIMAL && worldIn.rand.nextInt(10) == 0) {
- particlestatus = ParticleStatus.DECREASED;
- }
- if (particlestatus == ParticleStatus.DECREASED && worldIn.rand.nextInt(3) == 0) {
- particlestatus = ParticleStatus.MINIMAL;
- }
- return particlestatus;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement