Advertisement
Corosus

Weather mod particle manipulation code snippets

May 3rd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. //To make custom particles see this badly colored tutorial: http://coros.us/mods/wiki-modding?a=Custom_Particle_Textures
  2.  
  3. //spawning the leafs is just a matter of scanning around the player and looking for leaf blocks then spawning them like in the tutorial, not too complicated
  4.  
  5. //As for the more complicated manipulation of the particles....
  6.  
  7. //How I get access to the active particles in minecraft, call this in your tick if fxLayers = null
  8. public static List fxLayers[];
  9. public static void getFXLayers() {
  10.        
  11.         //fxLayers
  12.        
  13.         Field field = null;
  14.         try {
  15.             field = (EffectRenderer.class).getDeclaredField("b");
  16.             field.setAccessible(true);
  17.             fxLayers = (List[])field.get(ModLoader.getMinecraftInstance().effectRenderer);
  18.         } catch (Exception ex) {
  19.             try {
  20.                 field = (EffectRenderer.class).getDeclaredField("fxLayers");
  21.                 field.setAccessible(true);
  22.                 fxLayers = (List[])field.get(ModLoader.getMinecraftInstance().effectRenderer);
  23.             } catch (Exception ex2) {
  24.                 ex2.printStackTrace();
  25.             }
  26.         }
  27.     }
  28.  
  29. //Main wind methods, using a strength and direction of the wind
  30.  
  31. public void wind() {    
  32.       if (fxLayers != null && weatherMan.wind.strength >= 0.10) {
  33.             for (int layer = 0; layer < 4; layer++) {
  34.                 for(int i = 0; i < fxLayers[layer].size(); i++) {
  35.                     Entity entity1 = (Entity)fxLayers[layer].get(i);
  36.                     if ((worldRef.getHeightValue((int)(entity1.posX+0.5F), (int)(entity1.posZ+0.5F))-1 < (int)entity1.posY+1) || (entity1 instanceof c_w_EntityTexFX)) {
  37.                         if ((entity1 instanceof EntityFlameFX)) {
  38.                             ((EntityFX)entity1).particleAge+=2;
  39.                         } else if (((EntityFX)entity1).particleAge % 2 == 0) {
  40.                             ((EntityFX)entity1).particleAge+=1;
  41.                         }
  42.                        
  43.                         //rustle!
  44.                         if (entity1.onGround) {
  45.                             //entity1.onGround = false;
  46.                             entity1.motionY += entity1.rand.nextDouble() * entity1.motionX;
  47.                         }
  48.                        
  49.                         if (entity1.motionX < 0.01F && entity1.motionZ < 0.01F) {
  50.                             entity1.motionY += entity1.rand.nextDouble() * 0.05;
  51.                         }
  52.                        
  53.                    
  54.                         applyWindForce(entity1);
  55.                     }
  56.                 }
  57.             }
  58.           }
  59.     }
  60.  
  61.     public static void applyWindForce(Entity ent) {
  62.         applyWindForce(ent, 1D);
  63.     }
  64.  
  65.     public static void applyWindForce(Entity ent, double multiplier) {
  66.         double speed = weatherMan.wind.strength * 0.1D / getWeight(ent);
  67.         speed *= multiplier;
  68.         if ((ent.onGround && weatherMan.wind.strength < 0.7) && speed < 0.3) {
  69.             speed = 0D;
  70.         }
  71.        
  72.         ent.motionX += speed*(double)(-MathHelper.sin(weatherMan.wind.direction / 180.0F * 3.1415927F) * MathHelper.cos(weatherMan.wind.yDirection / 180.0F * 3.1415927F));
  73.         ent.motionZ += speed*(double)(MathHelper.cos(weatherMan.wind.direction / 180.0F * 3.1415927F) * MathHelper.cos(weatherMan.wind.yDirection / 180.0F * 3.1415927F));
  74.         ent.motionY += weatherMan.wind.yStrength*0.1D*(double)(-MathHelper.sin((weatherMan.wind.yDirection) / 180.0F * 3.1415927F));
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement