public void SetBlockEntity(BlockEntity blockEntity, bool broadcast = true) { ChunkColumn chunk = _worldProvider.GenerateChunkColumn(new ChunkCoordinates(blockEntity.Coordinates.X >> 4, blockEntity.Coordinates.Z >> 4)); chunk.SetBlockEntity(blockEntity.Coordinates, blockEntity.GetCompound()); if (blockEntity.UpdatesOnTick) { BlockEntities.Add(blockEntity); } if (!broadcast) { return; } Nbt nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, UseVarInt = true, RootTag = blockEntity.GetCompound() } }; var entityData = McpeBlockEntityData.CreateObject(); entityData.namedtag = nbt; entityData.coordinates = blockEntity.Coordinates; RelayBroadcast(entityData); }
public void SetBlockEntity(BlockEntity blockEntity, bool broadcast = true) { ChunkColumn chunk = _worldProvider.GenerateChunkColumn(new ChunkCoordinates(blockEntity.Coordinates.X >> 4, blockEntity.Coordinates.Z >> 4)); chunk.SetBlockEntity(blockEntity.Coordinates, blockEntity.GetCompound()); if (blockEntity.UpdatesOnTick) { BlockEntities.Add(blockEntity); } if (!broadcast) { return; } Nbt nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, RootTag = blockEntity.GetCompound() } }; var entityData = new McpeTileEntityData { namedtag = nbt, x = blockEntity.Coordinates.X, y = (byte)blockEntity.Coordinates.Y, z = blockEntity.Coordinates.Z }; RelayBroadcast(entityData); }
private static void RevertBlockAction(OpenPlayer player, Block block, BlockEntity blockEntity) { var message = McpeUpdateBlock.CreateObject(); message.blockRuntimeId = (uint)block.GetRuntimeId(); message.coordinates = block.Coordinates; message.blockPriority = 0xb; player.SendPacket(message); // Revert block entity if exists if (blockEntity != null) { Nbt nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, RootTag = blockEntity.GetCompound() } }; var entityData = McpeBlockEntityData.CreateObject(); entityData.namedtag = nbt; entityData.coordinates = blockEntity.Coordinates; player.SendPacket(entityData); } }
public Inventory GetInventory(BlockCoordinates inventoryCoord) { lock (_cache) { if (_cache.ContainsKey(inventoryCoord)) { Inventory cachedInventory = _cache[inventoryCoord]; if (cachedInventory != null) { return(cachedInventory); } } BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord); if (blockEntity == null) { return(null); } NbtCompound comp = blockEntity.GetCompound(); Inventory inventory; if (blockEntity is ChestBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"]) { Type = 0, WindowsId = 10, }; } else if (blockEntity is EnchantingTableBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"]) { Type = 4, WindowsId = 12, }; } else if (blockEntity is FurnaceBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 3, (NbtList)comp["Items"]) { Type = 2, WindowsId = 11, }; FurnaceBlockEntity furnace = (FurnaceBlockEntity)blockEntity; furnace.Inventory = inventory; } else { return(null); } _cache[inventoryCoord] = inventory; return(inventory); } }
public void BreakBlock(Player player, BlockCoordinates blockCoordinates) { List <Item> drops = new List <Item>(); Block block = GetBlock(blockCoordinates); BlockEntity blockEntity = GetBlockEntity(blockCoordinates); drops.AddRange(block.GetDrops()); if (!AllowBreak || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops))) { // Revert var message = McpeUpdateBlock.CreateObject(); message.blockId = block.Id; message.coordinates = block.Coordinates; message.blockMetaAndPriority = (byte)(0xb << 4 | (block.Metadata & 0xf)); player.SendPackage(message); // Revert block entity if exists if (blockEntity != null) { Nbt nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, RootTag = blockEntity.GetCompound() } }; var entityData = McpeBlockEntityData.CreateObject(); entityData.namedtag = nbt; entityData.coordinates = blockEntity.Coordinates; player.SendPackage(entityData); } } else { block.BreakBlock(this); if (blockEntity != null) { RemoveBlockEntity(blockCoordinates); drops.AddRange(blockEntity.GetDrops()); } if (player.GameMode != GameMode.Creative) { foreach (Item drop in drops) { DropItem(blockCoordinates, drop); } } player.HungerManager.IncreaseExhaustion(0.025f); } }
public void SetSlot(Player player, byte slot, Item itemStack) { Slots[slot] = itemStack; NbtCompound compound = BlockEntity.GetCompound(); compound["Items"] = GetSlots(); OnInventoryChange(player, slot, itemStack); }
public Inventory GetInventory(BlockCoordinates inventoryCoord) { lock (_cache) { if (_cache.ContainsKey(inventoryCoord)) { Inventory cachedInventory = _cache[inventoryCoord]; if (cachedInventory != null) { return(cachedInventory); } } BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord); if (blockEntity == null) { if (Log.IsDebugEnabled) { Log.Warn($"No blockentity found at {inventoryCoord}"); } return(null); } NbtCompound comp = blockEntity.GetCompound(); Inventory inventory; switch (blockEntity) { case ChestBlockEntity _: case ShulkerBoxBlockEntity _: inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"]) { Type = 0, WindowsId = 10, }; break; case EnchantingTableBlockEntity _: inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"]) { Type = 3, WindowsId = 12, }; break; case FurnaceBlockEntity furnaceBlockEntity: { inventory = new Inventory(GetInventoryId(), furnaceBlockEntity, 3, (NbtList)comp["Items"]) { Type = 2, WindowsId = 11, }; furnaceBlockEntity.Inventory = inventory; break; } case BlastFurnaceBlockEntity furnaceBlockEntity: { inventory = new Inventory(GetInventoryId(), furnaceBlockEntity, 3, (NbtList)comp["Items"]) { Type = 27, WindowsId = 13, }; furnaceBlockEntity.Inventory = inventory; break; } default: { if (Log.IsDebugEnabled) { Log.Warn($"Block entity did not have a matching inventory {blockEntity}"); } return(null); } } _cache[inventoryCoord] = inventory; return(inventory); } }
public Inventory GetInventory(BlockCoordinates inventoryCoord) { lock (_cache) { if (_cache.ContainsKey(inventoryCoord)) { Inventory cachedInventory = _cache[inventoryCoord]; if (cachedInventory != null) { return(cachedInventory); } } BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord); if (blockEntity == null) { if (Log.IsDebugEnabled) { Log.Warn($"No blockentity found at {inventoryCoord}"); } return(null); } NbtCompound comp = blockEntity.GetCompound(); Inventory inventory; if (blockEntity is ChestBlockEntity || blockEntity is ShulkerBoxBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"]) { Type = 0, WindowsId = 10, }; } else if (blockEntity is EnchantingTableBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"]) { Type = 3, WindowsId = 12, }; } else if (blockEntity is FurnaceBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 3, (NbtList)comp["Items"]) { Type = 2, WindowsId = 11, }; FurnaceBlockEntity furnace = (FurnaceBlockEntity)blockEntity; furnace.Inventory = inventory; } else { if (Log.IsDebugEnabled) { Log.Warn($"Block entity did not have a matching inventory {blockEntity}"); } return(null); } _cache[inventoryCoord] = inventory; return(inventory); } }