public static void applyShape(
      IShape shape,
      EntityPlayer player,
      ArrayList<NBTTagCompound> blockDataNbtList,
      byte baseRotation) {
    try {
      ArrayList<BlockData> blockDataList = new ArrayList<>();
      for (NBTTagCompound compound : blockDataNbtList) {
        BlockData blockData = new BlockData(compound);
        for (int i = 0; i <= blockData.weight; i++) blockDataList.add(blockData);
      }

      int x = Helper.round(player.posX),
          y = Helper.round(player.posY + 1),
          z = Helper.round(player.posZ);
      Collection<PointI> points =
          shape
              .rotate(baseRotation)
              .rotate(baseRotation == -1 ? -1 : Helper.getHeading(player))
              .move(x, y, z)
              .getPoints();
      for (PointI p : points) {
        if (!shape.getReplaceableOnly()
            || player
                .worldObj
                .getBlock(p.getX(), p.getY(), p.getZ())
                .isReplaceable(player.worldObj, p.getX(), p.getY(), p.getZ())) {
          BlockData block =
              blockDataList.size() == 1
                  ? blockDataList.get(0)
                  : Helper.getRandomFromSet(blockDataList);
          Block block1 = Block.getBlockById(block.id);
          player.worldObj.setBlock(p.getX(), p.getY(), p.getZ(), block1, block.meta, 2);
          if (block.te != null) {
            TileEntity tileEntity = TileEntity.createAndLoadEntity(block.te);
            tileEntity.setWorldObj(player.worldObj);
            tileEntity.xCoord = p.getX();
            tileEntity.yCoord = p.getY();
            tileEntity.zCoord = p.getZ();
            player.worldObj.setTileEntity(p.getX(), p.getY(), p.getZ(), tileEntity);
          }
        }
      }
    } catch (BlockData.BannedBlockException e) {
      ((EntityPlayerMP) player).playerNetServerHandler.kickPlayerFromServer(e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      Pay2Spawn.getLogger().warn("Error spawning in shape.");
      Pay2Spawn.getLogger().warn("Shape: " + shape.toString());
      Pay2Spawn.getLogger().warn("Player: " + player);
      Pay2Spawn.getLogger()
          .warn("BlockData array: " + Arrays.deepToString(blockDataNbtList.toArray()));
    }
  }
示例#2
0
  public static boolean swapBlocks(
      Object caller,
      World worldI,
      World worldF,
      int xi,
      int yi,
      int zi,
      int xf,
      int yf,
      int zf,
      boolean doSound,
      int flag) {
    TileEntity tileEntityI = worldI.getTileEntity(xi, yi, zi);
    TileEntity tileEntityF = worldF.getTileEntity(xf, yf, zf);

    NBTTagCompound nbttag1 = new NBTTagCompound();
    NBTTagCompound nbttag2 = new NBTTagCompound();

    if (tileEntityI != null) {
      tileEntityI.writeToNBT(nbttag1);
    }

    if (tileEntityF != null) {
      tileEntityF.writeToNBT(nbttag2);
    }

    Block blockI = worldI.getBlock(xi, yi, zi);
    Block blockF = worldF.getBlock(xf, yf, zf);

    if (blockI.equals(Blocks.air) && blockF.equals(Blocks.air)) {
      return false;
    }

    if (blockI instanceof BlockMobSpawner
            || blockF instanceof BlockMobSpawner
            || caller instanceof TEDemonPortal
        ? false
        : blockI instanceof BlockPortal || blockF instanceof BlockPortal) {
      return false;
    }

    int metaI = worldI.getBlockMetadata(xi, yi, zi);
    int metaF = worldF.getBlockMetadata(xf, yf, zf);

    TeleposeEvent evt =
        new TeleposeEvent(worldI, xi, yi, zi, blockI, metaI, worldF, xf, yf, zf, blockF, metaF);
    if (MinecraftForge.EVENT_BUS.post(evt)) return false;

    if (doSound) {
      worldI.playSoundEffect(xi, yi, zi, "mob.endermen.portal", 1.0F, 1.0F);
      worldF.playSoundEffect(xf, yf, zf, "mob.endermen.portal", 1.0F, 1.0F);
    }

    // CLEAR TILES
    Block finalBlock = blockF;

    if (finalBlock != null) {
      TileEntity tileToSet = finalBlock.createTileEntity(worldF, metaF);

      worldF.setTileEntity(xf, yf, zf, tileToSet);
    }

    if (blockI != null) {
      TileEntity tileToSet = blockI.createTileEntity(worldI, metaI);

      worldI.setTileEntity(xi, yi, zi, tileToSet);
    }

    // TILES CLEARED
    worldF.setBlock(xf, yf, zf, blockI, metaI, flag);

    if (tileEntityI != null) {
      TileEntity newTileEntityI = TileEntity.createAndLoadEntity(nbttag1);

      if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
        newTileEntityI = createMultipartFromNBT(worldF, nbttag1);
      }

      worldF.setTileEntity(xf, yf, zf, newTileEntityI);

      newTileEntityI.xCoord = xf;
      newTileEntityI.yCoord = yf;
      newTileEntityI.zCoord = zf;

      if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
        sendDescriptorOfTile(worldF, newTileEntityI);
      }
    }

    worldI.setBlock(xi, yi, zi, finalBlock, metaF, flag);

    if (tileEntityF != null) {
      TileEntity newTileEntityF = TileEntity.createAndLoadEntity(nbttag2);
      if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
        newTileEntityF = createMultipartFromNBT(worldI, nbttag2);
      }

      worldI.setTileEntity(xi, yi, zi, newTileEntityF);

      newTileEntityF.xCoord = xi;
      newTileEntityF.yCoord = yi;
      newTileEntityF.zCoord = zi;

      if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
        sendDescriptorOfTile(worldI, newTileEntityF);
      }
    }

    return true;
  }