public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face.Opposite)); IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer != null && be is BlockEntityToolMold) { BlockEntityToolMold beim = (BlockEntityToolMold)be; if (beim.OnPlayerInteract(byPlayer, blockSel.Face, blockSel.HitPosition)) { handHandling = EnumHandHandling.PreventDefault; } } }
public async Task SaveAsync(BlockModel blockModel) { BlockEntity blockEntity = _mapper.Map <BlockEntity>(blockModel); await _collection.DeleteOneAsync((x) => x.Number == blockEntity.Number); await _collection.InsertOneAsync(blockEntity); }
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 = 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 { return(null); } _cache[inventoryCoord] = inventory; return(inventory); } }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) { if (!byPlayer.Entity.Controls.Sneak || world.BlockAccessor.GetBlockEntity(blockSel.Position.DownCopy()) is ILiquidMetalSink) { failureCode = "__ignore__"; return(false); } if (!CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { return(false); } if (world.BlockAccessor.GetBlock(blockSel.Position.DownCopy()).CanAttachBlockAt(world.BlockAccessor, this, blockSel.Position, BlockFacing.UP)) { DoPlaceBlock(world, byPlayer, blockSel, itemstack); BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntitySmeltedContainer) { BlockEntitySmeltedContainer belmc = (BlockEntitySmeltedContainer)be; KeyValuePair <ItemStack, int> contents = GetContents(world, itemstack); contents.Key.Collectible.SetTemperature(world, contents.Key, GetTemperature(world, itemstack)); belmc.contents = contents.Key.Clone(); belmc.units = contents.Value; } return(true); } failureCode = "requiresolidground"; return(false); }
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 BEBehaviorBurning(BlockEntity be) : base(be) { OnCanBurn = (pos) => { Block block = Api.World.BlockAccessor.GetBlock(pos); return(block?.CombustibleProps != null && block.CombustibleProps.BurnDuration > 0); }; ShouldBurn = () => true; OnFireTick = (dt) => { if (remainingBurnDuration <= 0) { KillFire(true); } }; OnFireDeath = (consumefuel) => { if (consumefuel) { var becontainer = Api.World.BlockAccessor.GetBlockEntity(FuelPos) as BlockEntityContainer; becontainer?.OnBlockBroken(); Api.World.BlockAccessor.SetBlock(0, FuelPos); Api.World.BlockAccessor.TriggerNeighbourBlockUpdate(FuelPos); TrySpreadTo(FuelPos); } Api.World.BlockAccessor.SetBlock(0, FirePos); Api.World.BlockAccessor.TriggerNeighbourBlockUpdate(FirePos); }; }
//will check and see if there is an appropriate heated block in order to generator power bool CheckHeat() { //find heated blocks - firepits, furnaces, burning coal piles heated = false; BlockPos bp = Pos.Copy().Offset(heatFace); BlockEntity checkblock = Api.World.BlockAccessor.GetBlockEntity(bp); if (checkblock == null) { return(false); } //check for hot firepit var checkFirePit = checkblock as BlockEntityFirepit; if (checkFirePit != null) { if (checkFirePit.furnaceTemperature >= requiredHeat) { heated = true; return(true); } } //check for coal piles: Note need to add check for how hot var checkCoalPile = checkblock as BlockEntityCoalPile; if (checkCoalPile != null) { if (checkCoalPile.IsBurning) { heated = true; return(true); } } return(false); }
protected void transferEnergy(BlockFacing side, float dt) { BlockPos outPos = Pos.Copy().Offset(side); BlockEntity tileEntity = Api.World.BlockAccessor.GetBlockEntity(outPos); if (tileEntity == null) { return; } if (!(tileEntity is IFluxStorage)) { return; } if (tileEntity is IEnergyPoint && ((IEnergyPoint)tileEntity).GetCore() == GetCore()) { return; } float eout = Math.Min(MyMiniLib.GetAttributeInt(Block, "transfer", 500) * dt, core.storage.getEnergyStored() * dt); eout = ((IFluxStorage)tileEntity).receiveEnergy(side.Opposite, eout, false, dt); if (tileEntity is IEnergyPoint && eout > 0) { ((IEnergyPoint)tileEntity).AddSkipSide(side.Opposite); } core.storage.modifyEnergyStored(-eout); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { handling = EnumHandling.PreventSubsequent; BlockEntity entity = world.BlockAccessor.GetBlockEntity(blockSel.Position); if (entity is BlockEntityResinVessel) { BlockEntityResinVessel vessel = (BlockEntityResinVessel)entity; if (!vessel.Inventory.Empty) { ItemStack stack = vessel.Inventory[0].TakeOutWhole(); if (!byPlayer.InventoryManager.TryGiveItemstack(stack)) { world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5)); } vessel.UpdateAsset(); return(true); } else { return(false); } } return(false); }
public void SetLargeGear(BlockEntity be) { if (largeGear == null) { largeGear = be.GetBehavior <BEBehaviorMPLargeGear3m>(); } }
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 checkForInteractions() { if (Input.GetButtonDown("Interact")) { // if the player workbench is open then close it and do not // interact if (playerWorkbenchUI.activeSelf) { playerWorkbenchUI.SetActive(false); freeze = false; return; } // look for a block entitty in the range of the player Collider2D collider = Physics2D.OverlapCircle(transform.position, LookUpData.playerRange, whatIsBlockEntity); // if we hit something then open that else open the player workbench if (collider != null) { // get the entity script and tell it we interacted with it BlockEntity blockEntity = (BlockEntity)collider.gameObject.GetComponent(typeof(BlockEntity)); blockEntity.interacted(this); } else { playerWorkbenchUI.SetActive(true); freeze = true; } } }
public override bool BreakBlock(Level world, Player player, Block block, BlockEntity blockEntity) { SetPosition1(player, block.Coordinates); Log.Warn("Break"); return(false); // Will revert block break; }
public void SetBlockEntity(int x, int y, int z, BlockEntity blockEntity) { var coords = new BlockCoordinates(x, y, z); var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; var chunkPos = new BlockCoordinates(cx, cy, cz); var blockAtPos = chunk.GetBlockState(cx, cy, cz); if (blockAtPos.Block.BlockMaterial == Material.Air) { return; } chunk.RemoveBlockEntity(chunkPos); EntityManager.RemoveBlockEntity(coords); chunk.AddBlockEntity(chunkPos, blockEntity); EntityManager.AddBlockEntity(coords, blockEntity); } }
public void BreakBlock(Player player, BlockCoordinates blockCoordinates) { List <ItemStack> drops = new List <ItemStack>(); Block block = GetBlock(blockCoordinates); drops.Add(block.GetDrops()); if (OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops))) { block.BreakBlock(this); BlockEntity blockEnity = GetBlockEntity(blockCoordinates); if (blockEnity != null) { RemoveBlockEntity(blockCoordinates); drops.AddRange(blockEnity.GetDrops()); } foreach (ItemStack drop in drops) { DropItem(blockCoordinates, drop); } } else { var message = McpeUpdateBlock.CreateObject(); message.blocks = new BlockRecords { block }; player.SendPackage(message, true); } }
private void UpdateBlock(bool remove, BlockPos pos) { if (remove) { if (DoRemoveBlock) { World.BlockAccessor.SetBlock(0, pos); World.BlockAccessor.MarkBlockDirty(pos, () => OnChunkRetesselated(true)); } } else { World.BlockAccessor.SetBlock(Block.BlockId, pos); World.BlockAccessor.MarkBlockDirty(pos, () => OnChunkRetesselated(false)); if (blockEntityAttributes != null) { BlockEntity be = World.BlockAccessor.GetBlockEntity(pos); blockEntityAttributes.SetInt("posx", pos.X); blockEntityAttributes.SetInt("posy", pos.Y); blockEntityAttributes.SetInt("posz", pos.Z); if (be != null) { be.FromTreeAttributes(blockEntityAttributes, World); } } } NotifyNeighborsOfBlockChange(pos); }
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); }
public EntityBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos, AssetLocation fallSound, float impactDamageMul, bool canFallSideways, float dustIntensity) { this.impactDamageMul = impactDamageMul; this.fallSound = fallSound; this.canFallSideways = canFallSideways; this.dustIntensity = dustIntensity; WatchedAttributes.SetBool("canFallSideways", canFallSideways); WatchedAttributes.SetFloat("dustIntensity", dustIntensity); if (fallSound != null) { WatchedAttributes.SetString("fallSound", fallSound.ToShortString()); } this.Code = new AssetLocation("blockfalling"); this.blockCode = block.Code; this.removedBlockentity = blockEntity; this.initialPos = initialPos.Copy(); // Must have a Copy() here! ServerPos.SetPos(initialPos); ServerPos.X += 0.5; ServerPos.Z += 0.5; Pos.SetFrom(ServerPos); }
/// <summary> /// Draws a specific BlockEntity with whatever texture is currently bound. /// </summary> /// <param name="entity"></param> private void DrawBlockEntity(BlockEntity entity) { GraphicsManager.DrawQuad(new Vector3d(entity.Position.X - (entity.Width / 2.0), entity.Position.Y + (entity.Height / 2.0), entity.Position.Z), new Vector3d(entity.Position.X + (entity.Width / 2.0), entity.Position.Y + (entity.Height / 2.0), entity.Position.Z), new Vector3d(entity.Position.X + (entity.Width / 2.0), entity.Position.Y - (entity.Height / 2.0), entity.Position.Z), new Vector3d(entity.Position.X - (entity.Width / 2.0), entity.Position.Y - (entity.Height / 2.0), entity.Position.Z)); }
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1) { if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)) { ItemStack[] drops = new ItemStack[] { OnPickBlock(world, pos) }; if (drops != null) { for (int i = 0; i < drops.Length; i++) { world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null); } } world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer); } if (EntityClass != null) { BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos); if (entity != null) { entity.OnBlockBroken(); } } world.BlockAccessor.SetBlock(0, pos); }
/// <summary> /// 添加到黑名单 /// </summary> /// <param name="model">黑名单model</param> /// <returns></returns> public ActionResult AddEntity(Guid typeId, string blockValue) { if (ModelState.IsValid) { var entity = new BlockEntity() { BlockId = Guid.NewGuid(), BlockTypeId = typeId, BlockValue = blockValue, BlockTime = DateTime.Now }; try { var count = _blockEntityHelper.Insert(entity); if (count == 1) { //记录日志 OperLogHelper.AddOperLog(string.Format("添加 {0} 到黑名单", blockValue), OperLogModule.BlockEntity, Username); return(Json(true)); } } catch (Exception ex) { Logger.Error(ex); } return(Json(false)); } else { return(Json(false)); } }
public override void OnBlockExploded(IWorldAccessor world, BlockPos pos, BlockPos explosionCenter, EnumBlastType blastType) { EnumHandling handled = EnumHandling.PassThrough; foreach (BlockBehavior behavior in BlockBehaviors) { behavior.OnBlockExploded(world, pos, explosionCenter, blastType, ref handled); if (handled == EnumHandling.PreventSubsequent) { break; } } if (handled == EnumHandling.PreventDefault) { return; } double dropChancce = ExplosionDropChance(world, pos, blastType); if (world.Rand.NextDouble() < dropChancce) { ItemStack[] drops = GetDrops(world, pos, null); if (drops == null) { return; } for (int i = 0; i < drops.Length; i++) { if (SplitDropStacks) { for (int k = 0; k < drops[i].StackSize; k++) { ItemStack stack = drops[i].Clone(); if (stack.Collectible.Code.Path.Contains("crystal")) { continue; // Do not drop crystalized ores when the ore is being blown up } stack.StackSize = 1; world.SpawnItemEntity(stack, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null); } } } } if (EntityClass != null) { BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos); if (entity != null) { entity.OnBlockBroken(); } } }
public InventoryPulverizer(BlockEntity be, int size) : base(be, size, "pulverizer-0", null) { slots = GenEmptySlots(size); for (int i = 0; i < size; i++) { slots[i].MaxSlotStackSize = 1; } }
public VoxelCircuit(int sizex, int sizey, int sizez, BlockEntity blockEntity) { SIZEX = sizex; SIZEY = sizey; SIZEZ = sizez; myBE = blockEntity; wiring = new VoxelWiring(sizex, sizey); }
private async Task CommitBlock(BlockEntity block) { using (var _db = new BlockContext(_options)) { _db.BlockEntity.Add(block); await _finiteStateMachine.Execute(block.ToBlock(), _db); } }
public async Task <BigInteger> GetLastSyncedBlockAsync() { var sort = Builders <BlockEntity> .Sort.Descending(x => x.Number); //build sort object BlockEntity result = _collection.Find <BlockEntity>(x => true).Sort(sort).FirstOrDefault(); return(new BigInteger(result?.Number ?? 1)); }
public void RemoveBlockEntity(BlockEntity blockEntity) { if (!this.BlockEntities.Contains(blockEntity)) { return; } this.BlockEntities.Remove(blockEntity); }
public async Task <bool> DoesBlockExistAsync(string blockHash) { var filterBuilder = Builders <BlockEntity> .Filter; FilterDefinition <BlockEntity> filter = filterBuilder.Eq(x => x.BlockHash, blockHash); BlockEntity blockEntity = await _collection.Find(filter).FirstOrDefaultAsync(); return(blockEntity != null); }
public void AddBlockEntity(BlockEntity blockEntity) { if (blockEntity.World.Name != this.Name) { return; } this.BlockEntities.Add(blockEntity); }
protected override void DoDeviceComplete() { deviceState = enDeviceState.IDLE; string userecipe = recipe; if (ingredient_subtype != "") { userecipe += "-" + ingredient_subtype; } Block outputBlock = Api.World.GetBlock(new AssetLocation(userecipe)); Item outputItem = Api.World.GetItem(new AssetLocation(userecipe)); if (outputBlock == null && outputItem == null) { deviceState = enDeviceState.ERROR; return; } ItemStack outputStack; if (outputBlock != null) { outputStack = new ItemStack(outputBlock, outputQuantity); } else { outputStack = new ItemStack(outputItem, outputQuantity); } dummy[0].Itemstack = outputStack; outputStack.Collectible.SetTemperature(Api.World, outputStack, lastheatreading); BlockPos bp = Pos.Copy().Offset(outputFace); BlockEntity checkblock = Api.World.BlockAccessor.GetBlockEntity(bp); var outputContainer = checkblock as BlockEntityContainer; if (outputContainer != null) { WeightedSlot tryoutput = outputContainer.Inventory.GetBestSuitedSlot(dummy[0]); if (tryoutput.slot != null) { ItemStackMoveOperation op = new ItemStackMoveOperation(Api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, outputQuantity); dummy[0].TryPutInto(tryoutput.slot, ref op); } } if (!dummy.Empty) { //If no storage then spill on the ground Vec3d pos = Pos.ToVec3d(); dummy.DropAll(pos); } Api.World.PlaySoundAt(new AssetLocation("sounds/doorslide"), Pos.X, Pos.Y, Pos.Z, null, false, 8, 1); if (Api.World.Side == EnumAppSide.Client && animUtil != null) { animUtil.StopAnimation(Pos.ToString() + animationName); } }
static bool IsLastCharge(int chargeCount, BlockEntity blockEntity, BlockCommandEntity blockCommandEntity) { if (chargeCount == blockEntity.maxChargeCount) { return true; } if (blockCommandEntity.maxChargePoint == 0f) { return true; } return false; }
public Matching(PuzzlePanel panel, Pattern pattern, int x, int y, BlockEntity blockEntity, Block[] blocks) { this.panel = panel; this.pattern = pattern; this.x = x; this.y = y; this.blockEntity = blockEntity; this.blocks = blocks; chargeCount = 0; chargePoint = 0; blockCommandEntity = blockCommandTable.Get(blockEntity.HeroType, blockEntity.BlockType, chargeCount); AttachEffect(blockCommandEntity); }
// Use this for initialization void Start() { rigidbody = GetComponent<Rigidbody>(); blockPool = GameObject.Find("BlockPool").GetComponent<BlockPoolController>(); keyAction = GameObject.Find("KeyAction").GetComponent<KeyAction>(); blockEntity = GameObject.Find("BlockEntity").GetComponent<BlockEntity>(); // can vary only y position rigidbody.constraints = ( RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation ); }