Advertisement
hassansyyid

Untitled

Jul 5th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. package halocraft.packets;
  2.  
  3. import java.util.List;
  4.  
  5. import halocraft.entities.EntityBullet;
  6. import halocraft.entities.EntityPurplePlasma;
  7. import halocraft.entities.EntityRocket;
  8. import halocraft.entities.EntityWarthogTurret;
  9. import net.minecraft.entity.player.EntityPlayerMP;
  10. import net.minecraft.util.BlockPos;
  11. import net.minecraft.util.Vec3;
  12. import net.minecraft.world.World;
  13. import net.minecraft.world.WorldServer;
  14. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  15. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  16. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  17.  
  18. public class FireMessageHandler implements IMessageHandler < FireMessage, IMessage > {
  19.  
  20.     @Override
  21.     public IMessage onMessage(FireMessage message, MessageContext ctx) {
  22.  
  23.         final EntityPlayerMP serverPlayerIn = ctx.getServerHandler().playerEntity;
  24.         final World worldIn = serverPlayerIn.worldObj;
  25.         WorldServer mainThread = (WorldServer)(serverPlayerIn.worldObj);
  26.  
  27.         // The value that was sent
  28.         int value = message.toSend;
  29.  
  30.         if (value == 1) {
  31.             mainThread.addScheduledTask(new Runnable() {@Override
  32.                 public void run() {
  33.                     worldIn.spawnEntityInWorld(new EntityRocket(worldIn, serverPlayerIn));
  34.                 }
  35.             });
  36.         } else if (value == 2) {
  37.             mainThread.addScheduledTask(new Runnable() {@Override
  38.                 public void run() {
  39.                     worldIn.spawnEntityInWorld(new EntityPurplePlasma(worldIn, serverPlayerIn));
  40.                 }
  41.             });
  42.         } else if (value == 3) {
  43.             mainThread.addScheduledTask(new Runnable() {@Override
  44.                 public void run() {
  45.                     if (isThirdRider(worldIn, serverPlayerIn)) {
  46.                         worldIn.spawnEntityInWorld(new EntityBullet(worldIn, serverPlayerIn));
  47.                     }
  48.                 }
  49.             });
  50.         }
  51.         return null;
  52.     }
  53.  
  54.     public boolean isThirdRider(World worldIn, EntityPlayerMP serverPlayerIn) {
  55.         List < EntityWarthogTurret > entities = worldIn.getEntitiesWithinAABB(EntityWarthogTurret.class, serverPlayerIn.getEntityBoundingBox().expand(4, 4, 4));
  56.         if (entities != null) {
  57.             for (EntityWarthogTurret e: entities) {
  58.                 if (e.thirdRider == serverPlayerIn) {
  59.                     return true;
  60.                 }
  61.             }
  62.         }
  63.         return false;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement