@Override
  public boolean onBlockActivated(
      World worldIn,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float subX,
      float subY,
      float subZ) {
    // Play the block break sound and spawn the block break particle effects
    worldIn.playAuxSFXAtEntity(
        player,
        2001,
        x,
        y,
        z,
        Block.getIdFromBlock(this) + (worldIn.getBlockMetadata(x, y, z) << 12));

    if (!worldIn.isRemote) {
      ItemStack itemStack =
          LootSpawns.RubbleMilitaryLoot.getOneItem(
              worldIn.rand); // Get a random item from the loot list
      dropBlockAsItem(worldIn, x, y, z, itemStack); // Drop it in the world

      worldIn.setBlockToAir(x, y, z); // Set this block to air
    }

    return true;
  }
Exemplo n.º 2
0
  /** Called upon block activation (right click on the block.) */
  public boolean onBlockActivated(
      World p_149727_1_,
      int p_149727_2_,
      int p_149727_3_,
      int p_149727_4_,
      EntityPlayer p_149727_5_,
      int p_149727_6_,
      float p_149727_7_,
      float p_149727_8_,
      float p_149727_9_) {
    if (this.blockMaterial == Material.iron) {
      return false; // Allow items to interact with the door
    } else {
      int i1 = this.func_150012_g(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);
      int j1 = i1 & 7;
      j1 ^= 4;

      if ((i1 & 8) == 0) {
        p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, j1, 2);
        p_149727_1_.markBlockRangeForRenderUpdate(
            p_149727_2_, p_149727_3_, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);
      } else {
        p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_ - 1, p_149727_4_, j1, 2);
        p_149727_1_.markBlockRangeForRenderUpdate(
            p_149727_2_, p_149727_3_ - 1, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);
      }

      p_149727_1_.playAuxSFXAtEntity(p_149727_5_, 1003, p_149727_2_, p_149727_3_, p_149727_4_, 0);
      return true;
    }
  }
Exemplo n.º 3
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityplayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    if (!canBlockStay(world, x, y, z)) {
      world.setBlockToAir(x, y, z);
      world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(this, 1)));
    } else if ((TEBloomery) world.getTileEntity(x, y, z) != null) {
      TEBloomery te = (TEBloomery) world.getTileEntity(x, y, z);
      ItemStack is = entityplayer.getCurrentEquippedItem();

      if (is != null
          && (is.getItem() == TFCItems.FireStarter || is.getItem() == TFCItems.FlintSteel)) {
        if (te.canLight()) entityplayer.getCurrentEquippedItem().damageItem(1, entityplayer);
      } else {
        world.playAuxSFXAtEntity(entityplayer, 1003, x, y, z, 0);
        if (isOpen(world.getBlockMetadata(x, y, z)))
          world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 8, 3);
        else world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) + 8, 3);
      }
    }
    return true;
  }
  public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    MovingObjectPosition var4 = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, false);
    if (var4 != null
        && var4.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
        && worldIn.getBlockState(var4.func_178782_a()).getBlock() == Blocks.end_portal_frame) {
      return itemStackIn;
    } else {
      if (!worldIn.isRemote) {
        BlockPos var5 = worldIn.func_180499_a("Stronghold", new BlockPos(playerIn));
        if (var5 != null) {
          EntityEnderEye var6 =
              new EntityEnderEye(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ);
          var6.func_180465_a(var5);
          worldIn.spawnEntityInWorld(var6);
          worldIn.playSoundAtEntity(
              playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
          worldIn.playAuxSFXAtEntity((EntityPlayer) null, 1002, new BlockPos(playerIn), 0);
          if (!playerIn.capabilities.isCreativeMode) {
            --itemStackIn.stackSize;
          }

          playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
        }
      }

      return itemStackIn;
    }
  }
  @Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {

    if (!world.isRemote) {
      BlockPos blockpos = world.getStrongholdPos("Stronghold", new BlockPos(player));

      if (blockpos != null) {
        EntityEnderEye entityendereye =
            new EntityEnderEye(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5);
        entityendereye.moveTowards(blockpos);
        world.spawnEntityInWorld(entityendereye);
        world.playAuxSFXAtEntity((EntityPlayer) null, 1002, new BlockPos(player), 0);
      }
    }

    return true;
  }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {

    ItemStack ci = player.inventory.mainInventory[player.inventory.currentItem];
    if (ci != null && Block.getBlockFromItem(ci.getItem()).equals(this)) {
      for (int i = y + 1, e = world.getActualHeight(); i < e; ++i) {
        Block block = world.getBlock(x, i, z);
        if (block.isAir(world, x, i, z) || block.isReplaceable(world, x, i, z)) {
          if (!world.isRemote && world.setBlock(x, i, z, this, 0, 3)) {
            world.playAuxSFXAtEntity(null, 2001, x, i, z, Block.getIdFromBlock(this));
            if (!player.capabilities.isCreativeMode) {
              ci.stackSize--;
              if (ci.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
              }
            }
          }
          return true;
        } else if (!block.equals(this)) {
          return false;
        }
      }
    }
    return false;
  }
  public static void activate(World par1World, BlockPos pos, EntityPlayer player) {
    if (!BlockUtils.getBlockPropertyAsBoolean(par1World, pos, BlockKeypadFurnace.OPEN)) {
      BlockUtils.setBlockProperty(par1World, pos, BlockKeypadFurnace.OPEN, true, false);
    }

    par1World.playAuxSFXAtEntity((EntityPlayer) null, 1006, pos, 0);
    player.openGui(mod_SecurityCraft.instance, 16, par1World, pos.getX(), pos.getY(), pos.getZ());
  }
Exemplo n.º 8
0
  public int acceptEnergy(int offeredAmount) {
    if (BlockUtils.isUnbreakableBlock(world, x, y, z)) {
      hasFailed = true;
      return 0;
    }

    energyRequired = BlockUtils.computeBlockBreakEnergy(world, x, y, z);

    int usedAmount =
        MathUtils.clamp(offeredAmount, 0, Math.max(0, energyRequired - energyAccepted));
    energyAccepted += usedAmount;

    if (energyAccepted >= energyRequired) {
      world.destroyBlockInWorldPartially(minerId, x, y, z, -1);

      hasMined = true;

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

      BlockEvent.BreakEvent breakEvent =
          new BlockEvent.BreakEvent(
              x,
              y,
              z,
              world,
              block,
              meta,
              CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get());
      MinecraftForge.EVENT_BUS.post(breakEvent);

      if (!breakEvent.isCanceled()) {
        List<ItemStack> stacks = BlockUtils.getItemStackFromBlock((WorldServer) world, x, y, z);

        if (stacks != null) {
          for (ItemStack s : stacks) {
            if (s != null) {
              mineStack(s);
            }
          }
        }

        world.playAuxSFXAtEntity(null, 2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));

        world.setBlockToAir(x, y, z);
      } else {
        hasFailed = true;
      }
    } else {
      world.destroyBlockInWorldPartially(
          minerId,
          x,
          y,
          z,
          MathUtils.clamp((int) Math.floor(energyAccepted * 10 / energyRequired), 0, 9));
    }
    return usedAmount;
  }
Exemplo n.º 9
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    MovingObjectPosition movingobjectposition =
        this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false);

    if (movingobjectposition != null
        && movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
      int i =
          par2World.getBlockId(
              movingobjectposition.blockX,
              movingobjectposition.blockY,
              movingobjectposition.blockZ);

      if (i == Block.endPortalFrame.blockID) {
        return par1ItemStack;
      }
    }

    if (!par2World.isRemote) {
      ChunkPosition chunkposition =
          par2World.findClosestStructure(
              "Stronghold",
              (int) par3EntityPlayer.posX,
              (int) par3EntityPlayer.posY,
              (int) par3EntityPlayer.posZ);

      if (chunkposition != null) {
        EntityEnderEye entityendereye =
            new EntityEnderEye(
                par2World,
                par3EntityPlayer.posX,
                par3EntityPlayer.posY + 1.62D - (double) par3EntityPlayer.yOffset,
                par3EntityPlayer.posZ);
        entityendereye.moveTowards(
            (double) chunkposition.x, chunkposition.y, (double) chunkposition.z);
        par2World.spawnEntityInWorld(entityendereye);
        par2World.playSoundAtEntity(
            par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        par2World.playAuxSFXAtEntity(
            (EntityPlayer) null,
            1002,
            (int) par3EntityPlayer.posX,
            (int) par3EntityPlayer.posY,
            (int) par3EntityPlayer.posZ,
            0);

        if (!par3EntityPlayer.capabilities.isCreativeMode) {
          --par1ItemStack.stackSize;
        }
      }
    }

    return par1ItemStack;
  }
  public int acceptEnergy(int offeredAmount) {
    energyRequired = BlockUtils.computeBlockBreakEnergy(world, x, y, z);

    int usedAmount =
        MathUtils.clamp(offeredAmount, 0, Math.max(0, energyRequired - energyAccepted));
    energyAccepted += usedAmount;

    if (energyAccepted >= energyRequired) {
      world.destroyBlockInWorldPartially(minerId, x, y, z, -1);

      hasMined = true;

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

      /* TODO gamerforEA code replace, old code:
      BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(x, y, z, world, block, meta, CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get());
      MinecraftForge.EVENT_BUS.post(breakEvent);

      if (!breakEvent.isCanceled())*/
      EntityPlayer player =
          this.owner instanceof TileBuildCraft
              ? ((TileBuildCraft) this.owner).getOwnerFake()
              : CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get();
      if (!FakePlayerUtils.cantBreak(player, x, y, z))
      // TODO gamerforEA code end
      {
        List<ItemStack> stacks = BlockUtils.getItemStackFromBlock((WorldServer) world, x, y, z);

        if (stacks != null) {
          for (ItemStack s : stacks) {
            if (s != null) {
              mineStack(s);
            }
          }
        }

        world.playAuxSFXAtEntity(null, 2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));

        Utils.preDestroyBlock(world, x, y, z);
        world.setBlockToAir(x, y, z);
      } else {
        hasFailed = true;
      }
    } else {
      world.destroyBlockInWorldPartially(
          minerId,
          x,
          y,
          z,
          MathUtils.clamp((int) Math.floor(energyAccepted * 10 / energyRequired), 0, 9));
    }
    return usedAmount;
  }
Exemplo n.º 11
0
  public void func_150120_a(
      World p_150120_1_, int p_150120_2_, int p_150120_3_, int p_150120_4_, boolean p_150120_5_) {
    int l = p_150120_1_.getBlockMetadata(p_150120_2_, p_150120_3_, p_150120_4_);
    boolean flag1 = (l & 4) > 0;

    if (flag1 != p_150120_5_) {
      p_150120_1_.setBlockMetadataWithNotify(p_150120_2_, p_150120_3_, p_150120_4_, l ^ 4, 2);
      p_150120_1_.playAuxSFXAtEntity(
          (EntityPlayer) null, 1003, p_150120_2_, p_150120_3_, p_150120_4_, 0);
    }
  }
Exemplo n.º 12
0
  /** Sets state (open or closed). */
  public static void setState(TEBase TE, int state, boolean playSound) {
    int temp = BlockProperties.getMetadata(TE) & 0xffbf;
    temp |= state << 6;

    World world = TE.getWorldObj();

    if (!world.isRemote && playSound) {
      world.playAuxSFXAtEntity((EntityPlayer) null, 1003, TE.xCoord, TE.yCoord, TE.zCoord, 0);
    }

    BlockProperties.setMetadata(TE, temp);
  }
Exemplo n.º 13
0
 private void emulateBlockHarvest(
     ItemStack stack,
     World world,
     int x,
     int y,
     int z,
     Block block,
     int meta,
     EntityPlayer player) {
   world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) | meta << 12);
   stack.func_150999_a(world, block, x, y, z, player);
   if (stack.stackSize == 0) player.destroyCurrentEquippedItem();
   if (block.removedByPlayer(world, player, x, y, z, false)) {
     block.dropBlockAsItem(world, x, y, z, meta, EnchantmentHelper.getFortuneModifier(player));
   }
 }
Exemplo n.º 14
0
  public static List<ItemStack> breakBlock(
      World worldObj,
      EntityPlayer player,
      int x,
      int y,
      int z,
      Block block,
      int fortune,
      boolean doBreak,
      boolean silkTouch) {

    if (block.getBlockHardness(worldObj, x, y, z) == -1) {
      return new LinkedList<ItemStack>();
    }
    int meta = worldObj.getBlockMetadata(x, y, z);
    List<ItemStack> stacks = null;
    if (silkTouch && block.canSilkHarvest(worldObj, player, x, y, z, meta)) {
      stacks = new LinkedList<ItemStack>();
      stacks.add(createStackedBlock(block, meta));
    } else {
      stacks = block.getDrops(worldObj, x, y, z, meta, fortune);
    }
    if (!doBreak) {
      return stacks;
    }
    worldObj.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
    worldObj.setBlockToAir(x, y, z);

    List<EntityItem> result =
        worldObj.getEntitiesWithinAABB(
            EntityItem.class,
            AxisAlignedBB.getBoundingBox(x - 2, y - 2, z - 2, x + 3, y + 3, z + 3));
    for (int i = 0; i < result.size(); i++) {
      EntityItem entity = result.get(i);
      if (entity.isDead || entity.getEntityItem().stackSize <= 0) {
        continue;
      }
      stacks.add(entity.getEntityItem());
      entity.worldObj.removeEntity(entity);
    }
    return stacks;
  }
Exemplo n.º 15
0
  public void func_150014_a(
      World p_150014_1_, int p_150014_2_, int p_150014_3_, int p_150014_4_, boolean p_150014_5_) {
    int l = this.func_150012_g(p_150014_1_, p_150014_2_, p_150014_3_, p_150014_4_);
    boolean flag1 = (l & 4) != 0;

    if (flag1 != p_150014_5_) {
      int i1 = l & 7;
      i1 ^= 4;

      if ((l & 8) == 0) {
        p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_, p_150014_4_, i1, 2);
        p_150014_1_.markBlockRangeForRenderUpdate(
            p_150014_2_, p_150014_3_, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_);
      } else {
        p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_ - 1, p_150014_4_, i1, 2);
        p_150014_1_.markBlockRangeForRenderUpdate(
            p_150014_2_, p_150014_3_ - 1, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_);
      }

      p_150014_1_.playAuxSFXAtEntity(
          (EntityPlayer) null, 1003, p_150014_2_, p_150014_3_, p_150014_4_, 0);
    }
  }
Exemplo n.º 16
0
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (this.blockMaterial == Material.iron) {
      return false; // Allow items to interact with the door
    } else {
      BlockPos blockpos1 =
          state.getValue(HALF) == AbstractLockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
      IBlockState iblockstate1 = pos.equals(blockpos1) ? state : worldIn.getBlockState(blockpos1);

      if (iblockstate1.getBlock() != this) {
        return false;
      } else {
        if (!isOpen(worldIn, blockpos1)) {
          if (!worldIn.isRemote) {
            if (playerIn.inventory.getCurrentItem() == null) {
              playerIn.addChatMessage(new ChatComponentTranslation("message.mustusekey"));
              return false;
            }

            if (!(playerIn.inventory.getCurrentItem().getItem() == ModItems.key_master)) {
              if (playerIn.inventory.getCurrentItem().getItem() == ModItems.key_master) {
                return true;
              }

              TileEntity tileentity = worldIn.getTileEntity(blockpos1);
              if (!(tileentity instanceof TileEntityWoodenLockDoor)) {
                if (tileentity == null) {
                  System.out.println("BUG");
                }
                playerIn.addChatMessage(new ChatComponentTranslation("message.invalidkey"));
                return false;
              }

              if (!(playerIn.inventory.getCurrentItem().getItem() instanceof KeyEmerald)) {
                playerIn.addChatMessage(new ChatComponentTranslation("message.emeraldkey"));
                return false;
              }

              if (!playerIn
                  .inventory
                  .getCurrentItem()
                  .getTagCompound()
                  .getString("code")
                  .equals(((TileEntityWoodenLockDoor) tileentity).code)) {
                playerIn.addChatMessage(new ChatComponentTranslation("message.invalidkey"));
                return false;
              }
            }
          } else {
            return false;
          }
        }

        state = iblockstate1.cycleProperty(OPEN);
        worldIn.setBlockState(blockpos1, state, 2);
        worldIn.markBlockRangeForRenderUpdate(blockpos1, pos);
        worldIn.playAuxSFXAtEntity(
            playerIn, ((Boolean) state.getValue(OPEN)).booleanValue() ? 1003 : 1006, pos, 0);

        return true;
      }
    }
  }