Advertisement
hassansyyid

KeyInputHandler

Jul 5th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.97 KB | None | 0 0
  1. package halocraft.handlers;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataOutputStream;
  5. import java.util.List;
  6.  
  7. import halocraft.KeyBindings;
  8. import halocraft.Main;
  9. import halocraft.entities.EntityGhost;
  10. import halocraft.entities.EntityMongoose;
  11. import halocraft.entities.EntityRocket;
  12. import halocraft.entities.EntityScorpion;
  13. import halocraft.entities.EntityWarthogTurret;
  14. import halocraft.items.ItemBattleRifle;
  15. import halocraft.items.ItemSniperRifle;
  16. import halocraft.packets.FireMessage;
  17. import halocraft.packets.HalocraftPacketHandler;
  18.  
  19. import org.lwjgl.opengl.GL11;
  20.  
  21. import net.minecraft.client.Minecraft;
  22. import net.minecraft.client.entity.EntityPlayerSP;
  23. import net.minecraft.client.multiplayer.WorldClient;
  24. import net.minecraft.client.renderer.Tessellator;
  25. import net.minecraft.client.renderer.WorldRenderer;
  26. import net.minecraft.entity.Entity;
  27. import net.minecraft.entity.player.EntityPlayer;
  28. import net.minecraft.util.ChatComponentText;
  29. import net.minecraft.util.EnumChatFormatting;
  30. import net.minecraft.util.ResourceLocation;
  31. import net.minecraft.world.World;
  32. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  33. import net.minecraftforge.fml.common.gameevent.InputEvent;
  34.  
  35. public class KeyInputHandler{
  36.     private Minecraft mc = Minecraft.getMinecraft();
  37.     World worldIn = mc.theWorld;
  38.     EntityPlayer playerIn = mc.thePlayer;
  39.     public static boolean keyPressed = false;
  40.     public static int fire = 0;
  41.    
  42.     @SubscribeEvent
  43.     public void onKeyInput(InputEvent.KeyInputEvent event) {
  44.         if(KeyBindings.scope.isPressed()){
  45.             if(mc.thePlayer.getHeldItem() != null){
  46.                 if(mc.thePlayer.getHeldItem().getItem() == ItemBattleRifle.instance || mc.thePlayer.getHeldItem().getItem() == ItemSniperRifle.instance){
  47.                     keyPressed = true;
  48.  
  49.                 }
  50.                 else{
  51.                     mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " This is not a weapon or does not have a scope."));
  52.                 }
  53.             }
  54.             else{
  55.                 mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " You're not holding anything!"));
  56.             }
  57.         }
  58.         else if(KeyBindings.fire.isPressed()){
  59.             if(isThirdRiderOfWarthog(mc.thePlayer, mc.theWorld))
  60.             {
  61.                 fire = 3;
  62.                 HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  63.                 System.out.println("Tried to fire");
  64.             }
  65.             if(mc.thePlayer.isRiding())
  66.             {
  67.                 Entity ridingEntity = mc.thePlayer.ridingEntity;
  68.                 if(ridingEntity instanceof EntityScorpion){
  69.                     fire = 1;
  70.                     HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  71.                 }
  72.                 else if(ridingEntity instanceof EntityGhost)
  73.                 {
  74.                     fire = 2;
  75.                     HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  76.                 }
  77.                 else{
  78.                     mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " This is not a Scorpion!"));
  79.                 }
  80.             }
  81.             else{
  82.                 mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " You're not riding anything!"));
  83.             }
  84.            
  85.         }
  86.         else{
  87.             keyPressed = false;
  88.         }
  89.     }
  90.  
  91.     public boolean isThirdRiderOfWarthog(EntityPlayerSP thePlayer,
  92.             WorldClient theWorld) {
  93.         try
  94.         {
  95.             List<EntityWarthogTurret> entities = theWorld.getEntitiesWithinAABB(EntityWarthogTurret.class, thePlayer.getBoundingBox().expand(4, 4, 4));
  96.             for(EntityWarthogTurret e : entities)
  97.             {
  98.                 if(e.thirdRider == thePlayer)
  99.                 {
  100.                     return true;
  101.                 }
  102.             }
  103.         }
  104.         catch(NullPointerException e)
  105.         {
  106.             System.out.println("I can't find the warthog!");
  107.         }
  108.         System.out.println("I can't find the warthog!");
  109.         return false;
  110.     }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement