コード例 #1
0
  public boolean interact(
      World world,
      BlockPosition blockposition,
      IBlockData iblockdata,
      EntityHuman entityhuman,
      EnumHand enumhand,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    ItemStack itemstack = entityhuman.b(enumhand);

    if (!itemstack.isEmpty()
        && (itemstack.getItem() == Items.FLINT_AND_STEEL
            || itemstack.getItem() == Items.FIRE_CHARGE)) {
      this.a(
          world,
          blockposition,
          iblockdata.set(BlockTNT.EXPLODE, Boolean.valueOf(true)),
          (EntityLiving) entityhuman);
      world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 11);
      if (itemstack.getItem() == Items.FLINT_AND_STEEL) {
        itemstack.damage(1, entityhuman);
      } else if (!entityhuman.abilities.canInstantlyBuild) {
        itemstack.subtract(1);
      }

      return true;
    } else {
      return super.interact(
          world, blockposition, iblockdata, entityhuman, enumhand, enumdirection, f, f1, f2);
    }
  }
コード例 #2
0
ファイル: ItemHoe.java プロジェクト: fouram/mc-dev
  public boolean a(
      ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
    if (!entityhuman.c(i, j, k)) {
      return false;
    } else {
      int i1 = world.getTypeId(i, j, k);
      int j1 = world.getTypeId(i, j + 1, k);

      if ((l == 0 || j1 != 0 || i1 != Block.GRASS.id) && i1 != Block.DIRT.id) {
        return false;
      } else {
        Block block = Block.SOIL;

        world.makeSound(
            (double) ((float) i + 0.5F),
            (double) ((float) j + 0.5F),
            (double) ((float) k + 0.5F),
            block.stepSound.getName(),
            (block.stepSound.getVolume1() + 1.0F) / 2.0F,
            block.stepSound.getVolume2() * 0.8F);
        if (world.isStatic) {
          return true;
        } else {
          world.setTypeId(i, j, k, block.id);
          itemstack.damage(1, entityhuman);
          return true;
        }
      }
    }
  }
コード例 #3
0
  public boolean a(EntityHuman entityhuman) {
    ItemStack itemstack = entityhuman.inventory.getItemInHand();

    if (itemstack != null && itemstack.getItem() == Items.BOWL && this.getAge() >= 0) {
      if (itemstack.count == 1) {
        entityhuman.inventory.setItem(
            entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_STEW));
        return true;
      }

      if (entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_STEW))
          && !entityhuman.abilities.canInstantlyBuild) {
        entityhuman.inventory.splitStack(entityhuman.inventory.itemInHandIndex, 1);
        return true;
      }
    }

    if (itemstack != null && itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) {
      this.die();
      this.world.addParticle(
          EnumParticle.EXPLOSION_LARGE,
          this.locX,
          this.locY + (double) (this.length / 2.0F),
          this.locZ,
          0.0D,
          0.0D,
          0.0D,
          new int[0]);
      if (!this.world.isClientSide) {
        EntityCow entitycow = new EntityCow(this.world);

        entitycow.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
        entitycow.setHealth(this.getHealth());
        entitycow.aI = this.aI;
        if (this.hasCustomName()) {
          entitycow.setCustomName(this.getCustomName());
        }

        this.world.addEntity(entitycow);

        for (int i = 0; i < 5; ++i) {
          this.world.addEntity(
              new EntityItem(
                  this.world,
                  this.locX,
                  this.locY + (double) this.length,
                  this.locZ,
                  new ItemStack(Blocks.RED_MUSHROOM)));
        }

        itemstack.damage(1, entityhuman);
        this.makeSound("mob.sheep.shear", 1.0F, 1.0F);
      }

      return true;
    } else {
      return super.a(entityhuman);
    }
  }
コード例 #4
0
ファイル: EntityMySheep.java プロジェクト: EALS634/MyPet
  public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
      return true;
    }

    ItemStack itemStack = entityhuman.inventory.getItemInHand();

    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
      if (itemStack.getItem() == Items.DYE
          && itemStack.getData() <= 15
          && itemStack.getData() != getMyPet().getColor().getDyeData()
          && !getMyPet().isSheared()) {
        getMyPet().setColor(DyeColor.getByDyeData((byte) itemStack.getData()));
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        return true;
      } else if (itemStack.getItem() == Items.SHEARS
          && MySheep.CAN_BE_SHEARED
          && !getMyPet().isSheared()) {
        getMyPet().setSheared(true);
        int woolDropCount = 1 + this.random.nextInt(3);

        for (int j = 0; j < woolDropCount; ++j) {
          EntityItem entityitem =
              this.a(new ItemStack(Blocks.WOOL, 1, getMyPet().getColor().getDyeData()), 1.0F);

          entityitem.motY += (double) this.random.nextFloat() * 0.05F;
          entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
          entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
        }
        makeSound("mob.sheep.shear", 1.0F, 1.0F);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }
        return true;
      } else if (MySheep.GROW_UP_ITEM.compare(itemStack)
          && getMyPet().isBaby()
          && getOwner().getPlayer().isSneaking()) {
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        getMyPet().setBaby(false);
        return true;
      }
    }
    return false;
  }
コード例 #5
0
ファイル: ItemHoe.java プロジェクト: CasperGrey/MineCraft
 protected boolean a(
     ItemStack itemstack,
     EntityHuman entityhuman,
     World world,
     BlockPosition blockposition,
     IBlockData iblockdata) {
   world.makeSound(
       (double) ((float) blockposition.getX() + 0.5F),
       (double) ((float) blockposition.getY() + 0.5F),
       (double) ((float) blockposition.getZ() + 0.5F),
       iblockdata.getBlock().stepSound.getStepSound(),
       (iblockdata.getBlock().stepSound.getVolume1() + 1.0F) / 2.0F,
       iblockdata.getBlock().stepSound.getVolume2() * 0.8F);
   if (world.isClientSide) {
     return true;
   } else {
     world.setTypeUpdate(blockposition, iblockdata);
     itemstack.damage(1, entityhuman);
     return true;
   }
 }
コード例 #6
0
ファイル: EntityMyIronGolem.java プロジェクト: jjm223/MyPet
  public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
      return true;
    }

    ItemStack itemStack = entityhuman.inventory.getItemInHand();

    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
      if (itemStack.getItem() == Item.getItemOf(Blocks.RED_FLOWER)
          && !getMyPet().hasFlower()
          && getOwner().getPlayer().isSneaking()) {
        getMyPet().setFlower(CraftItemStack.asBukkitCopy(itemStack));
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        return true;
      } else if (itemStack.getItem() == Items.SHEARS
          && getMyPet().hasFlower()
          && getOwner().getPlayer().isSneaking()) {
        EntityItem entityitem = this.a(CraftItemStack.asNMSCopy(getMyPet().getFlower()), 1.0F);
        entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
        entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
        entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);

        makeSound("mob.sheep.shear", 1.0F, 1.0F);
        getMyPet().setFlower(null);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }

        return true;
      }
    }
    return false;
  }
コード例 #7
0
  @Override
  public boolean update() {
    EntityHuman passenger = (EntityHuman) this.getEntityHandle().passenger;
    EntityLiving entity = this.getEntityHandle();
    float f = MathHelper.g(passenger.yaw - entity.yaw) * 0.5f;

    if (f > 5) f = 5;

    if (f < -5) f = -5;

    entity.yaw = MathHelper.g(entity.yaw + f);
    if (this.m_currentSpeed < this.m_maxSpeed)
      this.m_currentSpeed += (this.m_maxSpeed - this.m_currentSpeed) * 0.01;

    if (this.m_currentSpeed > this.m_maxSpeed) this.m_currentSpeed = this.m_maxSpeed;

    int x = MathHelper.floor(entity.locX);
    int y = MathHelper.floor(entity.locY);
    int z = MathHelper.floor(entity.locZ);
    float speed = this.m_currentSpeed;

    if (this.m_speedBoosted) {
      if (this.m_speedBoostTime++ > this.m_maxSpeedBoostTime) this.m_speedBoosted = false;

      speed +=
          speed
              * 1.15
              * MathHelper.sin(
                  (float) (this.m_speedBoostTime / this.m_maxSpeedBoostTime * Math.PI));
    }

    float f2 = 0.91f;
    if (entity.onGround) {
      f2 = 0.54600006F;
      Block block = entity.world.getType(MathHelper.d(x), MathHelper.d(y) - 1, MathHelper.d(z));
      if (block.getMaterial() != Material.AIR) f2 = block.frictionFactor * 0.91f;
    }

    float f3 = 0.16277136F / (f2 * f2 * f2);
    float f4 = MathHelper.sin(entity.yaw * 3.1415927F / 180.0F);
    float f5 = MathHelper.cos(entity.yaw * 3.1415927F / 180.0F);
    float f6 = entity.bl() * f3;
    float f7 = Math.max(speed, 1.0F);

    f7 = f6 / f7;
    float f8 = speed * f7;
    float f9 = -(f8 * f4);
    float f10 = f8 * f5;

    if (MathHelper.abs(f9) > MathHelper.abs(f10)) {
      if (f9 < 0.0F) {
        f9 -= entity.width / 2.0F;
      }

      if (f9 > 0.0F) {
        f9 += entity.width / 2.0F;
      }

      f10 = 0.0F;
    } else {
      f9 = 0.0F;
      if (f10 < 0.0F) {
        f10 -= entity.width / 2.0F;
      }

      if (f10 > 0.0F) {
        f10 += entity.width / 2.0F;
      }
    }

    int nextX = MathHelper.floor(entity.locX + f9);
    int nextZ = MathHelper.floor(entity.locZ + f10);
    PathPoint point =
        new PathPoint(
            MathHelper.d(entity.width + 1),
            MathHelper.d(entity.length + passenger.length + 1),
            MathHelper.d(entity.width + 1));
    if (x != nextX || z != nextZ) {
      Block type1 = entity.world.getType(x, y, z);
      Block type2 = entity.world.getType(x, y - 1, z);
      boolean isStep = this.isStep(type1) || type1 == null && this.isStep(type2);

      if (!isStep
          && Pathfinder.a(entity, nextX, y, nextZ, point, false, false, true) == 0
          && Pathfinder.a(entity, x, y + 1, z, point, false, false, true) == 1
          && Pathfinder.a(entity, nextX, y + 1, nextZ, point, false, false, true) == 1)
        NMSUtil.getControllerLook(entity).a();
    }

    if (!passenger.abilities.canInstantlyBuild
        && this.m_currentSpeed >= this.m_maxSpeed * 0.5
        && entity.aI().nextFloat() < 0.006f
        && !this.m_speedBoosted) {
      ItemStack item = passenger.be();

      if (item != null && item.getItem() == Items.CARROT_STICK) {
        item.damage(1, passenger);
        if (item.count == 0) {
          ItemStack newItem = new ItemStack(Items.FISHING_ROD);
          newItem.setTag(item.tag);
          passenger.inventory.items[passenger.inventory.itemInHandIndex] = newItem;
        }
      }
    }

    entity.e(0, speed);
    return true;
  }