Advertisement
LostKitty

Make it rain 100 Spiders

May 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.77 KB | None | 0 0
  1. //First you will have to left click the ground while holding a block of any type
  2. //Then you will have to also make sure there is an arrow that is moving that has entered the world but then stopped moving.
  3. //When that happens the spiders will rain
  4.         //Since this is linked to arrows any moving entity Arrow in minecraft that stops moving (aka hits something) will cause
  5.             //100 spiders to rain.
  6.             //Swapping the name EntitySpider with say EntityCreeper, or another Entity will change what happens
  7.                 //For some reason in my test build it works but crashes really hard when triggered wonder why? maybe too many
  8.                     //Entities at once? LOL did this with TNT already but for TNT a few more params are required and I didn't show it
  9.  
  10.  
  11. package com.example.examplemod;
  12. import java.util.Random;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.EntityCreature;
  15. import net.minecraft.entity.item.EntityTNTPrimed;
  16. import net.minecraft.entity.monster.EntityCreeper;
  17. import net.minecraft.entity.monster.EntitySpider;
  18. import net.minecraft.entity.projectile.EntityArrow;
  19. import net.minecraft.entity.projectile.EntitySpectralArrow;
  20. import net.minecraft.item.Item;
  21. import com.forgeessentials.core.ForgeEssentials;
  22. import net.minecraft.block.Block;
  23. import net.minecraft.block.BlockDirt;
  24. import net.minecraft.world.World;
  25. import com.sun.istack.internal.Nullable;
  26. import net.minecraft.block.state.IBlockState;
  27. import net.minecraft.entity.player.EntityPlayer;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.util.EnumFacing;
  30. import net.minecraft.util.EnumHand;
  31. import net.minecraft.util.ITickable;
  32. import net.minecraft.util.math.BlockPos;
  33. import net.minecraft.world.World;
  34. import net.minecraftforge.common.MinecraftForge;
  35. import net.minecraftforge.event.AttachCapabilitiesEvent;
  36. import net.minecraftforge.event.entity.EntityJoinWorldEvent;
  37. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  38. import net.minecraftforge.fml.common.Mod;
  39. import net.minecraftforge.fml.common.Mod.EventHandler;
  40. import net.minecraftforge.fml.common.SidedProxy;
  41. import net.minecraftforge.fml.common.WorldAccessContainer;
  42. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  43. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  44. import net.minecraftforge.fml.common.gameevent.TickEvent;
  45.  
  46.  
  47. import java.util.ArrayList;
  48. import java.util.EnumSet;
  49. import java.util.List;
  50.  
  51. @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
  52. public class ExampleMod {
  53.     public static final String MODID = "examplemod";
  54.     public static final String VERSION = "1.0";
  55.     public List<Entity> entitylist = new ArrayList<Entity>();
  56.     public net.minecraft.entity.player.EntityPlayer thisplayer;
  57.  
  58.  
  59.     @EventHandler
  60.     public void init(FMLInitializationEvent event) {
  61.         // some example code
  62.         //System.out.println("DIRT BLOCK >> "+Blocks.DIRT.getUnlocalizedName());
  63.         //MinecraftForge.EVENT_BUS.register(this);
  64.         MinecraftForge.EVENT_BUS.register(this);
  65.     }
  66.  
  67.  
  68.     @SubscribeEvent
  69.     public void leftClickBlock(PlayerInteractEvent.LeftClickBlock evt) {
  70.  
  71.         if (evt.getItemStack() != null) {
  72.             EntityTNTPrimed entity;
  73.             net.minecraft.entity.player.EntityPlayer player;
  74.             net.minecraft.world.World world;
  75.             player = evt.getEntityPlayer();
  76.             world = evt.getWorld();
  77.  
  78.             //entity = new EntityTNTPrimed(world, player.posX, player.posY, player.posZ, player);
  79.             //world.spawnEntityInWorld(entity);
  80.  
  81.             System.out.println(evt.getItemStack().getDisplayName().toString());
  82.             thisplayer = player;
  83.         }
  84.  
  85.         if (evt.getItemStack() == null) {
  86.             System.out.println("You don't have anything in hand");
  87.  
  88.         }
  89.  
  90.         // When item use denied, the event will keep firing as long as the left click button is held.
  91.         // This is due to how vanilla calls the left click handling methods to let people not lift their button when mining multiple blocks.
  92.         // Note that when item use is denied, the cool down for the item does not occur. This is good!
  93.     }
  94.  
  95.     @SubscribeEvent
  96.     public void ArrowJoins(EntityJoinWorldEvent evt) {
  97.  
  98.         if (evt.getEntity() instanceof EntityArrow) {
  99.             System.out.println("An arrow entered the world");
  100.             if (!evt.getEntity().isDead) {
  101.                 entitylist.add(evt.getEntity());
  102.  
  103.  
  104.             }
  105.         }
  106.  
  107.     }
  108.  
  109.     @SubscribeEvent
  110.     public void tickupdate(TickEvent evt) {
  111.         Random myrandomgen = new Random();
  112.  
  113.  
  114.         for (Entity ee : entitylist) {
  115.             boolean ground = false;
  116.  
  117.  
  118.             if (!ee.isDead) {
  119.  
  120.                 double lastposx = ee.lastTickPosX;
  121.                 double lastposy = ee.lastTickPosY;
  122.                 double lastposz = ee.lastTickPosZ;
  123.  
  124.                 double currentx = ee.posX;
  125.                 double currenty = ee.posY;
  126.                 double currentz = ee.posZ;
  127.                 double diffx = 0;
  128.                 double diffy = 0;
  129.                 double diffz = 0;
  130.                 boolean differencemajor = false;
  131.  
  132.                 //Get difference in X since last Tick
  133.                 if (lastposx > currentx) {
  134.                     diffx = lastposx - currentx;
  135.                 }
  136.                 if (currentx > lastposx) {
  137.                     diffx = currentx - lastposx;
  138.                 }
  139.  
  140.                 //Get difference in Y since last Tick
  141.                 if (lastposy > currenty) {
  142.                     diffy = lastposy - currenty;
  143.                 }
  144.                 if (currenty > lastposy) {
  145.                     diffy = currenty - lastposy;
  146.                 }
  147.                 //Get difference in Z since last Tick
  148.                 if (lastposz > currentz) {
  149.                     diffz = lastposz - currentz;
  150.                 }
  151.                 if (currentz > lastposz) {
  152.                     diffz = currentz - lastposz;
  153.                 }
  154.  
  155.                 if (diffx < 1) {
  156.                     if (diffy < 1) {
  157.                         if (diffz < 1) {
  158.                             differencemajor = true;
  159.                         }
  160.                     }
  161.  
  162.                 }
  163.  
  164.  
  165.                 if (thisplayer != null) {
  166.                     if (thisplayer.getEntityWorld().isRemote == false) {
  167.                         if (differencemajor == true) {
  168.                             EntitySpider tntentity;
  169.                             net.minecraft.entity.Entity thisarrow;
  170.                             net.minecraft.world.World world;
  171.                             world = ee.getEntityWorld();
  172.                             thisarrow = ee;
  173.  
  174.                             tntentity = new EntitySpider(thisplayer.getEntityWorld());
  175.                             tntentity.setLocationAndAngles(ee.posX, ee.posY, ee.posZ, 0, 0);
  176.                             world.spawnEntityInWorld(tntentity);
  177.  
  178.                             for (int a=1;a<300;a++){
  179.                                 int posx = myrandomgen.nextInt(200);
  180.                                 int posy = myrandomgen.nextInt(30);
  181.                                 int posz = myrandomgen.nextInt(200);
  182.  
  183.                                 double newx = (double)posx + ee.posX;
  184.                                 double newy = (double)posy + ee.posY;
  185.                                 double newz = (double)posz + ee.posZ;
  186.                                 tntentity = new EntitySpider(thisplayer.getEntityWorld());
  187.                                 tntentity.setLocationAndAngles(newx, newy, newz, 0, 0);
  188.                                 world.spawnEntityInWorld(tntentity);
  189.  
  190.  
  191.  
  192.  
  193.  
  194.                             }
  195.  
  196.  
  197.  
  198.                             ee.setDead();
  199.                         }
  200.                     }
  201.                 }
  202.  
  203.  
  204.             }
  205.         }
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement