public void DecideOwner(BlockProvider blockProvider, Owner owner) { blockProvider.DecideOwner(owner); var address = blockProvider.GetAddress(); blocks[(int)address.y, (int)address.x] = owner; }
public void Configure() { config = new ConfigLoader <WorldConfig>(new[] { "Worlds" }).GetConfig(worldConfig); textureProvider = Voxelmetric.resources.GetTextureProvider(this); blockProvider = Voxelmetric.resources.GetBlockProvider(this); renderMaterial.mainTexture = textureProvider.atlas; }
/// <summary> /// Draws the tile at zoom level <paramref name="zoomLevel"/> with the tile coordinate <paramref name="tileX"/>/<paramref name="tileZ"/>. /// </summary> /// <param name="zoomLevel">Zoom level of the tile, with 0 being the closest zoom available.</param> /// <param name="tileX">X-coordinate of the tile.</param> /// <param name="tileZ">Z-coordinate of the tile.</param> internal void DrawMap(int zoomLevel, int tileX, int tileZ) { // Closest zoom means at the moment 1px = 1 block if (zoomLevel == 0) { // Create a new bitmap int tileSizeX = Math.Min(TileSize, BlockProvider.DimensionX - tileX * TileSize); int tileSizeZ = Math.Min(TileSize, BlockProvider.DimensionZ - tileZ * TileSize); if (tileSizeX <= 0 || tileSizeZ <= 0) { throw new ArgumentException("Tile is out of bounds"); } // Create the bitmap using (var bmp = new Bitmap(TileSize, TileSize)) { for (int x = 0; x < tileSizeX; ++x) { for (int z = 0; z < tileSizeZ; ++z) { var tile = BlockProvider.GetTopBlock(x + tileX * TileSize, z + tileZ * TileSize); bmp.SetPixel(x, z, TileRenderer.GetColor(tile)); } } TileRenderer.SaveBitmap(GetTileName(zoomLevel, tileX, tileZ), bmp); } } else { List <Image> bitmaps = new List <Image>(); using (var bitmap = new Bitmap(TileSize, TileSize)) using (var graphics = Graphics.FromImage(bitmap)) { for (int dx = 0; dx <= 1; ++dx) { for (int dz = 0; dz <= 1; ++dz) { var previousBitmap = TileRenderer.LoadBitmap(GetTileName(zoomLevel, tileX * 2 + dx, tileZ * 2 + dz)); if (previousBitmap != null) { bitmaps.Add(previousBitmap); graphics.DrawImage(previousBitmap, 0, 0); } } } TileRenderer.SaveBitmap(GetTileName(zoomLevel, tileX, tileZ), bitmap); } bitmaps.ForEach(i => i.Dispose()); } }
public override void OnInit(BlockProvider blockProvider) { base.OnInit(blockProvider); air = BlockProvider.AirBlock; Block blk = blockProvider.GetBlock("dirt"); dirt = new BlockData(blk.Type, blk.Solid); blk = blockProvider.GetBlock("grass"); grass = new BlockData(blk.Type, blk.Solid); }
public override void OnInit(BlockProvider blockProvider) { if (connectedMeshConfig.connectsToTypes == null) { connectedMeshConfig.connectsToTypes = new int[connectedMeshConfig.connectsToNames.Length]; for (int i = 0; i < connectedMeshConfig.connectsToNames.Length; i++) { connectedMeshConfig.connectsToTypes[i] = blockProvider.GetType(connectedMeshConfig.connectsToNames[i]); } } }
public async Task <Block> GetLastBlock() { var blockhash = await BlockProvider.GetBestBlockHash(); var block = await GetBlock(blockhash) ?? new Block { Hash = blockhash }; return(block); }
void Start() { UIManager = GetComponent <UIManager>(); BlockProvider = GetComponent <BlockProvider>(); InitializeStage(); // ライフが変化した時のUI処理 this.Life .TakeWhile(life => life >= 0) .Subscribe(life => this.UIManager.UpdateLife(life)); }
/// <summary> /// ブロック配置の初期化 /// </summary> private void InitializeStage() { var blocks = new List <Block>(); // 開始位置とブロックのサイズ var startPosX = -160; var startPosY = -80; var width = 70; var height = 20; // ブロックを生成 // 各ブロックのポジションは開始位置からブロックサイズ分右下にずらす for (int i = 0; i < row; i++) { var posY = startPosY - height * i; for (int j = 0; j < column; j++) { var posX = startPosX + width * j; var position = new Vector2(posX, posY); if (row % 2 == 0) { var color = Color.gray; } else { var color = Color.red; } var block = BlockProvider.Create(this.BlocksArea.GetComponent <RectTransform>(), position, Color.gray); blocks.Add(block); // ブロックがこわれたとき block.OnBroken.Subscribe( score => { this.ScoreManager.UpdateScore(score); // ブロック全部壊したらクリア if (this.ScoreManager.Score == block.Score * row * column) { GameClear(); } }).AddTo(block); } } // ゲームオーバ処理 this.Ground.OnTriggerEnter2DAsObservable() .Subscribe( collider => { Destroy(collider.gameObject); GameOver(); } ); }
public static void GetFirstTransaction(BlockProvider blockProvider, out Block block, out Transaction tx, out IDictionary <UInt256, Transaction> txLookup) { txLookup = new Dictionary <UInt256, Transaction>(); // prior outputs for first transaction GetTransaction(blockProvider, 9, 0, out block, out tx); txLookup.Add(tx.Hash, tx); // first transaction // do this last so its output is what is returned GetTransaction(blockProvider, 170, 1, out block, out tx); txLookup.Add(tx.Hash, tx); }
public override void OnInit(BlockProvider blockProvider) { base.OnInit(blockProvider); if (meshConfig.connectsToTypes == null) { meshConfig.connectsToTypes = new int[meshConfig.connectsToNames.Length]; for (int i = 0; i < meshConfig.connectsToNames.Length; i++) { meshConfig.connectsToTypes[i] = blockProvider.GetType(meshConfig.connectsToNames[i]); } } }
public BlockProvider GetBlockProvider(World world) { //Check for the folder in the dictionary and if it doesn't exist create it BlockProvider blockProvider; if (BlockProviders.TryGetValue(world.config.blockFolder, out blockProvider)) { return(blockProvider); } blockProvider = BlockProvider.Create(world.config.blockFolder, world); BlockProviders.Add(world.config.blockFolder, blockProvider); return(blockProvider); }
void Start() { int width_step = 4; int count = 0; int length = BlockProvider.BLOCKS.Count; foreach (KeyValuePair <string, char[, ]> blueprint in BlockProvider.BLOCKS) { Block block = BlockProvider.Create(blueprint); block.color = m_color; block.transform.parent = this.transform; block.transform.localPosition = new Vector3((count - length / 2) * width_step, 0, 0); count++; } }
private void BeginDigging(Coordinates3D target) { // TODO: Adjust digging time to compensate for latency var block = Game.Client.World.GetBlockId(target); Game.TargetBlock = target; Game.StartDigging = DateTime.UtcNow; Game.EndDigging = Game.StartDigging.AddMilliseconds( BlockProvider.GetHarvestTime(block, Game.Client.Inventory.Hotbar[Game.Client.HotBarSelection].Id, out _)); Game.Client.QueuePacket(new PlayerDiggingPacket( PlayerDiggingPacket.Action.StartDigging, Game.TargetBlock.X, (sbyte)Game.TargetBlock.Y, Game.TargetBlock.Z, Game.HighlightedBlockFace)); NextAnimation = DateTime.UtcNow.AddSeconds(0.25); }
public void Configure() { config = new ConfigLoader <WorldConfig>(new[] { "Worlds" }).GetConfig(worldConfig); VerifyConfig(); textureProvider = Voxelmetric.resources.GetTextureProvider(this); blockProvider = Voxelmetric.resources.GetBlockProvider(this); textureProvider.Init(config); blockProvider.Init(config.blockFolder, this); foreach (var renderMaterial in renderMaterials) { renderMaterial.mainTexture = textureProvider.atlas; } }
static void Main(string[] args) { var provider = new BlockProvider(); Task.Run(() => { provider.Start(); }); while (Console.ReadLine() != "x") { Thread.Sleep(1000); } provider.Stop(); Console.WriteLine("Stopped."); Thread.Sleep(1500); }
public Simulator(ChainType chainType) { // initialize kernel this.kernel = new StandardKernel(); // add logging module this.kernel.Load(new ConsoleLoggingModule()); // log startup this.logger = LogManager.GetCurrentClassLogger(); this.logger.Info($"Starting up: {DateTime.Now}"); this.random = new Random(); this.blockProvider = TestBlockProvider.CreateForRules(chainType); // add storage module this.kernel.Load(new MemoryStorageModule()); // add rules module this.kernel.Load(new RulesModule(chainType)); // by default, don't run scripts in unit tests var rules = this.kernel.Get <ICoreRules>(); rules.IgnoreScripts = true; // initialize the blockchain daemon this.kernel.Bind <CoreDaemon>().ToSelf().InSingletonScope(); this.coreDaemon = this.kernel.Get <CoreDaemon>(); this.coreStorage = this.coreDaemon.CoreStorage; // start the blockchain daemon this.coreDaemon.Start(); // wait for initial work this.coreDaemon.WaitForUpdate(); // verify initial state Assert.AreEqual(0, this.coreDaemon.TargetChainHeight); Assert.AreEqual(rules.ChainParams.GenesisBlock.Hash, this.coreDaemon.TargetChain.LastBlock.Hash); Assert.AreEqual(rules.ChainParams.GenesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlock.Hash); }
public Simulator(ChainType chainType) { // initialize kernel this.kernel = new StandardKernel(); // add logging module this.kernel.Load(new ConsoleLoggingModule()); // log startup this.logger = LogManager.GetCurrentClassLogger(); this.logger.Info($"Starting up: {DateTime.Now}"); this.random = new Random(); this.blockProvider = TestBlockProvider.CreateForRules(chainType); // add storage module this.kernel.Load(new MemoryStorageModule()); // add rules module this.kernel.Load(new RulesModule(chainType)); // by default, don't run scripts in unit tests var rules = this.kernel.Get<ICoreRules>(); rules.IgnoreScripts = true; // initialize the blockchain daemon this.kernel.Bind<CoreDaemon>().ToSelf().InSingletonScope(); this.coreDaemon = this.kernel.Get<CoreDaemon>(); this.coreStorage = this.coreDaemon.CoreStorage; // start the blockchain daemon this.coreDaemon.Start(); // wait for initial work this.coreDaemon.WaitForUpdate(); // verify initial state Assert.AreEqual(0, this.coreDaemon.TargetChainHeight); Assert.AreEqual(rules.ChainParams.GenesisBlock.Hash, this.coreDaemon.TargetChain.LastBlock.Hash); Assert.AreEqual(rules.ChainParams.GenesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlock.Hash); }
public virtual void OnInit(BlockProvider blockProvider) { }
public override void OnInit(BlockProvider blockProvider) { base.OnInit(blockProvider); textures = ((CubeBlockConfig)Config).textures; }
public override void OnInit(BlockProvider blockProvider) { base.OnInit(blockProvider); Custom = true; }
public void DecideBlock(BlockProvider blockProvider) { blockManager.DecideOwner(blockProvider, onwer); }
public BlockProvider InstantiateBlock() { BlockProvider newBlock = Instantiate(basicBlockProvider) as BlockProvider; return(newBlock); }
public static void HandlePlayerDiggingPacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server) { var packet = (PlayerDiggingPacket)_packet; var client = (RemoteClient)_client; var world = _client.World; var position = new Coordinates3D(packet.X, packet.Y, packet.Z); var descriptor = world.GetBlockData(position); var provider = server.BlockRepository.GetBlockProvider(descriptor.ID); short damage; int time; switch (packet.PlayerAction) { case PlayerDiggingPacket.Action.DropItem: // Throwing item if (client.SelectedItem.Empty) { break; } var spawned = client.SelectedItem; spawned.Count = 1; var inventory = client.SelectedItem; inventory.Count--; var item = new ItemEntity(client.Entity.Position + new Vector3(0, PlayerEntity.Height, 0), spawned); item.Velocity = MathHelper.FowardVector(client.Entity.Yaw) * 0.3; client.Inventory[client.SelectedSlot] = inventory; server.GetEntityManagerForWorld(client.World).SpawnEntity(item); break; case PlayerDiggingPacket.Action.StartDigging: foreach (var nearbyClient in server.Clients) // TODO: Send this repeatedly during the course of the digging { var c = (RemoteClient)nearbyClient; if (c.KnownEntities.Contains(client.Entity)) { c.QueuePacket(new AnimationPacket(client.Entity.EntityID, AnimationPacket.PlayerAnimation.SwingArm)); } } if (provider == null) { server.SendMessage(ChatColor.Red + "WARNING: block provider for ID {0} is null (player digging)", descriptor.ID); } else { provider.BlockLeftClicked(descriptor, packet.Face, world, client); } // "But why on Earth does this behavior change if you use shears on leaves?" // "This is poor seperation of concerns" // "Let me do a git blame and flame whoever wrote the next line" // To answer all of those questions, here: // Minecraft sends a player digging packet when the player starts and stops digging a block (two packets) // However, it only sends ONE packet if the block would be mined immediately - which usually is only the case // for blocks that have a hardness equal to zero. // The exception to this rule is shears on leaves. Leaves normally have a hardness of 0.2, but when you mine them // using shears the client only sends the start digging packet and expects them to be mined immediately. // So if you want to blame anyone, send flames to Notch for the stupid idea of not sending "stop digging" packets // for hardness == 0 blocks. time = BlockProvider.GetHarvestTime(descriptor.ID, client.SelectedItem.ID, out damage); if (time <= 20) { provider.BlockMined(descriptor, packet.Face, world, client); break; } client.ExpectedDigComplete = DateTime.UtcNow.AddMilliseconds(time); break; case PlayerDiggingPacket.Action.StopDigging: foreach (var nearbyClient in server.Clients) { var c = (RemoteClient)nearbyClient; if (c.KnownEntities.Contains(client.Entity)) { c.QueuePacket(new AnimationPacket(client.Entity.EntityID, AnimationPacket.PlayerAnimation.None)); } } if (provider != null && descriptor.ID != 0) { time = BlockProvider.GetHarvestTime(descriptor.ID, client.SelectedItem.ID, out damage); if (time <= 20) { break; // Already handled earlier } var diff = (DateTime.UtcNow - client.ExpectedDigComplete).TotalMilliseconds; if (diff > -100) // Allow a small tolerance { provider.BlockMined(descriptor, packet.Face, world, client); // Damage the item if (damage != 0) { var tool = server.ItemRepository.GetItemProvider(client.SelectedItem.ID) as ToolItem; if (tool != null && tool.Uses != -1) { var slot = client.SelectedItem; slot.Metadata += damage; if (slot.Metadata >= tool.Uses) { slot.Count = 0; // Destroy item } client.Inventory[client.SelectedSlot] = slot; } } } } break; } }
public override void OnInit(BlockProvider blockProvider) { base.OnInit(blockProvider); colors = ((ColoredBlockConfig)Config).colors; }
public static void GetTransaction(BlockProvider blockProvider, int blockIndex, int txIndex, out Block block, out Transaction tx) { block = blockProvider.GetBlock(blockIndex); tx = block.Transactions[txIndex]; }
protected override void Init() { base.Init(); if (_articleProvider == null) _articleProvider = new ArticleProvider(); if (_localizationProvider == null) _localizationProvider = new LocalizationProvider(); if (_layoutProvider == null) _layoutProvider = new LayoutProvider(); if (_pageProvider == null) _pageProvider = new PageProvider(); if (_blockProvider == null) _blockProvider = new BlockProvider(); if (IsEdit) { Title = "Edit Article | " + CoreSettings.CurrentSite.Name; ltlTitle.Text = "Edit Article"; } else { Title = "New Article | " + CoreSettings.CurrentSite.Name; ltlTitle.Text = "New Article"; } FillLanguages(); FillPages(); FillLayouts(); }
protected override void Init() { base.Init(); if (_blockProvider == null) _blockProvider = new BlockProvider(); if (_pageProvider == null) _pageProvider = new PageProvider(); if (_pageNBlockProvider == null) _pageNBlockProvider = new PageNBlockProvider(); }
protected override void Init() { base.Init(); if (_layoutProvider == null) _layoutProvider = new LayoutProvider(); if (_layoutWebPartZoneProvider == null) _layoutWebPartZoneProvider = new LayoutWebPartZoneProvider(); if (_webPartProvider == null) _webPartProvider = new WebPartProvider(); if (_blockProvider == null) _blockProvider = new BlockProvider(); if (_layoutNBlockProvider == null) _layoutNBlockProvider = new LayoutNBlockProvider(); if (_localizationProvider == null) _localizationProvider = new LocalizationProvider(); if (IsEdit) { Title = "Edit Block | " + CoreSettings.CurrentSite.Name; ltlTitle.Text = "Edit Block"; } else { Title = "New Block | " + CoreSettings.CurrentSite.Name; ltlTitle.Text = "New Block"; } FillLanguages(); }
public async Task <Block> GetLastBlock() { return(await BlockProvider.GetLastBlock()); }
public void TestInitialize() { provider = new FileSystemBlockProvider(); //provider = new BlockExplorerProvider(); logger = new ScriptLogger(); }
public override void OnInit(BlockProvider blockProvider) { dirt = new BlockData(blockProvider.GetBlock("dirt").type); air = new BlockData(blockProvider.GetBlock("air").type); grass = new BlockData(blockProvider.GetBlock("grass").type); }
public async Task <Block> GetBlock(string id) { return(await BlockProvider.GetBlock(id)); }