public void PickBlocks(bool cooldown, bool left, bool middle, bool right) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if (cooldown && delta < 250) { return; // 4 times per second } lastClick = now; Inventory inv = game.Inventory; if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput) { input.pickingId = -1; input.ButtonStateChanged(MouseButton.Left, left); input.ButtonStateChanged(MouseButton.Right, right); input.ButtonStateChanged(MouseButton.Middle, middle); } if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick) { return; } if (left) { // always play delete animations, even if we aren't picking a block. game.HeldBlockRenderer.ClickAnim(true); Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) { return; } game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air); game.UserEvents.RaiseBlockChanged(pos, old, Block.Air); } else if (right) { Vector3I pos = game.SelectedPos.TranslatedPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); BlockID block = inv.Selected; if (game.AutoRotate) { block = AutoRotate.RotateBlock(game, block); } if (game.CanPick(old) || !BlockInfo.CanPlace[block]) { return; } // air-ish blocks can only replace over other air-ish blocks if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas) { return; } if (!PickingHandler.CheckIsFree(game, block)) { return; } game.UpdateBlock(pos.X, pos.Y, pos.Z, block); game.UserEvents.RaiseBlockChanged(pos, old, block); } else if (middle) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID cur = game.World.GetBlock(pos); if (BlockInfo.Draw[cur] == DrawType.Gas) { return; } if (!(BlockInfo.CanPlace[cur] || BlockInfo.CanDelete[cur])) { return; } if (!inv.CanChangeSelected() || inv.Selected == cur) { return; } // Is the currently selected block an empty slot if (inv[inv.SelectedIndex] == Block.Air) { inv.Selected = cur; return; } // Try to replace same block for (int i = 0; i < Inventory.BlocksPerRow; i++) { if (inv[i] != cur) { continue; } inv.SelectedIndex = i; return; } // Try to replace empty slots for (int i = 0; i < Inventory.BlocksPerRow; i++) { if (inv[i] != Block.Air) { continue; } inv[i] = cur; inv.SelectedIndex = i; return; } // Finally, replace the currently selected block. inv.Selected = cur; } }
public void PickBlocks(bool cooldown, bool left, bool middle, bool right) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if (cooldown && delta < 250) { return; // 4 times per second } lastClick = now; Inventory inv = game.Inventory; if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput) { byte targetId = game.Entities.GetClosetPlayer(game.LocalPlayer); input.ButtonStateChanged(MouseButton.Left, left, targetId); input.ButtonStateChanged(MouseButton.Right, right, targetId); input.ButtonStateChanged(MouseButton.Middle, middle, targetId); } int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0); if (buttonsDown > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.HeldBlock == Block.Air) { return; } // always play delete animations, even if we aren't picking a block. if (left) { game.HeldBlockRenderer.anim.SetClickAnim(true); } if (!game.SelectedPos.Valid) { return; } BlockInfo info = game.BlockInfo; if (middle) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.World.IsValidPos(pos)) { return; } byte old = game.World.GetBlock(pos); if (!info.IsAir[old] && (inv.CanPlace[old] || inv.CanDelete[old])) { for (int i = 0; i < inv.Hotbar.Length; i++) { if (inv.Hotbar[i] == old) { inv.HeldBlockIndex = i; return; } } inv.HeldBlock = old; } } else if (left) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.World.IsValidPos(pos)) { return; } byte old = game.World.GetBlock(pos); if (!info.IsAir[old] && inv.CanDelete[old]) { game.UpdateBlock(pos.X, pos.Y, pos.Z, 0); game.UserEvents.RaiseBlockChanged(pos, old, 0); } } else if (right) { Vector3I pos = game.SelectedPos.TranslatedPos; if (!game.World.IsValidPos(pos)) { return; } byte old = game.World.GetBlock(pos); byte block = (byte)inv.HeldBlock; if (!game.CanPick(old) && inv.CanPlace[block] && CheckIsFree(game.SelectedPos, block)) { game.UpdateBlock(pos.X, pos.Y, pos.Z, block); game.UserEvents.RaiseBlockChanged(pos, old, block); } } }
public void PickBlocks(bool cooldown, bool left, bool middle, bool right) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if (cooldown && delta < 250) { return; // 4 times per second } lastClick = now; Inventory inv = game.Inventory; if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput) { input.pickingId = -1; input.ButtonStateChanged(MouseButton.Left, left); input.ButtonStateChanged(MouseButton.Right, right); input.ButtonStateChanged(MouseButton.Middle, middle); } if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick) { return; } if (left) { if (game.Mode.PickingLeft()) { return; } Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) { return; } game.Mode.PickLeft(old); } else if (right) { if (game.Mode.PickingRight()) { return; } Vector3I pos = game.SelectedPos.TranslatedPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); BlockID block = inv.Selected; if (game.AutoRotate) { block = AutoRotate.RotateBlock(game, block); } if (game.CanPick(old) || !BlockInfo.CanPlace[block]) { return; } // air-ish blocks can only replace over other air-ish blocks if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas) { return; } if (!PickingHandler.CheckIsFree(game, block)) { return; } game.Mode.PickRight(old, block); } else if (middle) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); game.Mode.PickMiddle(old); } }
public void PickBlocks(bool cooldown, bool left, bool middle, bool right) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if (cooldown && delta < 250) { return; // 4 times per second } lastClick = now; Inventory inv = game.Inventory; if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput) { input.pickingId = -1; input.ButtonStateChanged(MouseButton.Left, left); input.ButtonStateChanged(MouseButton.Right, right); input.ButtonStateChanged(MouseButton.Middle, middle); } int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0); if (btns > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid) { return; } // always play delete animations, even if we aren't picking a block. if (left) { game.HeldBlockRenderer.anim.SetClickAnim(true); byte id = game.Entities.GetClosetPlayer(game.LocalPlayer); if (id != EntityList.SelfID && game.Mode.PickEntity(id)) { return; } } if (!game.SelectedPos.Valid) { return; } if (middle) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); game.Mode.PickMiddle(old); } else if (left) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); if (game.BlockInfo.Draw[old] == DrawType.Gas || !inv.CanDelete[old]) { return; } game.Mode.PickLeft(old); } else if (right) { Vector3I pos = game.SelectedPos.TranslatedPos; if (!game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); BlockID block = inv.Selected; block = AutoRotate.RotateBlock(game, block); if (game.CanPick(old)) { return; } if (!inv.CanPlace[block] && game.SelectedPos.Block != Block.Chest1 && game.SelectedPos.Block != Block.Chest2 && game.SelectedPos.Block != Block.Chest3 && game.SelectedPos.Block != Block.Chest4) { return; } if (!PickingHandler.CheckIsFree(game, block)) { return; } game.Mode.PickRight(old, block); } }