Advertisement
Guest User

It works

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