Advertisement
hassansyyid

Untitled

Jul 5th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 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.     EntityPlayerMP serverPlayerIn;
  20.     World worldIn;
  21.     @Override
  22.     public IMessage onMessage(FireMessage message, MessageContext ctx) {
  23.  
  24.         serverPlayerIn = ctx.getServerHandler().playerEntity;
  25.         worldIn = serverPlayerIn.worldObj;
  26.         WorldServer mainThread = (WorldServer)(serverPlayerIn.worldObj);
  27.  
  28.         // The value that was sent
  29.         int value = message.toSend;
  30.  
  31.         if (value == 1) {
  32.             mainThread.addScheduledTask(new Runnable() {@Override
  33.                 public void run() {
  34.                     if (!worldIn.isRemote) {
  35.                         worldIn.spawnEntityInWorld(new EntityRocket(worldIn, serverPlayerIn));
  36.                     }
  37.                 }
  38.             });
  39.         } else if (value == 2) {
  40.             mainThread.addScheduledTask(new Runnable() {@Override
  41.                 public void run() {
  42.                     if (!worldIn.isRemote) {
  43.                         worldIn.spawnEntityInWorld(new EntityPurplePlasma(worldIn, serverPlayerIn));
  44.                     }
  45.                 }
  46.             });
  47.         } else if (value == 3) {
  48.             if (isThirdRider()) {
  49.                 mainThread.addScheduledTask(new Runnable() {@Override
  50.                     public void run() {
  51.                         if (!worldIn.isRemote) {
  52.                             worldIn.spawnEntityInWorld(new EntityBullet(worldIn, serverPlayerIn));
  53.                         }
  54.                     }
  55.                 });
  56.             }
  57.         }
  58.         return null;
  59.     }
  60.  
  61.     public boolean isThirdRider() {
  62.         List < EntityWarthogTurret > entities = worldIn.getEntitiesWithinAABB(EntityWarthogTurret.class, serverPlayerIn.getEntityBoundingBox().expand(4, 4, 4));
  63.         if (entities != null) {
  64.             for (EntityWarthogTurret e: entities) {
  65.                 if (e.thirdRider == serverPlayerIn) {
  66.                     return true;
  67.                 }
  68.             }
  69.         }
  70.         return false;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement