Esempio n. 1
0
        public override bool Place(Block clicked, Block replace, BlockFace face, Vector3 clickPos, Player player,
                                   Item item)
        {
            int[] faces = { 2, 5, 3, 4 };
            this.Damage = faces[player.GetDirection().GetHorizontalIndex()];
            this.World.SetBlock(this.ToVector3(), this, true);

            CompoundTag nbt = new CompoundTag();

            nbt.PutInt("x", this.X);
            nbt.PutInt("y", this.Y);
            nbt.PutInt("z", this.Z);

            Chunk chunk = this.World.GetChunk(new Tuple <int, int>(this.X >> 4, this.Z >> 4));

            BlockEntity blockEntity = BlockEntity.CreateBlockEntity("chest", chunk, nbt);

            ((BlockEntitySpawnable)blockEntity).SpawnToAll();
            return(true);
        }
Esempio n. 2
0
        public override bool Activate(Player player, Item item)
        {
            BlockEntity blockEntity = this.World.GetBlockEntity(this.ToBlockCoordinate3D());

            if (!(blockEntity is BlockEntityChest))
            {
                CompoundTag nbt = new CompoundTag();
                nbt.PutInt("x", this.X);
                nbt.PutInt("y", this.Y);
                nbt.PutInt("z", this.Z);

                Chunk chunk = this.World.GetChunk(new Tuple <int, int>(this.X >> 4, this.Z >> 4));

                blockEntity = BlockEntity.CreateBlockEntity("chest", chunk, nbt);
                ((BlockEntitySpawnable)blockEntity).SpawnToAll();
            }

            Inventory inventory = ((BlockEntityChest)blockEntity).Inventory;

            player.Inventory.OpenInventory(inventory);
            return(true);
        }
Esempio n. 3
0
        public Chunk(World world, int x, int z, SubChunk[] chunkDatas = null, byte[] biomes = null,
                     short[] heightMap   = null,
                     ListTag entitiesTag = null, ListTag blockEntitiesTag = null)
        {
            this.World = world;
            this.X     = x;
            this.Z     = z;

            if (biomes != null)
            {
                this.Biomes = biomes;
            }

            if (heightMap != null)
            {
                this.HeightMap = heightMap;
            }

            if (chunkDatas != null)
            {
                this.SubChunks = chunkDatas;
            }

            for (int i = 0; i < entitiesTag?.Count; ++i)
            {
                CompoundTag entity = (CompoundTag)entitiesTag[i];
                this.AddEntity(Entity.CreateEntity(entity.GetString("id"), this, entity));
            }

            for (int i = 0; i < blockEntitiesTag?.Count; ++i)
            {
                CompoundTag blockEntity = (CompoundTag)blockEntitiesTag[i];
                this.AddBlockEntity(BlockEntity.CreateBlockEntity(blockEntity.GetString("id").ToLower(), this,
                                                                  blockEntity));
            }
        }