Esempio n. 1
0
  @Override
  public void placeInWorld(
      IBuilderContext context, int x, int y, int z, LinkedList<ItemStack> stacks) {
    if (isConcrete) {
      if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), x, y, z)) {
        return;
      } else {
        ItemStack stack = stacks.getFirst();
        EntityPlayer player =
            BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get();

        // force the block to be air block, in case it's just a soft
        // block which replacement is not straightforward
        context.world().setBlock(x, y, z, Blocks.air, 0, 3);

        // Find nearest solid surface to place on
        ForgeDirection dir = ForgeDirection.DOWN;
        while (dir != ForgeDirection.UNKNOWN
            && BuildCraftAPI.isSoftBlock(
                context.world(), x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ)) {
          dir = ForgeDirection.getOrientation(dir.ordinal() + 1);
        }

        stack.tryPlaceItemIntoWorld(
            player,
            context.world(),
            x + dir.offsetX,
            y + dir.offsetY,
            z + dir.offsetZ,
            dir.getOpposite().ordinal(),
            0.0f,
            0.0f,
            0.0f);
      }
    } else {
      context.world().setBlock(x, y, z, Blocks.air, 0, 3);
    }
  }