예제 #1
0
        private bool TryPlace(Block block, int dx, int dy, int dz)
        {
            IBlockAccessor blockAccess = entity.World.BlockAccessor;
            BlockPos       pos         = entity.ServerPos.XYZ.AsBlockPos.Add(dx, dy, dz);
            Block          blockAtPos  = blockAccess.GetBlock(pos);

            pos.Y--;
            if (blockAtPos.IsReplacableBy(block) && blockAccess.GetSolidBlock(pos.X, pos.Y, pos.Z).CanAttachBlockAt(blockAccess, block, pos, BlockFacing.UP))
            {
                pos.Y++;
                blockAccess.SetBlock(block.BlockId, pos);

                // Instantly despawn the block again if it expired already
                BlockEntityTransient betran = blockAccess.GetBlockEntity(pos) as BlockEntityTransient;
                betran?.SetPlaceTime(TotalHoursUntilPlace);

                if (betran?.IsDueTransition() == true)
                {
                    blockAccess.SetBlock(0, pos);
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
        private bool TryPlace(Block block, int dx, int dy, int dz)
        {
            IBlockAccessor blockAccess = entity.World.BlockAccessor;
            BlockPos       pos         = entity.ServerPos.XYZ.AsBlockPos.Add(dx, dy, dz);
            Block          blockAtPos  = blockAccess.GetBlock(pos);

            if (blockAtPos.IsReplacableBy(block) && blockAccess.GetBlock(pos.X, pos.Y - 1, pos.Z).SideSolid[BlockFacing.UP.Index])
            {
                blockAccess.SetBlock(block.BlockId, pos);

                // Not the most elegant solution, but should work either way
                BlockEntityTransient betran = blockAccess.GetBlockEntity(pos) as BlockEntityTransient;
                if (betran != null)
                {
                    if (!betran.WasPlacedAtTotalHours(TotalHoursUntilPlace))
                    {
                        blockAccess.SetBlock(0, pos);
                    }
                }

                return(true);
            }

            return(false);
        }