private boolean func_150946_a(
      ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) {
    if (side == 0) y--;
    if (side == 1) y++;
    if (side == 2) z--;
    if (side == 3) z++;
    if (side == 4) x--;
    if (side == 5) x++;

    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block == field_150939_a && meta != 2) {
      if (world.checkNoEntityCollision(
              field_150939_a.getCollisionBoundingBoxFromPool(world, x, y, z))
          && world.setBlockMetadataWithNotify(x, y, z, 2, 3)) {
        world.playSoundEffect(
            x + 0.5F,
            y + 0.5F,
            z + 0.5F,
            field_150939_a.stepSound.func_150496_b(),
            (field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F,
            field_150939_a.stepSound.getPitch() * 0.8F);
        stack.stackSize--;
      }

      return true;
    } else return false;
  }
  /**
   * Callback for item usage. If the item does something special on right clicking, he will have one
   * of those. Return True if something happen and false if it don't. This is for ITEMS, not BLOCKS
   */
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    if (this.field_150948_b) {
      return super.onItemUse(
          par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
    } else if (par1ItemStack.stackSize == 0) {
      return false;
    } else if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)) {
      return false;
    } else {
      Block block = par3World.getBlock(par4, par5, par6);
      int i1 = par3World.getBlockMetadata(par4, par5, par6);
      int j1 = i1 & 7;
      boolean flag = (i1 & 8) != 0;

      if ((par7 == 1 && !flag || par7 == 0 && flag)
          && block == this.field_150949_c
          && j1 == par1ItemStack.getItemDamage()) {
        if (par3World.checkNoEntityCollision(
                this.field_150947_d.getCollisionBoundingBoxFromPool(par3World, par4, par5, par6))
            && par3World.setBlock(par4, par5, par6, this.field_150947_d, j1, 3)) {
          par3World.playSoundEffect(
              (double) ((float) par4 + 0.5F),
              (double) ((float) par5 + 0.5F),
              (double) ((float) par6 + 0.5F),
              this.field_150947_d.stepSound.func_150496_b(),
              (this.field_150947_d.stepSound.getVolume() + 1.0F) / 2.0F,
              this.field_150947_d.stepSound.getPitch() * 0.8F);
          --par1ItemStack.stackSize;
        }

        return true;
      } else {
        return this.func_150946_a(
                par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7)
            ? true
            : super.onItemUse(
                par1ItemStack,
                par2EntityPlayer,
                par3World,
                par4,
                par5,
                par6,
                par7,
                par8,
                par9,
                par10);
      }
    }
  }
  private boolean func_150946_a(
      ItemStack p_150946_1_,
      EntityPlayer p_150946_2_,
      World p_150946_3_,
      int p_150946_4_,
      int p_150946_5_,
      int p_150946_6_,
      int p_150946_7_) {
    if (p_150946_7_ == 0) {
      --p_150946_5_;
    }

    if (p_150946_7_ == 1) {
      ++p_150946_5_;
    }

    if (p_150946_7_ == 2) {
      --p_150946_6_;
    }

    if (p_150946_7_ == 3) {
      ++p_150946_6_;
    }

    if (p_150946_7_ == 4) {
      --p_150946_4_;
    }

    if (p_150946_7_ == 5) {
      ++p_150946_4_;
    }

    Block block = p_150946_3_.getBlock(p_150946_4_, p_150946_5_, p_150946_6_);
    int i1 = p_150946_3_.getBlockMetadata(p_150946_4_, p_150946_5_, p_150946_6_);
    int j1 = i1 & 7;

    if (block == this.field_150949_c && j1 == p_150946_1_.getItemDamage()) {
      if (p_150946_3_.checkNoEntityCollision(
              this.field_150947_d.getCollisionBoundingBoxFromPool(
                  p_150946_3_, p_150946_4_, p_150946_5_, p_150946_6_))
          && p_150946_3_.setBlock(
              p_150946_4_, p_150946_5_, p_150946_6_, this.field_150947_d, j1, 3)) {
        p_150946_3_.playSoundEffect(
            (double) ((float) p_150946_4_ + 0.5F),
            (double) ((float) p_150946_5_ + 0.5F),
            (double) ((float) p_150946_6_ + 0.5F),
            this.field_150947_d.stepSound.func_150496_b(),
            (this.field_150947_d.stepSound.getVolume() + 1.0F) / 2.0F,
            this.field_150947_d.stepSound.getPitch() * 0.8F);
        --p_150946_1_.stackSize;
      }

      return true;
    } else {
      return false;
    }
  }
  @Override
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      int x,
      int y,
      int z,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (stack.stackSize == 0) return false;
    else if (!player.canPlayerEdit(x, y, z, side, stack)) return false;
    else {
      Block block = world.getBlock(x, y, z);
      int meta = world.getBlockMetadata(x, y, z);
      boolean flag = meta == 1;

      if (block == field_150939_a && (side == 1 && !flag || side == 0 && flag)) {
        if (world.checkNoEntityCollision(
                field_150939_a.getCollisionBoundingBoxFromPool(world, x, y, z))
            && world.setBlock(x, y, z, field_150939_a, 2, 3)) {
          world.playSoundEffect(
              x + 0.5F,
              y + 0.5F,
              z + 0.5F,
              field_150939_a.stepSound.func_150496_b(),
              (field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F,
              field_150939_a.stepSound.getPitch() * 0.8F);
          stack.stackSize--;
        }

        return true;
      } else
        return func_150946_a(stack, player, world, x, y, z, side)
            ? true
            : super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
    }
  }
Exemple #5
0
  @Override
  public boolean onItemUse(
      ItemStack itemstack,
      EntityPlayer player,
      World world,
      int x,
      int y,
      int z,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {

    if (world.isRemote) {
      return true;
    }
    if (!containsSoul(itemstack)) {
      return false;
    }
    if (player == null) {
      return false;
    }

    Entity mob;
    NBTTagCompound root = itemstack.stackTagCompound;
    if (root.hasKey("isStub")) {
      String entityId = root.getString("id");
      mob = EntityList.createEntityByName(entityId, world);
    } else {
      mob = EntityList.createEntityFromNBT(root, world);
    }
    if (mob == null) {
      return true;
    }
    mob.readFromNBT(root);

    Block blk = world.getBlock(x, y, z);
    double spawnX = x + Facing.offsetsXForSide[side] + 0.5;
    double spawnY = y + Facing.offsetsYForSide[side];
    double spawnZ = z + Facing.offsetsZForSide[side] + 0.5;
    if (side == ForgeDirection.UP.ordinal()
        && (blk instanceof BlockFence || blk instanceof BlockWall)) {
      spawnY += 0.5;
    }
    mob.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0);

    boolean spaceClear =
        world.checkNoEntityCollision(mob.boundingBox)
            && world.getCollidingBoundingBoxes(mob, mob.boundingBox).isEmpty();
    if (!spaceClear) {
      return false;
    }

    if (itemstack.hasDisplayName() && mob instanceof EntityLiving) {
      ((EntityLiving) mob).setCustomNameTag(itemstack.getDisplayName());
    }

    world.spawnEntityInWorld(mob);
    if (mob instanceof EntityLiving) {
      ((EntityLiving) mob).playLivingSound();
    }

    Entity riddenByEntity = mob.riddenByEntity;
    while (riddenByEntity != null) {
      riddenByEntity.setLocationAndAngles(
          spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0.0F);
      world.spawnEntityInWorld(riddenByEntity);
      if (riddenByEntity instanceof EntityLiving) {
        ((EntityLiving) riddenByEntity).playLivingSound();
      }
      riddenByEntity = riddenByEntity.riddenByEntity;
    }

    if (!player.capabilities.isCreativeMode) {
      if (itemstack.stackSize > 1) {
        itemstack.stackSize--;
        player.inventory.addItemStackToInventory(new ItemStack(this));
        player.inventoryContainer.detectAndSendChanges();
      } else {
        itemstack.setTagCompound(null);
      }
    }

    return true;
  }
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    if (this.isNotSlab) {
      return super.onItemUse(
          par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
    } else if (par1ItemStack.stackSize == 0) {
      return false;
    } else if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)) {
      return false;
    } else {
      Block block = par3World.getBlock(par4, par5, par6);
      int i1 = par3World.getBlockMetadata(par4, par5, par6);
      int j1 = i1 & 7;
      boolean flag = (i1 & 8) != 0;

      String name = null;
      String uuid = null;

      if (par3World.getTileEntity(par4, par5, par6) instanceof IOwnable) {
        name = ((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwnerName();
        uuid = ((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwnerUUID();

        if (!BlockUtils.isOwnerOfBlock(
            (IOwnable) par3World.getTileEntity(par4, par5, par6), par2EntityPlayer)) {
          if (!par3World.isRemote) {
            PlayerUtils.sendMessageToPlayer(
                par2EntityPlayer,
                StatCollector.translateToLocal("messages.reinforcedSlab"),
                StatCollector.translateToLocal("messages.reinforcedSlab.cannotDoubleSlab"),
                EnumChatFormatting.RED);
          }

          return false;
        }
      }

      if ((par7 == 1 && !flag || par7 == 0 && flag)
          && isBlock(block)
          && j1 == par1ItemStack.getItemDamage()) {
        if (par3World.checkNoEntityCollision(
                this.getBlockVariant(i1)
                    .getCollisionBoundingBoxFromPool(par3World, par4, par5, par6))
            && par3World.setBlock(
                par4,
                par5,
                par6,
                this.getBlockVariant(block, i1),
                (block == mod_SecurityCraft.reinforcedStoneSlabs && i1 == 2 ? 2 : j1),
                3)) {
          par3World.playSoundEffect(
              (double) ((float) par4 + 0.5F),
              (double) ((float) par5 + 0.5F),
              (double) ((float) par6 + 0.5F),
              this.getBlockVariant(block, i1).stepSound.func_150496_b(),
              (this.getBlockVariant(block, i1).stepSound.getVolume() + 1.0F) / 2.0F,
              this.getBlockVariant(block, i1).stepSound.getPitch() * 0.8F);
          --par1ItemStack.stackSize;

          if (name != null && uuid != null) {
            ((IOwnable) par3World.getTileEntity(par4, par5, par6)).setOwner(uuid, name);
          }
        }

        return true;
      } else {
        return this.func_150946_a(
                par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7)
            ? true
            : super.onItemUse(
                par1ItemStack,
                par2EntityPlayer,
                par3World,
                par4,
                par5,
                par6,
                par7,
                par8,
                par9,
                par10);
      }
    }
  }
  private boolean func_150946_a(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7) {
    if (par7 == 0) {
      --par5;
    }

    if (par7 == 1) {
      ++par5;
    }

    if (par7 == 2) {
      --par6;
    }

    if (par7 == 3) {
      ++par6;
    }

    if (par7 == 4) {
      --par4;
    }

    if (par7 == 5) {
      ++par4;
    }

    Block block = par3World.getBlock(par4, par5, par6);
    int i1 = par3World.getBlockMetadata(par4, par5, par6);
    int j1 = i1 & 7;

    String name = null;
    String uuid = null;

    if (par3World.getTileEntity(par4, par5, par6) instanceof IOwnable) {
      name = ((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwnerName();
      uuid = ((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwnerUUID();
    }

    if (block == this.singleSlab && j1 == par1ItemStack.getItemDamage()) {
      if (par3World.checkNoEntityCollision(
              this.getBlockVariant(i1).getCollisionBoundingBoxFromPool(par3World, par4, par5, par6))
          && par3World.setBlock(par4, par5, par6, this.getBlockVariant(i1), j1, 3)) {
        par3World.playSoundEffect(
            (double) ((float) par4 + 0.5F),
            (double) ((float) par5 + 0.5F),
            (double) ((float) par6 + 0.5F),
            this.getBlockVariant(i1).stepSound.func_150496_b(),
            (this.getBlockVariant(i1).stepSound.getVolume() + 1.0F) / 2.0F,
            this.getBlockVariant(i1).stepSound.getPitch() * 0.8F);
        --par1ItemStack.stackSize;

        if (name != null && uuid != null) {
          ((IOwnable) par3World.getTileEntity(par4, par5, par6)).setOwner(uuid, name);
        }
      }

      return true;
    } else {
      return false;
    }
  }