Search in sources :

Example 21 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class MovingObjectPosition method fromBlock.

public static MovingObjectPosition fromBlock(int x, int y, int z, int side, Vector3 hitVector) {
    MovingObjectPosition objectPosition = new MovingObjectPosition();
    objectPosition.typeOfHit = 0;
    objectPosition.blockX = x;
    objectPosition.blockY = y;
    objectPosition.blockZ = z;
    objectPosition.hitVector = new Vector3(hitVector.x, hitVector.y, hitVector.z);
    return objectPosition;
}
Also used : Vector3(cn.nukkit.math.Vector3)

Example 22 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class MovingObjectPosition method fromEntity.

public static MovingObjectPosition fromEntity(Entity entity) {
    MovingObjectPosition objectPosition = new MovingObjectPosition();
    objectPosition.typeOfHit = 1;
    objectPosition.entityHit = entity;
    objectPosition.hitVector = new Vector3(entity.x, entity.y, entity.z);
    return objectPosition;
}
Also used : Vector3(cn.nukkit.math.Vector3)

Example 23 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BigMushroom method generate.

public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int block = this.mushroomType;
    if (block < 0) {
        block = rand.nextBoolean() ? RED : BROWN;
    }
    Block mushroom = block == 0 ? new BlockHugeMushroomBrown() : new BlockHugeMushroomRed();
    int i = rand.nextBoundedInt(3) + 4;
    if (rand.nextBoundedInt(12) == 0) {
        i *= 2;
    }
    boolean flag = true;
    if (position.getY() >= 1 && position.getY() + i + 1 < 256) {
        for (int j = position.getFloorY(); j <= position.getY() + 1 + i; ++j) {
            int k = 3;
            if (j <= position.getY() + 3) {
                k = 0;
            }
            Vector3 pos = new Vector3();
            for (int l = position.getFloorX() - k; l <= position.getX() + k && flag; ++l) {
                for (int i1 = position.getFloorZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                    if (j >= 0 && j < 256) {
                        pos.setComponents(l, j, i1);
                        int material = level.getBlockIdAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
                        if (material != Block.AIR && material != Block.LEAVES) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }
        if (!flag) {
            return false;
        } else {
            Vector3 pos2 = position.down();
            int block1 = level.getBlockIdAt(pos2.getFloorX(), pos2.getFloorY(), pos2.getFloorZ());
            if (block1 != Block.DIRT && block1 != Block.GRASS && block1 != Block.MYCELIUM) {
                return false;
            } else {
                int k2 = position.getFloorY() + i;
                if (block == RED) {
                    k2 = position.getFloorY() + i - 3;
                }
                for (int l2 = k2; l2 <= position.getY() + i; ++l2) {
                    int j3 = 1;
                    if (l2 < position.getY() + i) {
                        ++j3;
                    }
                    if (block == BROWN) {
                        j3 = 3;
                    }
                    int k3 = position.getFloorX() - j3;
                    int l3 = position.getFloorX() + j3;
                    int j1 = position.getFloorZ() - j3;
                    int k1 = position.getFloorZ() + j3;
                    for (int l1 = k3; l1 <= l3; ++l1) {
                        for (int i2 = j1; i2 <= k1; ++i2) {
                            int j2 = 5;
                            if (l1 == k3) {
                                --j2;
                            } else if (l1 == l3) {
                                ++j2;
                            }
                            if (i2 == j1) {
                                j2 -= 3;
                            } else if (i2 == k1) {
                                j2 += 3;
                            }
                            int meta = j2;
                            if (block == BROWN || l2 < position.getY() + i) {
                                if ((l1 == k3 || l1 == l3) && (i2 == j1 || i2 == k1)) {
                                    continue;
                                }
                                if (l1 == position.getX() - (j3 - 1) && i2 == j1) {
                                    meta = NORTH_WEST;
                                }
                                if (l1 == k3 && i2 == position.getZ() - (j3 - 1)) {
                                    meta = NORTH_WEST;
                                }
                                if (l1 == position.getX() + (j3 - 1) && i2 == j1) {
                                    meta = NORTH_EAST;
                                }
                                if (l1 == l3 && i2 == position.getZ() - (j3 - 1)) {
                                    meta = NORTH_EAST;
                                }
                                if (l1 == position.getX() - (j3 - 1) && i2 == k1) {
                                    meta = SOUTH_WEST;
                                }
                                if (l1 == k3 && i2 == position.getZ() + (j3 - 1)) {
                                    meta = SOUTH_WEST;
                                }
                                if (l1 == position.getX() + (j3 - 1) && i2 == k1) {
                                    meta = SOUTH_EAST;
                                }
                                if (l1 == l3 && i2 == position.getZ() + (j3 - 1)) {
                                    meta = SOUTH_EAST;
                                }
                            }
                            if (meta == CENTER && l2 < position.getY() + i) {
                                meta = ALL_INSIDE;
                            }
                            if (position.getY() >= position.getY() + i - 1 || meta != ALL_INSIDE) {
                                Vector3 blockPos = new Vector3(l1, l2, i2);
                                if (!Block.solid[level.getBlockIdAt(blockPos.getFloorX(), blockPos.getFloorY(), blockPos.getFloorZ())]) {
                                    mushroom.setDamage(meta);
                                    this.setBlockAndNotifyAdequately(level, blockPos, mushroom);
                                }
                            }
                        }
                    }
                }
                for (int i3 = 0; i3 < i; ++i3) {
                    Vector3 pos = position.up(i3);
                    int id = level.getBlockIdAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
                    if (!Block.solid[id]) {
                        mushroom.setDamage(STEM);
                        this.setBlockAndNotifyAdequately(level, pos, mushroom);
                    }
                }
                return true;
            }
        }
    } else {
        return false;
    }
}
Also used : BlockHugeMushroomBrown(cn.nukkit.block.BlockHugeMushroomBrown) BlockHugeMushroomRed(cn.nukkit.block.BlockHugeMushroomRed) Block(cn.nukkit.block.Block) Vector3(cn.nukkit.math.Vector3)

Example 24 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class HugeTreesGenerator method ensureDirtsUnderneath.

/**
 * returns whether or not there is dirt underneath the block where the tree will be grown.
 * It also generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos.
 */
private boolean ensureDirtsUnderneath(Vector3 pos, ChunkManager worldIn) {
    Vector3 blockpos = pos.down();
    int block = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z);
    if ((block == Block.GRASS || block == Block.DIRT) && pos.getY() >= 2) {
        this.setDirtAt(worldIn, blockpos);
        this.setDirtAt(worldIn, blockpos.east());
        this.setDirtAt(worldIn, blockpos.south());
        this.setDirtAt(worldIn, blockpos.south().east());
        return true;
    } else {
        return false;
    }
}
Also used : Vector3(cn.nukkit.math.Vector3)

Example 25 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class ObjectDarkOakTree method placeTreeOfHeight.

private boolean placeTreeOfHeight(ChunkManager worldIn, Vector3 pos, int height) {
    int i = pos.getFloorX();
    int j = pos.getFloorY();
    int k = pos.getFloorZ();
    Vector3 blockPos = new Vector3();
    for (int l = 0; l <= height + 1; ++l) {
        int i1 = 1;
        if (l == 0) {
            i1 = 0;
        }
        if (l >= height - 1) {
            i1 = 2;
        }
        for (int j1 = -i1; j1 <= i1; ++j1) {
            for (int k1 = -i1; k1 <= i1; ++k1) {
                blockPos.setComponents(i + j1, j + l, k + k1);
                if (!this.canGrowInto(worldIn.getBlockIdAt(blockPos.getFloorX(), blockPos.getFloorY(), blockPos.getFloorZ()))) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Vector3(cn.nukkit.math.Vector3)

Aggregations

Vector3 (cn.nukkit.math.Vector3)62 BlockFace (cn.nukkit.math.BlockFace)16 Block (cn.nukkit.block.Block)5 Player (cn.nukkit.Player)3 Entity (cn.nukkit.entity.Entity)3 BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)3 Random (java.util.Random)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 EntityLiving (cn.nukkit.entity.EntityLiving)2 BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)2 BlockSpreadEvent (cn.nukkit.event.block.BlockSpreadEvent)2 VehicleMoveEvent (cn.nukkit.event.vehicle.VehicleMoveEvent)2 VehicleUpdateEvent (cn.nukkit.event.vehicle.VehicleUpdateEvent)2 ItemBlock (cn.nukkit.item.ItemBlock)2 TranslationContainer (cn.nukkit.lang.TranslationContainer)2 Level (cn.nukkit.level.Level)2 Location (cn.nukkit.level.Location)2 AxisAlignedBB (cn.nukkit.math.AxisAlignedBB)2 NukkitRandom (cn.nukkit.math.NukkitRandom)2 Rail (cn.nukkit.utils.Rail)2