Exemplo n.º 1
0
  @Override
  public void placeInWorld(
      IBuilderContext context, int x, int y, int z, LinkedList<ItemStack> stacks) {
    if ((meta & 8) != 0) {
      return;
    }

    context.world().setBlock(x, y, z, block, meta, 3);

    int x2 = x;
    int z2 = z;

    switch (meta) {
      case 0:
        z2++;
        break;
      case 1:
        x2--;
        break;
      case 2:
        z2--;
        break;
      case 3:
        x2++;
        break;
    }

    context.world().setBlock(x2, y, z2, block, meta + 8, 3);
  }
Exemplo n.º 2
0
  @Override
  public void readFromWorld(IBuilderContext context, TileEntity anchorTile, int x, int y, int z) {
    Block block = anchorTile.getWorldObj().getBlock(x, y, z);

    int posX = (int) (x - context.surroundingBox().pMin().x);
    int posY = (int) (y - context.surroundingBox().pMin().y);
    int posZ = (int) (z - context.surroundingBox().pMin().z);

    if (!BuildCraftAPI.softBlocks.contains(block)) {
      contents[posX][posY][posZ] = new SchematicMask(true);
    }
  }
Exemplo n.º 3
0
 @Override
 public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
   return context.world().getBlock(x, y, z) == block;
 }
Exemplo n.º 4
0
 @Override
 public void placeInWorld(
     IBuilderContext context, int x, int y, int z, LinkedList<ItemStack> stacks) {
   context.world().setBlock(x, y, z, block, 0, 3);
 }
Exemplo n.º 5
0
  @Override
  public void writeToWorld(IBuilderContext context) {
    if (mode == Mode.ClearIfInvalid) {
      if (!getSchematic().isAlreadyBuilt(context, x, y, z)) {
        if (BuildCraftBuilders.dropBrokenBlocks) {
          BlockUtils.breakBlock((WorldServer) context.world(), x, y, z);
        } else {
          context.world().setBlockToAir(x, y, z);
        }
      }
    } else {
      try {
        getSchematic().placeInWorld(context, x, y, z, stackConsumed);

        // This is slightly hackish, but it's a very important way to verify
        // the stored requirements.

        if (!context.world().isAirBlock(x, y, z)
            && getSchematic().getBuildingPermission() == BuildingPermission.ALL
            && getSchematic() instanceof SchematicBlock) {
          SchematicBlock sb = (SchematicBlock) getSchematic();
          // Copy the old array of stored requirements.
          ItemStack[] oldRequirementsArray = sb.storedRequirements;
          List<ItemStack> oldRequirements = Arrays.asList(oldRequirementsArray);
          sb.storedRequirements = new ItemStack[0];
          sb.storeRequirements(context, x, y, z);
          for (ItemStack s : sb.storedRequirements) {
            boolean contains = false;
            for (ItemStack ss : oldRequirements) {
              if (StackHelper.isMatchingItem(s, ss)) {
                contains = true;
                break;
              }
            }
            if (!contains) {
              BCLog.logger.warn(
                  "Blueprint has MISMATCHING REQUIREMENTS! Potential corrupted/hacked blueprint! Removed mismatched block.");
              BCLog.logger.warn(
                  "Location: " + x + ", " + y + ", " + z + " - ItemStack: " + s.toString());
              context.world().removeTileEntity(x, y, z);
              context.world().setBlockToAir(x, y, z);
              return;
            }
          }
          // Restore the stored requirements.
          sb.storedRequirements = oldRequirementsArray;
        }

        // Once the schematic has been written, we're going to issue
        // calls
        // to various functions, in particular updating the tile entity.
        // If these calls issue problems, in order to avoid corrupting
        // the world, we're logging the problem and setting the block to
        // air.

        TileEntity e = context.world().getTileEntity(x, y, z);

        if (e != null) {
          e.updateEntity();
        }
      } catch (Throwable t) {
        t.printStackTrace();
        context.world().setBlockToAir(x, y, z);
      }
    }
  }
Exemplo n.º 6
0
 @Override
 public void writeCompleted(IBuilderContext context, double complete) {
   if (mode == Mode.ClearIfInvalid) {
     context.world().destroyBlockInWorldPartially(0, x, y, z, (int) (complete * 10.0F) - 1);
   }
 }