From 6328bfe5b39c9aa45f4e4499cd90506783b26319 Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Fri, 21 Dec 2018 16:00:44 -0800 Subject: [PATCH] Properly remove objects from world by picking up and with destorying them with tools. --- .../Framework/Objects/CustomObject.cs | 37 +++++++++++++++++-- GeneralMods/Revitalize/ModCore.cs | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index b569f9cb..13e0c012 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -74,6 +74,7 @@ namespace Revitalize.Framework.Objects this.updateDrawPosition(); + this.bigCraftable.Value = false; } @@ -134,7 +135,35 @@ namespace Revitalize.Framework.Objects public override bool clicked(Farmer who) { Revitalize.ModCore.log("Clicky click!"); - return base.clicked(who); + + return removeAndAddToPlayersInventory(); + //return base.clicked(who); + } + + public override bool performToolAction(Tool t, GameLocation location) + { + + if(t.GetType()== typeof(StardewValley.Tools.Axe) || t.GetType()== typeof(StardewValley.Tools.Pickaxe)) + { + Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.getDirection()); + Game1.player.currentLocation.removeObject(this.TileLocation, false); + return false; + } + + return false; + //return base.performToolAction(t, location); + } + + public virtual bool removeAndAddToPlayersInventory() + { + if (Game1.player.isInventoryFull()) + { + Game1.showRedMessage("Inventory full."); + return false; + } + Game1.player.currentLocation.removeObject(this.TileLocation, false); + Game1.player.addItemToInventory(this); + return true; } public override Color getCategoryColor() @@ -233,10 +262,12 @@ namespace Revitalize.Framework.Objects double num2 = (double)this.scale.Y > 1.0 ? (double)this.getScale().Y : 4.0; int num3 = (bool)(this.flipped) ? 1 : 0; double num4 = (double)layerDepth; - spriteBatch1.Draw(this.displayTexture, local, sourceRectangle, color, (float)num1, origin, (float)num2, (SpriteEffects)num3, (float)num4); + + spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, color, (float)num1, origin, (float)num2, (SpriteEffects)num3, (float)num4); } + public override void drawAsProp(SpriteBatch b) { @@ -257,7 +288,7 @@ namespace Revitalize.Framework.Objects float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.Quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.Quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); } - spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize), (float)(Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), Color.White * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), 1f * 1 * scaleSize * .5f, SpriteEffects.None, layerDepth); + spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize), (float)(Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), Color.White * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize, SpriteEffects.None, layerDepth); } public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index a98f6f94..46f62943 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -30,7 +30,7 @@ namespace Revitalize private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) { - CustomObject obj = new CustomObject(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.CoreObject",Color.Violet,-300,1,false,100,Vector2.Zero,true,true,"Omegasis.bleh", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(CustomObject),null,new Framework.Graphics.Animations.AnimationManager())); + CustomObject obj = new CustomObject(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.CoreObject",Color.Violet,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.bleh", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(CustomObject),null,new Framework.Graphics.Animations.AnimationManager())); new InventoryItem(obj, 100,1).addToNPCShop("Gus");