@Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (!stack.hasTagCompound()) return false;

    World world = player.worldObj;
    final Block wood = world.getBlock(x, y, z);
    ;
    if (wood == null) {
      return super.onBlockStartBreak(stack, x, y, z, player);
    }
    if (wood.isWood(world, x, y, z) || wood.getMaterial() == Material.sponge) {
      int height = y;
      boolean foundTop = false;
      do {
        height++;
        Block block = world.getBlock(x, height, z);
        if (block != wood) {
          height--;
          foundTop = true;
        }
      } while (!foundTop);

      int numLeaves = 0;
      if (height - y < 50) {
        for (int xPos = x - 1; xPos <= x + 1; xPos++) {
          for (int yPos = height - 1; yPos <= height + 1; yPos++) {
            for (int zPos = z - 1; zPos <= z + 1; zPos++) {
              Block leaves = world.getBlock(xPos, yPos, zPos);
              if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos)) numLeaves++;
            }
          }
        }
      }

      NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
      int meta = world.getBlockMetadata(x, y, z);
      if (numLeaves > 3) breakTree(world, x, y, z, stack, tags, wood, meta, player);
      else destroyWood(world, x, y, z, stack, tags, player);

      if (!world.isRemote)
        world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
    } else if (wood.getMaterial() == Material.wood) {
      NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
      int meta = world.getBlockMetadata(x, y, z);
      destroyWood(world, x, y, z, stack, tags, player);
      if (!world.isRemote)
        world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
    }
    return super.onBlockStartBreak(stack, x, y, z, player);
  }
  @Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    World world = player.worldObj;
    int bID = player.worldObj.getBlockId(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);
    Block block = Block.blocksList[bID];
    if (block == null || bID < 1) return false;
    int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
    int shlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getSecondHarvestType());

    if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2")) {
      boolean cancelHarvest = false;
      for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
        if (mod.beforeBlockBreak(this, stack, x, y, z, player)) cancelHarvest = true;
      }

      return cancelHarvest;
    } else {
      if (!player.capabilities.isCreativeMode) onBlockDestroyed(stack, world, bID, x, y, z, player);
      world.setBlockToAir(x, y, z);
      if (!world.isRemote) world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
      return true;
    }
  }
 public void setSoupType(World world, int x, int y, int z, TileFilledSoupPan pan, SoupType type) {
   if (pan == null) return;
   pan.setType(type);
   pan.setRemainByte((byte) 8);
   world.playAuxSFX(2005, x, y, z, 0);
   world.markBlockForUpdate(x, y, z);
 }
Exemple #4
0
  /* Place bushes on dirt, grass, or other bushes only */
  @Override
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      int x,
      int y,
      int z,
      int side,
      float par8,
      float par9,
      float par10) {
    if (side != 1) return false;
    else if (player.canPlayerEdit(x, y, z, side, stack)
        && player.canPlayerEdit(x, y + 1, z, side, stack)) {
      Block block = Block.blocksList[world.getBlockId(x, y, z)];

      if (block != null
          && (block.canSustainPlant(
                  world, x, y, z, ForgeDirection.UP, (IPlantable) NContent.netherBerryBush)
              || block == Block.netherrack)
          && world.isAirBlock(x, y + 1, z)) {
        world.setBlock(x, y + 1, z, NContent.netherBerryBush.blockID, stack.getItemDamage() % 4, 3);
        if (!player.capabilities.isCreativeMode) stack.stackSize--;
        if (!world.isRemote) world.playAuxSFX(2001, x, y, z, NContent.netherBerryBush.blockID);
        return true;
      } else return false;
    } else return false;
  }
  @Override
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (ItemDye.applyBonemeal(par1ItemStack, par3World, pos, par2EntityPlayer)) {
      if (!par3World.isRemote) {
        par3World.playAuxSFX(2005, pos, 0);
      }
      return true;
    }

    IBlockState blockState = par3World.getBlockState(pos);
    if (blockState.getBlock() instanceof IGrowable) {
      IGrowable plant = (IGrowable) blockState.getBlock();
      plant.grow(par3World, new Random(), pos, blockState);
    }

    return true;
  }
Exemple #6
0
 protected void setWet(World worldIn, BlockPos p_176311_2_, IBlockState p_176311_3_) {
   if (!((Boolean) p_176311_3_.getValue(WET_PROP)).booleanValue()
       && this.absorbWater(worldIn, p_176311_2_)) {
     worldIn.setBlockState(
         p_176311_2_, p_176311_3_.withProperty(WET_PROP, Boolean.valueOf(true)), 2);
     worldIn.playAuxSFX(2001, p_176311_2_, Block.getIdFromBlock(Blocks.water));
   }
 }
Exemple #7
0
 protected int applySingle(World w, IBlockState state, BlockPos pos) {
   if (state != null
       && state.getBlock() instanceof IGrowable
       && !(state.getBlock() instanceof BlockGrass)) {
     IGrowable g = ((IGrowable) state.getBlock());
     if (g.canGrow(w, pos, state, w.isRemote) && g.canUseBonemeal(w, w.rand, pos, state)) {
       while (g.canGrow(w, pos, state, w.isRemote)) {
         g.grow(w, w.rand, pos, state);
         w.playAuxSFX(2005, pos, 0);
         if (g instanceof BlockDoublePlant) w.playAuxSFX(2005, pos.up(), 0);
         state = w.getBlockState(pos);
       }
       return 1;
     }
   }
   return 0;
 }
  @Override
  public void processPacket(NetHandler nethandler) {
    ObjectPair<World, EntityPlayer> pair = UtilMinecraft.getWorldAndPlayer(PlayerName);
    world = pair.getV1();
    player = pair.getV2();
    if (metadata == -1) {
      AnimalCrossing.reset(world, X, Y, Z);
      return;
    }

    world.playAuxSFX(1022, X, Y, Z, 0);

    if (AnimalCrossing.counting(world, X, Y, Z)) {
      SearchAndSpawnBlocks();
    }
  }
  @Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (!stack.hasTagCompound()) return false;

    World world = player.worldObj;
    final int blockID = world.getBlockId(x, y, z);
    final int meta = world.getBlockMetadata(x, y, z);
    if (!stack.hasTagCompound()) return false;
    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    for (int xPos = x - 1; xPos <= x + 1; xPos++) {
      for (int yPos = y - 1; yPos <= y + 1; yPos++) {
        for (int zPos = z - 1; zPos <= z + 1; zPos++) {
          if (!(tags.getBoolean("Broken"))) {
            boolean cancelHarvest = false;
            for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
              if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) cancelHarvest = true;
            }

            if (!cancelHarvest) {
              int localblockID = world.getBlockId(xPos, yPos, zPos);
              Block block = Block.blocksList[localblockID];
              if (block
                  != null) // && (block.blockMaterial == Material.leaves || block.isLeaves(world,
              // xPos, yPos, zPos)))
              {
                for (int iter = 0; iter < materials.length; iter++) {
                  if (materials[iter] == block.blockMaterial) {
                    int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
                    world.setBlockToAir(xPos, yPos, zPos);
                    if (!player.capabilities.isCreativeMode) {
                      block.onBlockDestroyedByPlayer(world, x, y, z, meta);
                      block.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
                      block.onBlockHarvested(world, x, y, z, localMeta, player);
                      onBlockDestroyed(stack, world, localblockID, xPos, yPos, zPos, player);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    if (!world.isRemote) world.playAuxSFX(2001, x, y, z, blockID + (meta << 12));
    return super.onBlockStartBreak(stack, x, y, z, player);
  }
  public static void removeBlockWithDrops(
      SpellContext context,
      EntityPlayer player,
      World world,
      ItemStack tool,
      BlockPos pos,
      boolean particles) {
    if (!world.isBlockLoaded(pos)
        || context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos()))
      return;

    int harvestLevel = ConfigHandler.cadHarvestLevel;
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (!world.isRemote
        && block != null
        && !block.isAir(world, pos)
        && !(block instanceof BlockLiquid)
        && block.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
      int neededHarvestLevel = block.getHarvestLevel(state);
      if (neededHarvestLevel > harvestLevel) return;

      BreakEvent event = new BreakEvent(world, pos, state, player);
      MinecraftForge.EVENT_BUS.post(event);
      if (!event.isCanceled()) {
        if (!player.capabilities.isCreativeMode) {
          block.onBlockHarvested(world, pos, state, player);

          if (block.removedByPlayer(world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
            block.harvestBlock(world, player, pos, state, world.getTileEntity(pos));
          }
        } else world.setBlockToAir(pos);
      }

      if (particles) world.playAuxSFX(2001, pos, Block.getStateId(state));
    }
  }
  // 右クリック効果
  @Override
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    Block block = par3World.getBlock(par4, par5, par6);
    TileEntity tile = par3World.getTileEntity(par4, par5, par6);
    int meta = par3World.getBlockMetadata(par4, par5, par6);

    if (par2EntityPlayer == null) return false;
    boolean se = false;

    // charge
    if (tile instanceof MachineBase) {
      MachineBase machine = (MachineBase) tile;
      if (!machine.isFullCharged()) {
        int max = machine.getMaxChargeAmount();
        int ret = machine.getChargeAmount() + 800;
        ret = MathHelper.clamp_int(ret, 0, max);
        machine.setChargeAmount(ret);
        se = true;
      }
    } else if (tile instanceof TileChargerDevice) {
      TileChargerDevice device = (TileChargerDevice) tile;
      if (!device.isFullCharged()) {
        int max = device.getMaxChargeAmount();
        int ret = device.getChargeAmount() + 800;
        ret = MathHelper.clamp_int(ret, 0, max);
        device.setChargeAmount(ret);
        se = true;
      }
    }
    // RF
    else if (ModAPIManager.INSTANCE.hasAPI("CoFHAPI|energy") && RFDeviceHandler.isRFDevice(tile)) {
      se = RFDeviceHandler.inputEnergy(ForgeDirection.UP, tile, 1000, false) > 0;
    }

    // Barrel
    if (tile instanceof TileBrewingBarrel) {
      TileBrewingBarrel barrel = (TileBrewingBarrel) tile;
      if (!barrel.getAged() && !barrel.productTank.isEmpty()) {
        barrel.setAgingStage(4);
        se = true;
      }
    }

    // 骨粉
    if (ItemDye.applyBonemeal(par1ItemStack, par3World, par4, par5, par6, par2EntityPlayer)) {
      if (!par3World.isRemote) {
        par3World.playAuxSFX(2005, par4, par5, par6, 0);
        se = true;
      }
    }

    // どれでもなかった場合
    if (!se) {
      if (block.canPlaceTorchOnTop(par3World, par4, par5, par6)
          && par3World.isAirBlock(par4, par5 + 1, par6)) {
        if (!par3World.isRemote) par3World.setBlock(par4, par5 + 1, par6, Blocks.torch);
        se = true;
      }
    }

    if (se) {
      par3World.playSoundAtEntity(par2EntityPlayer, "random.pop", 0.4F, 1.8F);
    }
    return true;
  }
  @Override
  public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer ep) {
    if (is.getItemDamage() <= 0) {
      this.noCharge();
      return is;
    }
    this.warnCharge(is);
    if (!ReikaPlayerAPI.playerHasOrIsCreative(ep, Block.gravel.blockID, -1)) {
      if (!world.isRemote) world.playAuxSFX(1001, (int) ep.posX, (int) ep.posY, (int) ep.posZ, 1);
      return is;
    }
    for (float i = 1; i <= 128; i += 0.5) {
      Vec3 look = ep.getLookVec();
      double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, i);
      AxisAlignedBB fov =
          AxisAlignedBB.getBoundingBox(
              looks[0] - 0.5,
              looks[1] - 0.5,
              looks[2] - 0.5,
              looks[0] + 0.5,
              looks[1] + 0.5,
              looks[2] + 0.5);
      List infov = world.getEntitiesWithinAABB(EntityLivingBase.class, fov);
      for (int k = 0; k < infov.size(); k++) {
        EntityLivingBase ent = (EntityLivingBase) infov.get(k);
        if (!ep.equals(ent)
            && this.isEntityAttackable(ent)
            && ReikaWorldHelper.lineOfSight(world, ep, ent)) {
          double dist =
              ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ);
          double x = ep.posX + look.xCoord;
          double y = ep.posY + ep.getEyeHeight() + look.yCoord;
          double z = ep.posZ + look.zCoord;
          double dx = ent.posX - ep.posX;
          double dy = ent.posY - ep.posY;
          double dz = ent.posZ - ep.posZ;
          if (!world.isRemote) {
            ItemStack fl = new ItemStack(Item.flint);
            EntityItem ei =
                new EntityItem(
                    world,
                    look.xCoord / look.lengthVector() + ep.posX,
                    look.yCoord / look.lengthVector() + ep.posY,
                    look.zCoord / look.lengthVector() + ep.posZ,
                    fl);
            ei.delayBeforeCanPickup = 100;
            ei.motionX = dx;
            ei.motionY = dy + 1;
            ei.motionZ = dz;
            // ReikaChatHelper.writeCoords(world, ei.posX, ei.posY, ei.posZ);
            ei.velocityChanged = true;
            world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F);
            ei.lifespan = 5;
            world.spawnEntityInWorld(ei);

            if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob
              // ReikaPacketHelper.sendUpdatePacket(RotaryCraft.packetChannel,
              // PacketRegistry.GRAVELGUN.getMinValue(), world, (int)ent.posX, (int)ent.posY,
              // (int)ent.posZ);
              // world.playSoundAtEntity(ep, "random.explode", 0.25F, 1F);
            }
            if (ent instanceof EntityDragon) {
              EntityDragon ed = (EntityDragon) ent;
              ed.attackEntityFromPart(
                  ed.dragonPartBody, DamageSource.causePlayerDamage(ep), this.getAttackDamage(is));
            } else {
              int dmg = this.getAttackDamage(is);
              if (ent instanceof EntityPlayer) {
                for (int n = 1; n < 5; n++) {
                  ItemRegistry ir = ItemRegistry.getEntry(ent.getCurrentItemOrArmor(n));
                  if (ir != null) {
                    if (ir.isBedrockArmor()) dmg *= 0.75;
                  }
                }
              }
              ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), dmg);
              if (dmg >= 500) RotaryAchievements.MASSIVEHIT.triggerAchievement(ep);
            }
            if (ent instanceof EntityMob
                && (ent.isDead || ent.getHealth() <= 0)
                && ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ)
                    >= 80) RotaryAchievements.GRAVELGUN.triggerAchievement(ep);
          }
          // ReikaWorldHelper.spawnParticleLine(world, x, y, z, ent.posX, ent.posY+ent.height/2,
          // ent.posZ, "crit", 0, 0, 0, 60);
          for (float t = 0; t < 2; t += 0.05F)
            world.spawnParticle("crit", x, y, z, dx / dist * t, dy / dist * t, dz / dist * t);
        }
      }
      if (infov.size() > 0 && !(infov.size() == 1 && infov.get(0) instanceof EntityPlayer)) {
        if (!ep.capabilities.isCreativeMode)
          ReikaInventoryHelper.findAndDecrStack(
              Block.gravel.blockID, -1, ep.inventory.mainInventory);
        return new ItemStack(is.itemID, is.stackSize, is.getItemDamage() - 1);
      }
    }
    return is;
  }
  /**
   * Description : 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. Args : stack, player, world, x, y, z, side, hitX, hitY, hitZ
   */
  public boolean onItemUse(
      ItemStack p_77648_1_,
      EntityPlayer p_77648_2_,
      World p_77648_3_,
      int p_77648_4_,
      int p_77648_5_,
      int p_77648_6_,
      int p_77648_7_,
      float p_77648_8_,
      float p_77648_9_,
      float p_77648_10_) {
    if (!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_)) {
      return false;
    } else {
      if (p_77648_1_.getMetadata() == 15) {
        if (applyBonemeal(p_77648_1_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_2_)) {
          if (!p_77648_3_.isRemote) {
            p_77648_3_.playAuxSFX(2005, p_77648_4_, p_77648_5_, p_77648_6_, 0);
          }

          return true;
        }
      } else if (p_77648_1_.getMetadata() == 3) {
        Block block = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_);
        int i1 = p_77648_3_.getBlockMetadata(p_77648_4_, p_77648_5_, p_77648_6_);

        if (block == Blocks.log && BlockLog.func_150165_c(i1) == 3) {
          if (p_77648_7_ == 0) {
            return false;
          }

          if (p_77648_7_ == 1) {
            return false;
          }

          if (p_77648_7_ == 2) {
            --p_77648_6_;
          }

          if (p_77648_7_ == 3) {
            ++p_77648_6_;
          }

          if (p_77648_7_ == 4) {
            --p_77648_4_;
          }

          if (p_77648_7_ == 5) {
            ++p_77648_4_;
          }

          if (p_77648_3_.isAirBlock(p_77648_4_, p_77648_5_, p_77648_6_)) {
            int j1 =
                Blocks.cocoa.onBlockPlaced(
                    p_77648_3_,
                    p_77648_4_,
                    p_77648_5_,
                    p_77648_6_,
                    p_77648_7_,
                    p_77648_8_,
                    p_77648_9_,
                    p_77648_10_,
                    0);
            p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.cocoa, j1, 2);

            if (!p_77648_2_.capabilities.isCreativeMode) {
              --p_77648_1_.stackSize;
            }
          }

          return true;
        }
      }

      return false;
    }
  }