Advertisement
hassansyyid

KeyInputHandler

Jul 5th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 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.                 } else {
  50.                     mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " This is not a weapon or does not have a scope."));
  51.                 }
  52.             } else {
  53.                 mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " You're not holding anything!"));
  54.             }
  55.         } else if (KeyBindings.fire.isPressed()) {
  56.             if (isThirdRiderOfWarthog(mc.thePlayer, mc.theWorld)) {
  57.                 fire = 3;
  58.                 HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  59.                 System.out.println("Tried to fire");
  60.             }
  61.             if (mc.thePlayer.isRiding()) {
  62.                 Entity ridingEntity = mc.thePlayer.ridingEntity;
  63.                 if (ridingEntity instanceof EntityScorpion) {
  64.                     fire = 1;
  65.                     HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  66.                 } else if (ridingEntity instanceof EntityGhost) {
  67.                     fire = 2;
  68.                     HalocraftPacketHandler.INSTANCE.sendToServer(new FireMessage(fire));
  69.                 } else {
  70.                     mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " This is not a Scorpion!"));
  71.                 }
  72.             } else {
  73.                 mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + "[HaloCraft 2.0]" + EnumChatFormatting.RED + " You're not riding anything!"));
  74.             }
  75.  
  76.         } else {
  77.             keyPressed = false;
  78.         }
  79.     }
  80.  
  81.     public boolean isThirdRiderOfWarthog(EntityPlayerSP thePlayer,
  82.     WorldClient theWorld) {
  83.         List < EntityWarthogTurret > entities = theWorld.getEntitiesWithinAABB(EntityWarthogTurret.class, thePlayer.getBoundingBox().expand(4, 4, 4));
  84.         if (entities != null) {
  85.             for (EntityWarthogTurret e: entities) {
  86.                 if (e.thirdRider == thePlayer) {
  87.                     return true;
  88.                 }
  89.             }
  90.         }
  91.         System.out.println("I can't find the warthog!");
  92.         return false;
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement