Advertisement
LostKitty

Custom Mod stuff

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