Search in sources :

Example 6 with BlockPos

use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenWaterGrass method generate.

public boolean generate(World world, Random rand, int x, int y, int z) {
    while (y > 0) {
        if (!world.isAirBlock(new BlockPos(x, y, z)) || world.getBlockState(new BlockPos(x, y, z)).getBlock().isLeaves(world.getBlockState(new BlockPos(x, y, z)), world, new BlockPos(x, y, z))) {
            break;
        }
        if (y < varMinHeight) {
            return false;
        }
        y--;
    }
    Block b;
    if (blockData == Blocks.DOUBLE_PLANT) {
        int i1, j1, k1;
        for (int l = 0; l < 32; ++l) {
            i1 = x + rand.nextInt(8) - rand.nextInt(8);
            j1 = y + rand.nextInt(2) - rand.nextInt(2);
            k1 = z + rand.nextInt(8) - rand.nextInt(8);
            b = world.getBlockState(new BlockPos(i1, j1 - 1, k1)).getBlock();
            if (((b == Blocks.WATER && world.getBlockState(new BlockPos(i1, j1 - 2, k1)).getBlock() == Blocks.SAND) || b == Blocks.SAND) && world.getBlockState(new BlockPos(i1, j1, k1)).getBlock() == Blocks.AIR) {
                world.setBlockState(new BlockPos(i1, j1 - 1, k1), Blocks.GRASS.getDefaultState(), 0);
            }
            if (world.isAirBlock(new BlockPos(i1, j1, k1)) && j1 < 254 && Blocks.DOUBLE_PLANT.canPlaceBlockAt(world, new BlockPos(i1, j1, k1))) {
                world.setBlockState(new BlockPos(i1, j1, k1), Blocks.DOUBLE_PLANT.getStateFromMeta(varMetadata));
            }
        }
    } else if (blockData == Blocks.LEAVES) {
        for (int l = 0; l < 64; ++l) {
            int i1 = x + rand.nextInt(8) - rand.nextInt(8);
            int j1 = y + rand.nextInt(4) - rand.nextInt(4);
            int k1 = z + rand.nextInt(8) - rand.nextInt(8);
            b = world.getBlockState(new BlockPos(i1, j1 - 1, k1)).getBlock();
            if (((b == Blocks.WATER && world.getBlockState(new BlockPos(i1, j1 - 2, k1)).getBlock() == Blocks.SAND) || b == Blocks.SAND) && world.getBlockState(new BlockPos(i1, j1, k1)).getBlock() == Blocks.AIR) {
                world.setBlockState(new BlockPos(i1, j1 - 1, k1), Blocks.GRASS.getDefaultState(), 0);
            }
            if (world.isAirBlock(new BlockPos(i1, j1, k1)) && world.getBlockState(new BlockPos(i1, j1 - 1, k1)).getBlock() == Blocks.GRASS) {
                world.setBlockState(new BlockPos(i1, j1, k1), BlockUtil.getStateLeaf(varMetadata), 0);
            }
        }
    } else {
        for (int l = 0; l < 128; ++l) {
            int i1 = x + rand.nextInt(8) - rand.nextInt(8);
            int j1 = y + rand.nextInt(4) - rand.nextInt(4);
            int k1 = z + rand.nextInt(8) - rand.nextInt(8);
            b = world.getBlockState(new BlockPos(i1, j1 - 1, k1)).getBlock();
            if (((b == Blocks.WATER && world.getBlockState(new BlockPos(i1, j1 - 2, k1)).getBlock() == Blocks.SAND) || b == Blocks.SAND) && world.getBlockState(new BlockPos(i1, j1, k1)).getBlock() == Blocks.AIR) {
                world.setBlockState(new BlockPos(i1, j1 - 1, k1), Blocks.GRASS.getDefaultState(), 0);
            }
            if (world.isAirBlock(new BlockPos(i1, j1, k1))) //TODO replace this
            // && block.canBlockStay(world, new BlockPos(i1, j1, k1))
            {
                world.setBlockState(new BlockPos(i1, j1, k1), blockData.getStateFromMeta(varMetadata), 0);
            }
        }
    }
    return true;
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with BlockPos

use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.

the class TreeRTGRhizophoraMucronata method generateBranch.

/*
     * horDir = number between -180D and 180D
     * verDir = number between 1F (horizontal) and 0F (vertical)
     */
public void generateBranch(World world, Random rand, float x, float y, float z, double horDir, float verDir, float length, float speed, boolean isTrunk) {
    if (verDir < 0f) {
        verDir = -verDir;
    }
    float c = 0f;
    float velY = 1f - verDir;
    if (verDir > 1f) {
        verDir = 1f - (verDir - 1f);
    }
    float velX = (float) Math.cos(horDir * Math.PI / 180D) * verDir;
    float velZ = (float) Math.sin(horDir * Math.PI / 180D) * verDir;
    while (c < length) {
        if (isTrunk) {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.trunkLog, this.generateFlag);
        } else {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.logBlock, this.generateFlag);
        }
        x += velX;
        y += velY;
        z += velZ;
        c += speed;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 8 with BlockPos

use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.

the class TreeRTGRhizophoraMucronata method generateLeaves.

public void generateLeaves(World world, Random rand, int x, int y, int z, float size, float width) {
    float dist;
    int i, j, k, s = (int) (size - 1f), w = (int) ((size - 1f) * width);
    for (i = -w; i <= w; i++) {
        for (j = -s; j <= s; j++) {
            for (k = -w; k <= w; k++) {
                dist = Math.abs((float) i / width) + (float) Math.abs(j) + Math.abs((float) k / width);
                if (dist <= size - 0.5f || (dist <= size && rand.nextBoolean())) {
                    if (dist < 0.6f) {
                        this.placeLogBlock(world, new BlockPos(x + i, y + j, z + k), this.logBlock, this.generateFlag);
                    }
                    if (!this.noLeaves) {
                        this.placeLeavesBlock(world, new BlockPos(x + i, y + j, z + k), this.leavesBlock, this.generateFlag);
                    }
                }
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with BlockPos

use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.

the class TreeRTGCeibaPentandra method generateBranch.

/*
     * horDir = number between -180D and 180D
     * verDir = number between 1F (horizontal) and 0F (vertical)
     */
public void generateBranch(World world, Random rand, float x, float y, float z, double horDir, float verDir, float length, float speed, boolean isTrunk) {
    if (verDir < 0f) {
        verDir = -verDir;
    }
    float c = 0f;
    float velY = 1f - verDir;
    if (verDir > 1f) {
        verDir = 1f - (verDir - 1f);
    }
    float velX = (float) Math.cos(horDir * Math.PI / 180D) * verDir;
    float velZ = (float) Math.sin(horDir * Math.PI / 180D) * verDir;
    while (c < length) {
        if (isTrunk) {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.trunkLog, this.generateFlag);
        } else {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.logBlock, this.generateFlag);
        }
        x += velX;
        y += velY;
        z += velZ;
        c += speed;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 10 with BlockPos

use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.

the class TreeRTGCeibaRosea method generateBranch.

/*
     * horDir = number between -180D and 180D
     * verDir = number between 1F (horizontal) and 0F (vertical)
     */
public void generateBranch(World world, Random rand, float x, float y, float z, double horDir, float verDir, float length, float speed, boolean isTrunk) {
    if (verDir < 0f) {
        verDir = -verDir;
    }
    float c = 0f;
    float velY = 1f - verDir;
    if (verDir > 1f) {
        verDir = 1f - (verDir - 1f);
    }
    float velX = (float) Math.cos(horDir * Math.PI / 180D) * verDir;
    float velZ = (float) Math.sin(horDir * Math.PI / 180D) * verDir;
    while (c < length) {
        if (isTrunk) {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.trunkLog, this.generateFlag);
        } else {
            this.placeLogBlock(world, new BlockPos((int) x, (int) y, (int) z), this.logBlock, this.generateFlag);
        }
        x += velX;
        y += velY;
        z += velZ;
        c += speed;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)4488 IBlockState (net.minecraft.block.state.IBlockState)1202 TileEntity (net.minecraft.tileentity.TileEntity)675 ItemStack (net.minecraft.item.ItemStack)577 World (net.minecraft.world.World)550 Block (net.minecraft.block.Block)545 EnumFacing (net.minecraft.util.EnumFacing)517 EntityPlayer (net.minecraft.entity.player.EntityPlayer)257 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)249 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)216 Vec3d (net.minecraft.util.math.Vec3d)216 ArrayList (java.util.ArrayList)211 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)182 Entity (net.minecraft.entity.Entity)176 NBTTagList (net.minecraft.nbt.NBTTagList)139 Random (java.util.Random)130 Biome (net.minecraft.world.biome.Biome)129 Nullable (javax.annotation.Nullable)126 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)126 RayTraceResult (net.minecraft.util.math.RayTraceResult)112