public S1CPacketEntityMetadata(int p_i45217_1_, DataWatcher p_i45217_2_, boolean p_i45217_3_) {
   this.field_149379_a = p_i45217_1_;
   if (p_i45217_3_) {
     this.field_149378_b = p_i45217_2_.func_75685_c();
   } else {
     this.field_149378_b = p_i45217_2_.func_75688_b();
   }
 }
  @Override
  @SideOnly(Side.CLIENT)
  public ModelBiped getArmorModel(
      EntityLivingBase entityLiving, ItemStack itemStack, int armorSlot) {

    ModelBackBokken armorModel = null;
    if (itemStack != null) {
      if (itemStack.getItem() instanceof ItemArmourKatana) {
        int type = ((ItemArmor) itemStack.getItem()).armorType;

        if (type == 1) {
          armorModel = new ModelBackBokken();
          DataWatcher dw = entityLiving.getDataWatcher();
          armorModel.animationID = dw.getWatchableObjectString(20);
          armorModel.animationlastID = dw.getWatchableObjectString(26);
          armorModel.animationTick = dw.getWatchableObjectFloat(25);
        }
      }
    }
    if (entityLiving.getHeldItem() != null) {
      // armorModel.blade.isHidden = true;
      // armorModel.blade.isHidden = false;
      armorModel.handle.isHidden = entityLiving.getHeldItem().getItem() == NarutoItems.Katana;
    } else {
      // armorModel.blade.isHidden = false;
      armorModel.handle.isHidden = false;
    }

    if (armorModel != null) {
      armorModel.bipedBody.showModel = armorSlot == 1;

      armorModel.isSneak = entityLiving.isSneaking();
      armorModel.isRiding = entityLiving.isRiding();
      armorModel.isChild = entityLiving.isChild();
      armorModel.heldItemRight = entityLiving.getEquipmentInSlot(0) != null ? 1 : 0;
      armorModel.isSprinting = entityLiving.isSprinting();
      if (entityLiving instanceof EntityPlayer) {
        EntityPlayer entityPlayer = (EntityPlayer) entityLiving;
        if (itemStack != null && entityPlayer.getItemInUseCount() > 0) {
          EnumAction enumaction = itemStack.getItemUseAction();

          if (enumaction == EnumAction.block) {
            armorModel.heldItemRight = 3;
          } else if (enumaction == EnumAction.bow) {
            armorModel.aimedBow = true;
          } else if (enumaction == NarutoItems.Throw) {
            if (FMLClientHandler.instance().getClient().thePlayer == entityPlayer) {
              armorModel.isClientThrowing = true;
            } else {
              armorModel.isThrowing = true;
            }
          }
        }
      }
    }

    return armorModel;
  }
  /**
   * ■対象EntityのDataWatcherについてる傷を取得
   *
   * @param dwIn
   * @return
   */
  public int getHitCount(DataWatcher dwIn) {
    int countHit = 0;
    try {
      // ■情報が刻まれているなら値を取得できる
      countHit = dwIn.getWatchableObjectInt(Hizume.getDWID());
    } catch (NullPointerException e) {
      // ■初物
      dwIn.addObject(Hizume.getDWID(), Integer.valueOf(0));
    }

    return countHit;
  }
  /**
   * ■対象Entityに傷を指定数つける
   *
   * @param dwIn
   * @param countHit
   */
  public void setHitCount(DataWatcher dwIn, int countHit) {
    // ■確認用
    getHitCount(dwIn);

    // ■設定
    dwIn.updateObject(Hizume.getDWID(), MathHelper.clamp_int(countHit, 0, Integer.MAX_VALUE - 1));
  }
  /**
   * Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
   * return value is true further processing is canceled and the entity is not attacked.
   * ■左クリックでEntityを殴ると呼ばれる。 (return : 相手にダメージを [true = 与えない : false = 与える])
   *
   * @param stack The Item being used
   * @param player The player that is attacking
   * @param entity The entity being attacked
   * @return True to cancel the rest of the interaction.
   */
  @Override
  public boolean onLeftClickEntity(ItemStack stackIn, EntityPlayer player, Entity entity) {
    // ■相手に傷をつける(DataWatcherに情報を刻む)
    if (entity instanceof EntityDragonPart) {
      // ■DragonPartからDragonを取得
      entity = (Entity) ((EntityDragonPart) entity).entityDragonObj;
    }
    DataWatcher dw = entity.getDataWatcher();

    int countHit = getHitCount(dw);

    // ■情報を刻む
    dw.updateObject(Hizume.getDWID(), ++countHit);

    // TODO
    if (!player.worldObj.isRemote) {
      // System.out.println("Entity = " + entity.getName() + " : Scars!");
    }

    return false;
  }
Example #6
0
  /** also sends velocity, rotation, and riding info. */
  public void sendLocationToAllClients(List par1List) {
    this.playerEntitiesUpdated = false;

    if (!this.isDataInitialized
        || this.myEntity.getDistanceSq(this.posX, this.posY, this.posZ) > 16.0D) {
      this.posX = this.myEntity.posX;
      this.posY = this.myEntity.posY;
      this.posZ = this.myEntity.posZ;
      this.isDataInitialized = true;
      this.playerEntitiesUpdated = true;
      this.sendEventsToPlayers(par1List);
    }

    if (this.field_85178_v != this.myEntity.ridingEntity) {
      this.field_85178_v = this.myEntity.ridingEntity;
      this.sendPacketToAllTrackingPlayers(
          new Packet39AttachEntity(this.myEntity, this.myEntity.ridingEntity));
    }

    if (this.myEntity instanceof EntityItemFrame && this.ticks % 10 == 0) {
      EntityItemFrame var23 = (EntityItemFrame) this.myEntity;
      ItemStack var24 = var23.getDisplayedItem();

      if (var24 != null && var24.getItem() instanceof ItemMap) {
        MapData var26 = Item.map.getMapData(var24, this.myEntity.worldObj);
        Iterator var29 = par1List.iterator();

        while (var29.hasNext()) {
          EntityPlayer var30 = (EntityPlayer) var29.next();
          EntityPlayerMP var31 = (EntityPlayerMP) var30;
          var26.updateVisiblePlayers(var31, var24);

          if (var31.playerNetServerHandler.packetSize() <= 5) {
            Packet var32 = Item.map.createMapDataPacket(var24, this.myEntity.worldObj, var31);

            if (var32 != null) {
              var31.playerNetServerHandler.sendPacketToPlayer(var32);
            }
          }
        }
      }

      DataWatcher var28 = this.myEntity.getDataWatcher();

      if (var28.hasChanges()) {
        this.sendPacketToAllAssociatedPlayers(
            new Packet40EntityMetadata(this.myEntity.entityId, var28, false));
      }
    } else if (this.ticks++ % this.updateFrequency == 0 || this.myEntity.isAirBorne) {
      int var2;
      int var3;

      if (this.myEntity.ridingEntity == null) {
        ++this.ticksSinceLastForcedTeleport;
        var2 = this.myEntity.myEntitySize.multiplyBy32AndRound(this.myEntity.posX);
        var3 = MathHelper.floor_double(this.myEntity.posY * 32.0D);
        int var4 = this.myEntity.myEntitySize.multiplyBy32AndRound(this.myEntity.posZ);
        int var5 = MathHelper.floor_float(this.myEntity.rotationYaw * 256.0F / 360.0F);
        int var6 = MathHelper.floor_float(this.myEntity.rotationPitch * 256.0F / 360.0F);
        int var7 = var2 - this.lastScaledXPosition;
        int var8 = var3 - this.lastScaledYPosition;
        int var9 = var4 - this.lastScaledZPosition;
        Object var10 = null;
        boolean var11 =
            Math.abs(var7) >= 4
                || Math.abs(var8) >= 4
                || Math.abs(var9) >= 4
                || this.ticks % 60 == 0;
        boolean var12 = Math.abs(var5 - this.lastYaw) >= 4 || Math.abs(var6 - this.lastPitch) >= 4;

        if (var7 >= -128
            && var7 < 128
            && var8 >= -128
            && var8 < 128
            && var9 >= -128
            && var9 < 128
            && this.ticksSinceLastForcedTeleport <= 400
            && !this.ridingEntity) {
          if (var11 && var12) {
            var10 =
                new Packet33RelEntityMoveLook(
                    this.myEntity.entityId,
                    (byte) var7,
                    (byte) var8,
                    (byte) var9,
                    (byte) var5,
                    (byte) var6);
          } else if (var11) {
            var10 =
                new Packet31RelEntityMove(
                    this.myEntity.entityId, (byte) var7, (byte) var8, (byte) var9);
          } else if (var12) {
            var10 = new Packet32EntityLook(this.myEntity.entityId, (byte) var5, (byte) var6);
          }
        } else {
          this.ticksSinceLastForcedTeleport = 0;
          var10 =
              new Packet34EntityTeleport(
                  this.myEntity.entityId, var2, var3, var4, (byte) var5, (byte) var6);
        }

        if (this.sendVelocityUpdates) {
          double var13 = this.myEntity.motionX - this.motionX;
          double var15 = this.myEntity.motionY - this.motionY;
          double var17 = this.myEntity.motionZ - this.motionZ;
          double var19 = 0.02D;
          double var21 = var13 * var13 + var15 * var15 + var17 * var17;

          if (var21 > var19 * var19
              || var21 > 0.0D
                  && this.myEntity.motionX == 0.0D
                  && this.myEntity.motionY == 0.0D
                  && this.myEntity.motionZ == 0.0D) {
            this.motionX = this.myEntity.motionX;
            this.motionY = this.myEntity.motionY;
            this.motionZ = this.myEntity.motionZ;
            this.sendPacketToAllTrackingPlayers(
                new Packet28EntityVelocity(
                    this.myEntity.entityId, this.motionX, this.motionY, this.motionZ));
          }
        }

        if (var10 != null) {
          this.sendPacketToAllTrackingPlayers((Packet) var10);
        }

        DataWatcher var33 = this.myEntity.getDataWatcher();

        if (var33.hasChanges()) {
          this.sendPacketToAllAssociatedPlayers(
              new Packet40EntityMetadata(this.myEntity.entityId, var33, false));
        }

        if (var11) {
          this.lastScaledXPosition = var2;
          this.lastScaledYPosition = var3;
          this.lastScaledZPosition = var4;
        }

        if (var12) {
          this.lastYaw = var5;
          this.lastPitch = var6;
        }

        this.ridingEntity = false;
      } else {
        var2 = MathHelper.floor_float(this.myEntity.rotationYaw * 256.0F / 360.0F);
        var3 = MathHelper.floor_float(this.myEntity.rotationPitch * 256.0F / 360.0F);
        boolean var25 = Math.abs(var2 - this.lastYaw) >= 4 || Math.abs(var3 - this.lastPitch) >= 4;

        if (var25) {
          this.sendPacketToAllTrackingPlayers(
              new Packet32EntityLook(this.myEntity.entityId, (byte) var2, (byte) var3));
          this.lastYaw = var2;
          this.lastPitch = var3;
        }

        this.lastScaledXPosition =
            this.myEntity.myEntitySize.multiplyBy32AndRound(this.myEntity.posX);
        this.lastScaledYPosition = MathHelper.floor_double(this.myEntity.posY * 32.0D);
        this.lastScaledZPosition =
            this.myEntity.myEntitySize.multiplyBy32AndRound(this.myEntity.posZ);
        DataWatcher var27 = this.myEntity.getDataWatcher();

        if (var27.hasChanges()) {
          this.sendPacketToAllAssociatedPlayers(
              new Packet40EntityMetadata(this.myEntity.entityId, var27, false));
        }

        this.ridingEntity = true;
      }

      var2 = MathHelper.floor_float(this.myEntity.setRotationYawHead() * 256.0F / 360.0F);

      if (Math.abs(var2 - this.lastHeadMotion) >= 4) {
        this.sendPacketToAllTrackingPlayers(
            new Packet35EntityHeadRotation(this.myEntity.entityId, (byte) var2));
        this.lastHeadMotion = var2;
      }

      this.myEntity.isAirBorne = false;
    }

    if (this.myEntity.velocityChanged) {
      this.sendPacketToAllAssociatedPlayers(new Packet28EntityVelocity(this.myEntity));
      this.myEntity.velocityChanged = false;
    }
  }
 public void func_148840_b(PacketBuffer p_148840_1_) throws IOException {
   p_148840_1_.func_150787_b(this.field_149379_a);
   DataWatcher.func_151507_a(this.field_149378_b, p_148840_1_);
 }
 public void func_148837_a(PacketBuffer p_148837_1_) throws IOException {
   this.field_149379_a = p_148837_1_.func_150792_a();
   this.field_149378_b = DataWatcher.func_151508_b(p_148837_1_);
 }