@Override
  public IMessage onMessage(PacketKurosawaAttack message, MessageContext ctx) {
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    Kurosawa item = (Kurosawa) player.getHeldItem().getItem();

    if (!item.getCooldown()) {
      World world = player.worldObj;
      EntityLivingBase target = (EntityLivingBase) world.getEntityByID(message.targetID);
      Vec3 targetPos = target.getPositionVector();
      Vec3 attackerPos = player.getPositionVector();

      Vec3 distance = targetPos.subtractReverse(attackerPos).normalize();
      distance = new Vec3(distance.xCoord * 3, distance.yCoord * 3, distance.zCoord * 3);

      player.setPositionAndRotation(
          target.posX - distance.xCoord,
          target.posY - distance.yCoord,
          target.posZ - distance.zCoord,
          player.rotationYaw + 180,
          player.rotationPitch);
      player.setRotationYawHead(player.rotationYawHead + 180);
      player.cameraPitch += 180;
      player.setPositionAndUpdate(
          target.posX - distance.xCoord,
          target.posY - distance.yCoord,
          target.posZ - distance.zCoord);
      target.attackEntityFrom(DamageSource.causePlayerDamage(player), 44);
      item.setCooldown();
    }
    return null;
  }
  public void handlePacket(Packet250CustomPayload packet) throws IOException {

    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data));

    byte type = dis.readByte();

    World world = net.minecraft.client.Minecraft.getMinecraft().theWorld;

    ISyncHandler handler = null;

    if (type == TYPE_TILE) {
      int x = dis.readInt();
      int y = dis.readInt();
      int z = dis.readInt();
      if (world != null) {
        if (world.blockExists(x, y, z)) {
          TileEntity tile = world.getBlockTileEntity(x, y, z);
          if (tile instanceof ISyncHandler) {
            handler = (ISyncHandler) tile;
          }
        }
      }
    } else if (type == TYPE_ENTITY) {
      int entityId = dis.readInt();
      Entity entity = world.getEntityByID(entityId);
      if (entity != null && entity instanceof ISyncHandler) {
        handler = (ISyncHandler) entity;
      }
    }
    if (handler != null) {
      List<ISyncableObject> changes = handler.getSyncMap().readFromStream(dis);
      handler.onSynced(changes);
    }
    dis.close();
  }
 @Override
 public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
   switch (ID) {
     case NPC:
       return new GuiNPC((EntityNPC) world.getEntityByID(x), player);
     case SHOP:
       return new GuiNPCShop((EntityNPC) world.getEntityByID(x), player);
     case SHOP_BUILDER:
       return new GuiNPCBuilderShop((EntityNPC) world.getEntityByID(x), player);
     case GIFT:
       return new GuiNPCGift((EntityNPC) world.getEntityByID(x), player);
     case FRIDGE:
       return new GuiFridge(player.inventory, HFTrackers.getClientPlayerTracker().getFridge());
     default:
       return null;
   }
 }
 @Override
 public MessageUpdateTrackLocation onMessage(
     MessageUpdateTrackLocation message, MessageContext ctx) {
   World world = Minecraft.getMinecraft().theWorld;
   if (world == null) return null;
   Entity ent = world.getEntityByID(entityID);
   if (ent == null || !(ent instanceof EntityGenericRollingStock)) return null;
   EntityGenericRollingStock stock = (EntityGenericRollingStock) ent;
   stock.recieveMessageUpdateTrackLocation(message.componentID, message.ident, message.progress);
   return null;
 }
    @Override
    public IMessage onMessage(StringPacket message, MessageContext ctx) {
      World world = DimensionManager.getWorld(message.targetPos[0]);

      if (message.targetType == Syncer.TargetType.Entity) {
        Entity target = world.getEntityByID(message.targetPos[1]);
        IStringSyncer is = (IStringSyncer) target;
        is.setStringData(message.data);
      } else if (message.targetType == Syncer.TargetType.TileEntity) {
        TileEntity target =
            world.getTileEntity(
                new BlockPos(message.targetPos[1], message.targetPos[2], message.targetPos[3]));
        IStringSyncer is = (IStringSyncer) target;
        is.setStringData(message.data);
      }

      return null;
    }
  private void handleRocketJumpHackyPacket(ByteBufInputStream dat, World world) {
    try {
      int id = dat.readInt();
      EntityPlayer player = (EntityPlayer) world.getEntityByID(id);
      if (player != null) {
        double motionX = dat.readDouble();
        double motionY = dat.readDouble();
        double motionZ = dat.readDouble();

        Minecraft.getMinecraft().thePlayer.motionX += motionX;
        Minecraft.getMinecraft().thePlayer.motionY += motionY;
        Minecraft.getMinecraft().thePlayer.motionZ += motionZ;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }
  @Override
  public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    if (id != -1) {
      if (id < 0 || id >= OpenBlocks.GUIS.length) {
        Log.warn("Invalid GUI id: %d", id);
        return null;
      }

      GuiId guiId = OpenBlocks.GUIS[id];
      if (guiId == OpenBlocks.GuiId.luggage)
        return new ContainerLuggage(player.inventory, (EntityLuggage) world.getEntityByID(x));
    } else {
      TileEntity tile = world.getBlockTileEntity(x, y, z);
      if (tile instanceof IHasGui) {
        return ((IHasGui) tile).getServerGui(player);
      }
    }
    return null;
  }
    @Override
    @SideOnly(Side.CLIENT)
    public IMessage onMessage(StringPacket message, MessageContext ctx) {
      World world = Minecraft.getMinecraft().theWorld;
      if (world.provider.getDimension() != message.targetPos[0]) return null;

      if (message.targetType == Syncer.TargetType.Entity) {
        Entity target = world.getEntityByID(message.targetPos[1]);
        IStringSyncer is = (IStringSyncer) target;
        is.setStringData(message.data);
      } else if (message.targetType == Syncer.TargetType.TileEntity) {
        TileEntity target =
            world.getTileEntity(
                new BlockPos(message.targetPos[1], message.targetPos[2], message.targetPos[3]));
        IStringSyncer is = (IStringSyncer) target;
        is.setStringData(message.data);
      }

      return null;
    }
  // returns an instance of the Container
  @Override
  public Object getServerGuiElement(
      int guiID, EntityPlayer player, World world, int x, int y, int z) {
    if (guiID == ModRedstoneJukebox.redstoneJukeboxGuiID) {
      TileEntityRedstoneJukebox teJukebox =
          (TileEntityRedstoneJukebox) world.getBlockTileEntity(x, y, z);
      return new ContainerRedstoneJukebox(player.inventory, teJukebox);
    } else if (guiID == ModRedstoneJukebox.recordTradingGuiID) {
      // OBS: The X value is the EntityID - facepalm courtesy of
      // http://www.minecraftforge.net/forum/index.php?topic=1671.0
      // OBS 2: Not all villagers can trade records, so there is an extra condition.
      Entity villager = world.getEntityByID(x);
      if (villager instanceof EntityVillager && CustomRecordHelper.canTradeRecords(x)) {
        CustomRecordHelper.validateOffers(
            CustomRecordHelper.getStoreID(x)); // revalidates the offers before opening the GUI
        return new ContainerRecordTrading(player.inventory, (EntityVillager) villager, world);
      }
    }

    return null;
  }
 public Entity getEntityB(World world) {
   return world.getEntityByID(idB);
 }
 public Entity getEntityA(World world) {
   return world.getEntityByID(idA);
 }
示例#12
0
 @SideOnly(Side.CLIENT)
 public EntityPlayer func_149091_a(World p_149091_1_) {
   return (EntityPlayer) p_149091_1_.getEntityByID(this.field_149097_a);
 }