Exemplo n.º 1
0
  private void spawnRubble(Random random, int chunkX, int chunkZ, World world) {

    // Spawn above ground
    for (int i = 0; i < random.nextInt(ROCK_TRIES); i++) {
      int x = chunkX * 16 + random.nextInt(16);
      int z = chunkZ * 16 + random.nextInt(16);
      BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).down();
      Block block = world.getBlockState(pos).getBlock();
      if (isRockSpawnable(block)) {
        if (world.isAirBlock(pos.up())) {
          world.setBlockState(
              pos.up(),
              ModBlocks.rockBlock
                  .getDefaultState()
                  .withProperty(
                      GenericBlock.FACING_HORIZ, EnumFacing.getHorizontal(random.nextInt(4))),
              3);
        }
      }
    }
    for (int i = 0; i < random.nextInt(STICK_TRIES); i++) {
      int x = chunkX * 16 + random.nextInt(16);
      int z = chunkZ * 16 + random.nextInt(16);
      BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).down();
      Block block = world.getBlockState(pos).getBlock();
      if (isStickSpawnable(block)) {
        trySpawnSticks(world, pos, random);
      }
    }

    // Spawn in caves
    for (int i = 0; i < random.nextInt(ROCK_TRIES); i++) {
      int x = chunkX * 16 + random.nextInt(16);
      int z = chunkZ * 16 + random.nextInt(16);
      BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).down();
      int y = findCaveSpot(world, pos);
      pos = new BlockPos(x, y, z);
      Block block = world.getBlockState(pos).getBlock();
      if (y != -1 && isRockSpawnable(block)) {
        if (world.isAirBlock(pos.up())) {
          world.setBlockState(
              pos.up(),
              ModBlocks.rockBlock
                  .getDefaultState()
                  .withProperty(
                      GenericBlock.FACING_HORIZ, EnumFacing.getHorizontal(random.nextInt(4))),
              3);
        }
      }
    }
  }
Exemplo n.º 2
0
 private void trySpawnSticks(World world, BlockPos pos, Random random) {
   int x = pos.getX();
   int y = pos.getY();
   int z = pos.getZ();
   y++;
   if (!world.isAirBlock(new BlockPos(x, y, z))) {
     return;
   }
   y++;
   if (!BlockTools.isTopValidAndSolid(world, pos)) {
     return;
   }
   for (int i = 0; i < 15; i++) {
     if (!world.isAirBlock(new BlockPos(x, y, z))) {
       if (isLeafBlock(world.getBlockState(new BlockPos(x, y, z)).getBlock())) {
         world.setBlockState(
             pos.up(),
             ModBlocks.sticksBlock
                 .getDefaultState()
                 .withProperty(
                     GenericBlock.FACING_HORIZ, EnumFacing.getHorizontal(random.nextInt(4))),
             3);
         SticksTE sticksTE = (SticksTE) world.getTileEntity(pos.up());
         sticksTE.setSticks(random.nextInt(6) + 1);
       }
       return;
     }
     y++;
   }
 }
Exemplo n.º 3
0
 @Override
 public void onBlockPlacedBy(
     World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
   final int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
   int change = EnumFacing.getHorizontal(angle).getOpposite().getIndex();
   worldIn.setBlockState(pos, getStateFromMeta(change), 3);
 }
 /** Convert the given metadata into a BlockState for this Block */
 public IBlockState getStateFromMeta(int meta) {
   return this.getDefaultState()
       .withProperty(FACING, EnumFacing.getHorizontal(meta))
       .withProperty(POWERED, Boolean.valueOf((meta & 8) > 0))
       .withProperty(
           MODE,
           (meta & 4) > 0
               ? BlockRedstoneComparator.Mode.SUBTRACT
               : BlockRedstoneComparator.Mode.COMPARE);
 }
Exemplo n.º 5
0
  /** (abstract) Protected helper method to read subclass entity data from NBT. */
  public void readEntityFromNBT(NBTTagCompound tagCompund) {
    this.field_174861_a =
        new BlockPos(
            tagCompund.getInteger("TileX"),
            tagCompund.getInteger("TileY"),
            tagCompund.getInteger("TileZ"));
    EnumFacing var2;

    if (tagCompund.hasKey("Direction", 99)) {
      var2 = EnumFacing.getHorizontal(tagCompund.getByte("Direction"));
      this.field_174861_a = this.field_174861_a.offset(var2);
    } else if (tagCompund.hasKey("Facing", 99)) {
      var2 = EnumFacing.getHorizontal(tagCompund.getByte("Facing"));
    } else {
      var2 = EnumFacing.getHorizontal(tagCompund.getByte("Dir"));
    }

    this.func_174859_a(var2);
  }
Exemplo n.º 6
0
  @Override
  public void onBlockPlacedBy(
      World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    final int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
    int change = EnumFacing.getHorizontal(angle).getOpposite().getHorizontalIndex();

    if (stack.getItemDamage() >= METADATA_CARGO_UNLOADER) {
      change += METADATA_CARGO_UNLOADER;
    } else if (stack.getItemDamage() >= METADATA_CARGO_LOADER) {
      change += METADATA_CARGO_LOADER;
    }

    worldIn.setBlockState(pos, getStateFromMeta(change), 3);

    for (int dX = -2; dX < 3; dX++) {
      for (int dZ = -2; dZ < 3; dZ++) {
        final Block block = worldIn.getBlockState(pos.add(dX, 0, dZ)).getBlock();

        if (block == GCBlocks.landingPadFull) {
          worldIn.markBlockForUpdate(pos.add(dX, 0, dZ));
        }
      }
    }
  }
Exemplo n.º 7
0
 /** Convert the given metadata into a BlockState for this Block */
 public IBlockState getStateFromMeta(int meta) {
   return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
 }
Exemplo n.º 8
0
 /** Convert the given metadata into a BlockState for this Block */
 public IBlockState getStateFromMeta(int meta) {
   return this.getDefaultState()
       .withProperty(FACING, EnumFacing.getHorizontal(meta))
       .withProperty(OPEN, Boolean.valueOf((meta & 4) != 0))
       .withProperty(POWERED, Boolean.valueOf((meta & 8) != 0));
 }
Exemplo n.º 9
0
  public IBlockState getStateFromMeta(int meta) {
    EnumFacing enumfacing = EnumFacing.getHorizontal(meta % 4);
    EnumLoaderType type = EnumLoaderType.byMetadata((int) Math.floor(meta / 4.0));

    return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(TYPE, type);
  }
Exemplo n.º 10
0
    public BakedFluid(
        Optional<TRSRTransformation> transformation,
        ImmutableMap<TransformType, TRSRTransformation> transforms,
        VertexFormat format,
        int color,
        TextureAtlasSprite still,
        TextureAtlasSprite flowing,
        boolean gas,
        boolean statePresent,
        int[] cornerRound,
        int flowRound) {
      this.transformation = transformation;
      this.transforms = transforms;
      this.format = format;
      this.color = color;
      this.still = still;
      this.flowing = flowing;
      this.gas = gas;

      faceQuads = Maps.newEnumMap(EnumFacing.class);
      for (EnumFacing side : EnumFacing.values()) {
        faceQuads.put(side, ImmutableList.<BakedQuad>of());
      }

      if (statePresent) {
        float[] y = new float[4];
        for (int i = 0; i < 4; i++) {
          if (gas) {
            y[i] = 1 - cornerRound[i] / 768f;
          } else {
            y[i] = cornerRound[i] / 768f;
          }
        }

        float flow = (float) Math.toRadians(flowRound);

        // top

        TextureAtlasSprite topSprite = flowing;
        float scale = 4;
        if (flow < -17F) {
          flow = 0;
          scale = 8;
          topSprite = still;
        }

        float c = MathHelper.cos(flow) * scale;
        float s = MathHelper.sin(flow) * scale;

        EnumFacing side = gas ? EnumFacing.DOWN : EnumFacing.UP;
        UnpackedBakedQuad.Builder builder;
        ImmutableList.Builder<BakedQuad> topFaceBuilder = ImmutableList.builder();
        for (int k = 0; k < 2; k++) {
          builder = new UnpackedBakedQuad.Builder(format);
          builder.setQuadOrientation(side);
          builder.setTexture(topSprite);
          for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) {
            int l = (k * 3) + (1 - 2 * k) * i;
            putVertex(
                builder,
                side,
                x[l],
                y[l],
                z[l],
                topSprite.getInterpolatedU(8 + c * (x[l] * 2 - 1) + s * (z[l] * 2 - 1)),
                topSprite.getInterpolatedV(
                    8 + c * (x[(l + 1) % 4] * 2 - 1) + s * (z[(l + 1) % 4] * 2 - 1)));
          }
          topFaceBuilder.add(builder.build());
        }
        faceQuads.put(side, topFaceBuilder.build());

        // bottom

        side = side.getOpposite();
        builder = new UnpackedBakedQuad.Builder(format);
        builder.setQuadOrientation(side);
        builder.setTexture(still);
        for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) {
          putVertex(
              builder,
              side,
              z[i],
              gas ? 1 : 0,
              x[i],
              still.getInterpolatedU(z[i] * 16),
              still.getInterpolatedV(x[i] * 16));
        }
        faceQuads.put(side, ImmutableList.<BakedQuad>of(builder.build()));

        // sides

        for (int i = 0; i < 4; i++) {
          side = EnumFacing.getHorizontal((5 - i) % 4);
          BakedQuad q[] = new BakedQuad[2];

          for (int k = 0; k < 2; k++) {
            builder = new UnpackedBakedQuad.Builder(format);
            builder.setQuadOrientation(side);
            builder.setTexture(flowing);
            for (int j = 0; j < 4; j++) {
              int l = (k * 3) + (1 - 2 * k) * j;
              float yl = z[l] * y[(i + x[l]) % 4];
              if (gas && z[l] == 0) yl = 1;
              putVertex(
                  builder,
                  side,
                  x[(i + x[l]) % 4],
                  yl,
                  z[(i + x[l]) % 4],
                  flowing.getInterpolatedU(x[l] * 8),
                  flowing.getInterpolatedV((gas ? yl : 1 - yl) * 8));
            }
            q[k] = builder.build();
          }
          faceQuads.put(side, ImmutableList.of(q[0], q[1]));
        }
      } else {
        // 1 quad for inventory
        UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
        builder.setQuadOrientation(EnumFacing.UP);
        builder.setTexture(still);
        for (int i = 0; i < 4; i++) {
          putVertex(
              builder,
              EnumFacing.UP,
              z[i],
              x[i],
              0,
              still.getInterpolatedU(z[i] * 16),
              still.getInterpolatedV(x[i] * 16));
        }
        faceQuads.put(EnumFacing.SOUTH, ImmutableList.<BakedQuad>of(builder.build()));
      }
    }
Exemplo n.º 11
0
  public boolean addComponentParts(
      World worldIn, Random p_74875_2_, StructureBoundingBox p_74875_3_) {
    if (this.field_143015_k < 0) {
      this.field_143015_k = this.getAverageGroundLevel(worldIn, p_74875_3_);

      if (this.field_143015_k < 0) {
        return true;
      }

      this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 9 - 1, 0);
    }

    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        1,
        1,
        7,
        5,
        4,
        Blocks.air.getDefaultState(),
        Blocks.air.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        0,
        0,
        8,
        0,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        5,
        0,
        8,
        5,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        6,
        1,
        8,
        6,
        4,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        7,
        2,
        8,
        7,
        3,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    int i = this.getMetadataWithOffset(Blocks.nether_brick_stairs, 3);
    int j = this.getMetadataWithOffset(Blocks.nether_brick_stairs, 2);
    int k;
    int l;

    for (k = -1; k <= 2; ++k) {
      for (l = 0; l <= 8; ++l) {
        this.func_175811_a(
            worldIn, Blocks.nether_brick_stairs.getStateFromMeta(i), l, 6 + k, k, p_74875_3_);
        this.func_175811_a(
            worldIn, Blocks.nether_brick_stairs.getStateFromMeta(j), l, 6 + k, 5 - k, p_74875_3_);
      }
    }

    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        1,
        0,
        0,
        1,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        1,
        5,
        8,
        1,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        8,
        1,
        0,
        8,
        1,
        4,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        2,
        1,
        0,
        7,
        1,
        0,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        2,
        0,
        0,
        4,
        0,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        2,
        5,
        0,
        4,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        8,
        2,
        5,
        8,
        4,
        5,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        8,
        2,
        0,
        8,
        4,
        0,
        Blocks.quartz_block.getDefaultState(),
        Blocks.quartz_block.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        0,
        2,
        1,
        0,
        4,
        4,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        2,
        5,
        7,
        4,
        5,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        8,
        2,
        1,
        8,
        4,
        4,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        2,
        0,
        7,
        4,
        0,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 4, 2, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 5, 2, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 6, 2, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 4, 3, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 5, 3, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 6, 3, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 0, 2, 2, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 0, 2, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 0, 3, 2, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 0, 3, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 8, 2, 2, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 8, 2, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 8, 3, 2, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 8, 3, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 2, 2, 5, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 3, 2, 5, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 5, 2, 5, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.iron_bars.getDefaultState(), 6, 2, 5, p_74875_3_);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        4,
        1,
        7,
        4,
        1,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        4,
        4,
        7,
        4,
        4,
        Blocks.nether_brick.getDefaultState(),
        Blocks.nether_brick.getDefaultState(),
        false);
    this.func_175804_a(
        worldIn,
        p_74875_3_,
        1,
        3,
        4,
        7,
        3,
        4,
        Blocks.bookshelf.getDefaultState(),
        Blocks.bookshelf.getDefaultState(),
        false);
    this.func_175811_a(worldIn, Blocks.nether_brick.getDefaultState(), 7, 1, 4, p_74875_3_);
    this.func_175811_a(
        worldIn,
        Blocks.nether_brick_stairs.getStateFromMeta(
            this.getMetadataWithOffset(Blocks.nether_brick_stairs, 0)),
        7,
        1,
        3,
        p_74875_3_);
    k = this.getMetadataWithOffset(Blocks.nether_brick_stairs, 3);
    this.func_175811_a(
        worldIn, Blocks.nether_brick_stairs.getStateFromMeta(k), 6, 1, 4, p_74875_3_);
    this.func_175811_a(
        worldIn, Blocks.nether_brick_stairs.getStateFromMeta(k), 5, 1, 4, p_74875_3_);
    this.func_175811_a(
        worldIn, Blocks.nether_brick_stairs.getStateFromMeta(k), 4, 1, 4, p_74875_3_);
    this.func_175811_a(
        worldIn, Blocks.nether_brick_stairs.getStateFromMeta(k), 3, 1, 4, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.nether_brick_fence.getDefaultState(), 6, 1, 3, p_74875_3_);
    this.func_175811_a(
        worldIn, Blocks.wooden_pressure_plate.getDefaultState(), 6, 2, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.nether_brick_fence.getDefaultState(), 4, 1, 3, p_74875_3_);
    this.func_175811_a(
        worldIn, Blocks.wooden_pressure_plate.getDefaultState(), 4, 2, 3, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.enchanting_table.getDefaultState(), 7, 1, 1, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.air.getDefaultState(), 1, 1, 0, p_74875_3_);
    this.func_175811_a(worldIn, Blocks.air.getDefaultState(), 1, 2, 0, p_74875_3_);
    this.func_175810_a(
        worldIn,
        p_74875_3_,
        p_74875_2_,
        1,
        1,
        0,
        EnumFacing.getHorizontal(this.getMetadataWithOffset(Blocks.oak_door, 1)));

    if (this.func_175807_a(worldIn, 1, 0, -1, p_74875_3_).getBlock().getMaterial() == Material.air
        && this.func_175807_a(worldIn, 1, -1, -1, p_74875_3_).getBlock().getMaterial()
            != Material.air) {
      this.func_175811_a(
          worldIn,
          Blocks.quartz_stairs.getStateFromMeta(
              this.getMetadataWithOffset(Blocks.quartz_stairs, 3)),
          1,
          0,
          -1,
          p_74875_3_);
    }

    for (l = 0; l < 6; ++l) {
      for (int i1 = 0; i1 < 9; ++i1) {
        this.clearCurrentPositionBlocksUpwards(worldIn, i1, 9, l, p_74875_3_);
        this.func_175808_b(worldIn, Blocks.nether_brick.getDefaultState(), i1, -1, l, p_74875_3_);
      }
    }

    this.spawnVillagers(worldIn, p_74875_3_, 2, 1, 2, 1);
    return true;
  }