private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) { if (Context.IsWorldReady && Game1.currentLocation != null && Game1.activeClickableMenu == null && Game1.player.CurrentItem != null && Game1.player.CurrentItem.canBeGivenAsGift() && e.Button.IsActionButton()) { FishPond pond = GetPondAtTile(Game1.currentLocation, e.Cursor.GrabTile); if (pond != null && !pond.isUnderConstruction()) { Monitor.Log($"Trying to add an item ({Game1.player.CurrentItem.ParentSheetIndex}) to a pond of type {pond.fishType.Value}.", LogLevel.Trace); if (pond.fishType.Value == -1 || pond.fishType.Value == Game1.player.CurrentItem.ParentSheetIndex) { if (pond.currentOccupants.Value >= pond.maxOccupants.Value) { Monitor.Log("Right item, but pond is full.", LogLevel.Trace); Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\Buildings:PondFull")); Helper.Input.Suppress(e.Button); } else { bool success = Helper.Reflection.GetMethod(pond, "addFishToPond").Invoke <bool>(Game1.player, Game1.player.ActiveObject); Monitor.Log("Pond is empty or pond contains this item with room for more so we tried to add it. Success? {success}.", LogLevel.Trace); if (success) { Helper.Input.Suppress(e.Button); } } } else { Monitor.Log("This is not the right item for this pond. Mod will ignore it and not suppress the click.", LogLevel.Trace); } } } }
private bool IsEmpty(FishPond pond) { // We do this check a lot so here's a helper return(pond != null && pond.fishType.Value == -1 && pond.currentOccupants == 0 && !pond.isUnderConstruction()); }