public void SetUp() { World = new Mock<IWorld>(); Server = new Mock<IMultiplayerServer>(); EntityManager = new Mock<IEntityManager>(); User = new Mock<IRemoteClient>(); BlockRepository = new Mock<IBlockRepository>(); var itemRepository = new ItemRepository(); BlockProvider.BlockRepository = BlockRepository.Object; BlockProvider.ItemRepository = itemRepository; User.SetupGet(u => u.World).Returns(World.Object); User.SetupGet(u => u.Server).Returns(Server.Object); World.Setup(w => w.SetBlockID(It.IsAny<Coordinates3D>(), It.IsAny<byte>())); Server.Setup(s => s.GetEntityManagerForWorld(It.IsAny<IWorld>())) .Returns<IWorld>(w => EntityManager.Object); Server.SetupGet(s => s.BlockRepository).Returns(BlockRepository.Object); EntityManager.Setup(m => m.SpawnEntity(It.IsAny<IEntity>())); }
protected override void Initialize() { InputModules = new List<IGameplayModule>(); GraphicalModules = new List<IGameplayModule>(); base.Initialize(); // (calls LoadContent) White1x1 = new Texture2D(GraphicsDevice, 1, 1); White1x1.SetData<Color>(new[] { Color.White }); Audio = new AudioManager(); Audio.LoadDefaultPacks(Content); ChunkModule = new ChunkModule(this); DebugInfoModule = new DebugInfoModule(this, Pixel); ChatModule = new ChatModule(this, Pixel); var hud = new HUDModule(this, Pixel); var windowModule = new WindowModule(this, Pixel); GraphicalModules.Add(ChunkModule); GraphicalModules.Add(new HighlightModule(this)); GraphicalModules.Add(hud); GraphicalModules.Add(ChatModule); GraphicalModules.Add(windowModule); GraphicalModules.Add(DebugInfoModule); InputModules.Add(windowModule); InputModules.Add(DebugInfoModule); InputModules.Add(ChatModule); InputModules.Add(new HUDModule(this, Pixel)); InputModules.Add(new PlayerControlModule(this)); Client.PropertyChanged += HandleClientPropertyChanged; Client.Connect(EndPoint); BlockProvider.BlockRepository = BlockRepository; var itemRepository = new ItemRepository(); itemRepository.DiscoverItemProviders(); ItemRepository = itemRepository; BlockProvider.ItemRepository = ItemRepository; IconRenderer.CreateBlocks(this, BlockRepository); var centerX = GraphicsDevice.Viewport.Width / 2; var centerY = GraphicsDevice.Viewport.Height / 2; Mouse.SetPosition(centerX, centerY); Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.1f, 1000.0f); UpdateCamera(); MouseComponent.Scroll += OnMouseComponentScroll; MouseComponent.Move += OnMouseComponentMove; MouseComponent.ButtonDown += OnMouseComponentButtonDown; MouseComponent.ButtonUp += OnMouseComponentButtonUp; KeyboardComponent.KeyDown += OnKeyboardKeyDown; KeyboardComponent.KeyUp += OnKeyboardKeyUp; GamePadComponent.ButtonDown += OnGamePadButtonDown; GamePadComponent.ButtonUp += OnGamePadButtonUp; CreateRenderTarget(); SpriteBatch = new SpriteBatch(GraphicsDevice); ThreadID = Thread.CurrentThread.ManagedThreadId; }
/// <summary> /// Gets the time required to mine the given block with the given item. /// </summary> /// <returns>The harvest time in milliseconds.</returns> /// <param name="blockId">Block identifier.</param> /// <param name="itemId">Item identifier.</param> /// <param name="damage">Damage sustained by the item.</param> public static int GetHarvestTime(byte blockId, short itemId, out short damage) { // Reference: // http://minecraft.gamepedia.com/index.php?title=Breaking&oldid=138286 damage = 0; var block = BlockRepository.GetBlockProvider(blockId); var item = ItemRepository.GetItemProvider(itemId); double hardness = block.Hardness; if (hardness == -1) { return(-1); } double time = hardness * 1.5; var tool = ToolType.None; var material = ToolMaterial.None; if (item is ToolItem) { var _ = item as ToolItem; tool = _.ToolType; material = _.Material; if ((block.EffectiveTools & tool) == 0 || (block.EffectiveToolMaterials & material) == 0) { time *= 3.33; // Add time for ineffective tools } if (material != ToolMaterial.None) { switch (material) { case ToolMaterial.Wood: time /= 2; break; case ToolMaterial.Stone: time /= 4; break; case ToolMaterial.Iron: time /= 6; break; case ToolMaterial.Diamond: time /= 8; break; case ToolMaterial.Gold: time /= 12; break; } } damage = 1; if (tool == ToolType.Shovel || tool == ToolType.Axe || tool == ToolType.Pickaxe) { damage = (short)(hardness != 0 ? 1 : 0); } else if (tool == ToolType.Sword) { damage = (short)(hardness != 0 ? 2 : 0); time /= 1.5; if (block is CobwebBlock) { time /= 1.5; } } else if (tool == ToolType.Hoe) { damage = 0; // What? This doesn't seem right } else if (item is ShearsItem) { if (block is WoolBlock) { time /= 5; } else if (block is LeavesBlock || block is CobwebBlock) { time /= 15; } if (block is LeavesBlock || block is CobwebBlock || block is TallGrassBlock) { damage = 1; } else { damage = 0; } } } return((int)(time * 1000)); }