Search in sources :

Example 26 with BlockFace

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

the class BlockHopper method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing = face.getOpposite();
    if (facing == BlockFace.UP) {
        facing = BlockFace.DOWN;
    }
    this.setDamage(facing.getIndex());
    boolean powered = this.level.isBlockPowered(this);
    if (powered == this.isEnabled()) {
        this.setEnabled(!powered);
    }
    this.level.setBlock(this, this);
    CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.HOPPER).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
    new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    return true;
}
Also used : BlockEntityHopper(cn.nukkit.blockentity.BlockEntityHopper) BlockFace(cn.nukkit.math.BlockFace) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 27 with BlockFace

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

the class NewJungleTree method generate.

@Override
public boolean generate(ChunkManager worldIn, NukkitRandom rand, Vector3 vectorPosition) {
    BlockVector3 position = new BlockVector3(vectorPosition.getFloorX(), vectorPosition.getFloorY(), vectorPosition.getFloorZ());
    int i = rand.nextBoundedInt(3) + this.minTreeHeight;
    boolean flag = true;
    if (position.getY() >= 1 && position.getY() + i + 1 <= 256) {
        for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
            int k = 1;
            if (j == position.getY()) {
                k = 0;
            }
            if (j >= position.getY() + 1 + i - 2) {
                k = 2;
            }
            BlockVector3 pos2 = new BlockVector3();
            for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                    if (j >= 0 && j < 256) {
                        pos2.setComponents(l, j, i1);
                        if (!this.canGrowInto(worldIn.getBlockIdAt(pos2.x, pos2.y, pos2.z))) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }
        if (!flag) {
            return false;
        } else {
            BlockVector3 down = position.down();
            int block = worldIn.getBlockIdAt(down.x, down.y, down.z);
            if ((block == Block.GRASS || block == Block.DIRT || block == Block.FARMLAND) && position.getY() < 256 - i - 1) {
                this.setDirtAt(worldIn, down);
                int k2 = 3;
                int l2 = 0;
                for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
                    int i4 = i3 - (position.getY() + i);
                    int j1 = 1 - i4 / 2;
                    for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
                        int l1 = k1 - position.getX();
                        for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
                            int j2 = i2 - position.getZ();
                            if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextBoundedInt(2) != 0 && i4 != 0) {
                                BlockVector3 blockpos = new BlockVector3(k1, i3, i2);
                                int id = worldIn.getBlockIdAt(blockpos.x, blockpos.y, blockpos.z);
                                if (id == Block.AIR || id == Block.LEAVES || id == Block.VINE) {
                                    this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
                                }
                            }
                        }
                    }
                }
                for (int j3 = 0; j3 < i; ++j3) {
                    BlockVector3 up = position.up(j3);
                    int id = worldIn.getBlockIdAt(up.x, up.y, up.z);
                    if (id == Block.AIR || id == Block.LEAVES || id == Block.VINE) {
                        this.setBlockAndNotifyAdequately(worldIn, up, this.metaWood);
                        if (j3 > 0) {
                            if (rand.nextBoundedInt(3) > 0 && isAirBlock(worldIn, position.add(-1, j3, 0))) {
                                this.addVine(worldIn, position.add(-1, j3, 0), 8);
                            }
                            if (rand.nextBoundedInt(3) > 0 && isAirBlock(worldIn, position.add(1, j3, 0))) {
                                this.addVine(worldIn, position.add(1, j3, 0), 2);
                            }
                            if (rand.nextBoundedInt(3) > 0 && isAirBlock(worldIn, position.add(0, j3, -1))) {
                                this.addVine(worldIn, position.add(0, j3, -1), 1);
                            }
                            if (rand.nextBoundedInt(3) > 0 && isAirBlock(worldIn, position.add(0, j3, 1))) {
                                this.addVine(worldIn, position.add(0, j3, 1), 4);
                            }
                        }
                    }
                }
                for (int k3 = position.getY() - 3 + i; k3 <= position.getY() + i; ++k3) {
                    int j4 = k3 - (position.getY() + i);
                    int k4 = 2 - j4 / 2;
                    BlockVector3 pos2 = new BlockVector3();
                    for (int l4 = position.getX() - k4; l4 <= position.getX() + k4; ++l4) {
                        for (int i5 = position.getZ() - k4; i5 <= position.getZ() + k4; ++i5) {
                            pos2.setComponents(l4, k3, i5);
                            if (worldIn.getBlockIdAt(pos2.x, pos2.y, pos2.z) == Block.LEAVES) {
                                BlockVector3 blockpos2 = pos2.west();
                                BlockVector3 blockpos3 = pos2.east();
                                BlockVector3 blockpos4 = pos2.north();
                                BlockVector3 blockpos1 = pos2.south();
                                if (rand.nextBoundedInt(4) == 0 && worldIn.getBlockIdAt(blockpos2.x, blockpos2.y, blockpos2.z) == Block.AIR) {
                                    this.addHangingVine(worldIn, blockpos2, 8);
                                }
                                if (rand.nextBoundedInt(4) == 0 && worldIn.getBlockIdAt(blockpos3.x, blockpos3.y, blockpos3.z) == Block.AIR) {
                                    this.addHangingVine(worldIn, blockpos3, 2);
                                }
                                if (rand.nextBoundedInt(4) == 0 && worldIn.getBlockIdAt(blockpos4.x, blockpos4.y, blockpos4.z) == Block.AIR) {
                                    this.addHangingVine(worldIn, blockpos4, 1);
                                }
                                if (rand.nextBoundedInt(4) == 0 && worldIn.getBlockIdAt(blockpos1.x, blockpos1.y, blockpos1.z) == Block.AIR) {
                                    this.addHangingVine(worldIn, blockpos1, 4);
                                }
                            }
                        }
                    }
                }
                if (rand.nextBoundedInt(5) == 0 && i > 5) {
                    for (int l3 = 0; l3 < 2; ++l3) {
                        for (BlockFace enumfacing : BlockFace.Plane.HORIZONTAL) {
                            if (rand.nextBoundedInt(4 - l3) == 0) {
                                BlockFace enumfacing1 = enumfacing.getOpposite();
                                this.placeCocoa(worldIn, rand.nextBoundedInt(3), position.add(enumfacing1.getXOffset(), i - 5 + l3, enumfacing1.getZOffset()), enumfacing);
                            }
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    } else {
        return false;
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) BlockVector3(cn.nukkit.math.BlockVector3)

Example 28 with BlockFace

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

the class ObjectDarkOakTree method generate.

@Override
public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int i = rand.nextBoundedInt(3) + rand.nextBoundedInt(2) + 6;
    int j = position.getFloorX();
    int k = position.getFloorY();
    int l = position.getFloorZ();
    if (k >= 1 && k + i + 1 < 256) {
        Vector3 blockpos = position.down();
        int block = level.getBlockIdAt(blockpos.getFloorX(), blockpos.getFloorY(), blockpos.getFloorZ());
        if (block != Block.GRASS && block != Block.DIRT) {
            return false;
        } else if (!this.placeTreeOfHeight(level, position, i)) {
            return false;
        } else {
            this.setDirtAt(level, blockpos);
            this.setDirtAt(level, blockpos.east());
            this.setDirtAt(level, blockpos.south());
            this.setDirtAt(level, blockpos.south().east());
            BlockFace enumfacing = BlockFace.Plane.HORIZONTAL.random(rand);
            int i1 = i - rand.nextBoundedInt(4);
            int j1 = 2 - rand.nextBoundedInt(3);
            int k1 = j;
            int l1 = l;
            int i2 = k + i - 1;
            for (int j2 = 0; j2 < i; ++j2) {
                if (j2 >= i1 && j1 > 0) {
                    k1 += enumfacing.getXOffset();
                    l1 += enumfacing.getZOffset();
                    --j1;
                }
                int k2 = k + j2;
                Vector3 blockpos1 = new Vector3(k1, k2, l1);
                int material = level.getBlockIdAt(blockpos1.getFloorX(), blockpos1.getFloorY(), blockpos1.getFloorZ());
                if (material == Block.AIR || material == Block.LEAVES) {
                    this.placeLogAt(level, blockpos1);
                    this.placeLogAt(level, blockpos1.east());
                    this.placeLogAt(level, blockpos1.south());
                    this.placeLogAt(level, blockpos1.east().south());
                }
            }
            for (int i3 = -2; i3 <= 0; ++i3) {
                for (int l3 = -2; l3 <= 0; ++l3) {
                    int k4 = -1;
                    this.placeLeafAt(level, k1 + i3, i2 + k4, l1 + l3);
                    this.placeLeafAt(level, 1 + k1 - i3, i2 + k4, l1 + l3);
                    this.placeLeafAt(level, k1 + i3, i2 + k4, 1 + l1 - l3);
                    this.placeLeafAt(level, 1 + k1 - i3, i2 + k4, 1 + l1 - l3);
                    if ((i3 > -2 || l3 > -1) && (i3 != -1 || l3 != -2)) {
                        k4 = 1;
                        this.placeLeafAt(level, k1 + i3, i2 + k4, l1 + l3);
                        this.placeLeafAt(level, 1 + k1 - i3, i2 + k4, l1 + l3);
                        this.placeLeafAt(level, k1 + i3, i2 + k4, 1 + l1 - l3);
                        this.placeLeafAt(level, 1 + k1 - i3, i2 + k4, 1 + l1 - l3);
                    }
                }
            }
            if (rand.nextBoolean()) {
                this.placeLeafAt(level, k1, i2 + 2, l1);
                this.placeLeafAt(level, k1 + 1, i2 + 2, l1);
                this.placeLeafAt(level, k1 + 1, i2 + 2, l1 + 1);
                this.placeLeafAt(level, k1, i2 + 2, l1 + 1);
            }
            for (int j3 = -3; j3 <= 4; ++j3) {
                for (int i4 = -3; i4 <= 4; ++i4) {
                    if ((j3 != -3 || i4 != -3) && (j3 != -3 || i4 != 4) && (j3 != 4 || i4 != -3) && (j3 != 4 || i4 != 4) && (Math.abs(j3) < 3 || Math.abs(i4) < 3)) {
                        this.placeLeafAt(level, k1 + j3, i2, l1 + i4);
                    }
                }
            }
            for (int k3 = -1; k3 <= 2; ++k3) {
                for (int j4 = -1; j4 <= 2; ++j4) {
                    if ((k3 < 0 || k3 > 1 || j4 < 0 || j4 > 1) && rand.nextBoundedInt(3) <= 0) {
                        int l4 = rand.nextBoundedInt(3) + 2;
                        for (int i5 = 0; i5 < l4; ++i5) {
                            this.placeLogAt(level, new Vector3(j + k3, i2 - i5 - 1, l + j4));
                        }
                        for (int j5 = -1; j5 <= 1; ++j5) {
                            for (int l2 = -1; l2 <= 1; ++l2) {
                                this.placeLeafAt(level, k1 + k3 + j5, i2, l1 + j4 + l2);
                            }
                        }
                        for (int k5 = -2; k5 <= 2; ++k5) {
                            for (int l5 = -2; l5 <= 2; ++l5) {
                                if (Math.abs(k5) != 2 || Math.abs(l5) != 2) {
                                    this.placeLeafAt(level, k1 + k3 + k5, i2 - 1, l1 + j4 + l5);
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    } else {
        return false;
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 29 with BlockFace

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

the class ObjectSavannaTree method generate.

public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int i = rand.nextBoundedInt(3) + rand.nextBoundedInt(3) + 5;
    boolean flag = true;
    if (position.getY() >= 1 && position.getY() + i + 1 <= 256) {
        for (int j = (int) position.getY(); j <= position.getY() + 1 + i; ++j) {
            int k = 1;
            if (j == position.getY()) {
                k = 0;
            }
            if (j >= position.getY() + 1 + i - 2) {
                k = 2;
            }
            Vector3 vector3 = new Vector3();
            for (int l = (int) position.getX() - k; l <= position.getX() + k && flag; ++l) {
                for (int i1 = (int) position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                    if (j >= 0 && j < 256) {
                        vector3.setComponents(l, j, i1);
                        if (!this.canGrowInto(level.getBlockIdAt((int) vector3.x, (int) vector3.y, (int) vector3.z))) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }
        if (!flag) {
            return false;
        } else {
            Vector3 down = position.down();
            int block = level.getBlockIdAt(down.getFloorX(), down.getFloorY(), down.getFloorZ());
            if ((block == Block.GRASS || block == Block.DIRT) && position.getY() < 256 - i - 1) {
                this.setDirtAt(level, position.down());
                BlockFace face = BlockFace.Plane.HORIZONTAL.random(rand);
                int k2 = i - rand.nextBoundedInt(4) - 1;
                int l2 = 3 - rand.nextBoundedInt(3);
                int i3 = position.getFloorX();
                int j1 = position.getFloorZ();
                int k1 = 0;
                for (int l1 = 0; l1 < i; ++l1) {
                    int i2 = position.getFloorY() + l1;
                    if (l1 >= k2 && l2 > 0) {
                        i3 += face.getXOffset();
                        j1 += face.getZOffset();
                        --l2;
                    }
                    Vector3 blockpos = new Vector3(i3, i2, j1);
                    int material = level.getBlockIdAt(blockpos.getFloorX(), blockpos.getFloorY(), blockpos.getFloorZ());
                    if (material == Block.AIR || material == Block.LEAVES) {
                        this.placeLogAt(level, blockpos);
                        k1 = i2;
                    }
                }
                Vector3 blockpos2 = new Vector3(i3, k1, j1);
                for (int j3 = -3; j3 <= 3; ++j3) {
                    for (int i4 = -3; i4 <= 3; ++i4) {
                        if (Math.abs(j3) != 3 || Math.abs(i4) != 3) {
                            this.placeLeafAt(level, blockpos2.add(j3, 0, i4));
                        }
                    }
                }
                blockpos2 = blockpos2.up();
                for (int k3 = -1; k3 <= 1; ++k3) {
                    for (int j4 = -1; j4 <= 1; ++j4) {
                        this.placeLeafAt(level, blockpos2.add(k3, 0, j4));
                    }
                }
                this.placeLeafAt(level, blockpos2.east(2));
                this.placeLeafAt(level, blockpos2.west(2));
                this.placeLeafAt(level, blockpos2.south(2));
                this.placeLeafAt(level, blockpos2.north(2));
                i3 = position.getFloorX();
                j1 = position.getFloorZ();
                BlockFace face1 = BlockFace.Plane.HORIZONTAL.random(rand);
                if (face1 != face) {
                    int l3 = k2 - rand.nextBoundedInt(2) - 1;
                    int k4 = 1 + rand.nextBoundedInt(3);
                    k1 = 0;
                    for (int l4 = l3; l4 < i && k4 > 0; --k4) {
                        if (l4 >= 1) {
                            int j2 = position.getFloorY() + l4;
                            i3 += face1.getXOffset();
                            j1 += face1.getZOffset();
                            Vector3 blockpos1 = new Vector3(i3, j2, j1);
                            int material1 = level.getBlockIdAt(blockpos1.getFloorX(), blockpos1.getFloorY(), blockpos1.getFloorZ());
                            if (material1 == Block.AIR || material1 == Block.LEAVES) {
                                this.placeLogAt(level, blockpos1);
                                k1 = j2;
                            }
                        }
                        ++l4;
                    }
                    if (k1 > 0) {
                        Vector3 blockpos3 = new Vector3(i3, k1, j1);
                        for (int i5 = -2; i5 <= 2; ++i5) {
                            for (int k5 = -2; k5 <= 2; ++k5) {
                                if (Math.abs(i5) != 2 || Math.abs(k5) != 2) {
                                    this.placeLeafAt(level, blockpos3.add(i5, 0, k5));
                                }
                            }
                        }
                        blockpos3 = blockpos3.up();
                        for (int j5 = -1; j5 <= 1; ++j5) {
                            for (int l5 = -1; l5 <= 1; ++l5) {
                                this.placeLeafAt(level, blockpos3.add(j5, 0, l5));
                            }
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    } else {
        return false;
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Aggregations

BlockFace (cn.nukkit.math.BlockFace)29 Vector3 (cn.nukkit.math.Vector3)16 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)3 BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)2 Player (cn.nukkit.Player)1 Block (cn.nukkit.block.Block)1 BlockAir (cn.nukkit.block.BlockAir)1 BlockLiquid (cn.nukkit.block.BlockLiquid)1 BlockWater (cn.nukkit.block.BlockWater)1 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityHopper (cn.nukkit.blockentity.BlockEntityHopper)1 Entity (cn.nukkit.entity.Entity)1 BlockFromToEvent (cn.nukkit.event.block.BlockFromToEvent)1 PlayerBucketEmptyEvent (cn.nukkit.event.player.PlayerBucketEmptyEvent)1 PlayerBucketFillEvent (cn.nukkit.event.player.PlayerBucketFillEvent)1 Item (cn.nukkit.item.Item)1 ItemTool (cn.nukkit.item.ItemTool)1 Level (cn.nukkit.level.Level)1 Position (cn.nukkit.level.Position)1