using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; using Vintagestory.API.Server; namespace immersive_packed_dirt { public class immersive_packed_dirtModSystem : ModSystem { public override void Start(ICoreAPI api) { base.Start(api); api.RegisterBlockBehaviorClass("ImmersivePackedDirtBehavior", typeof(BlockBehaviorImmersivePackedDirt)); api.Logger.Chat("Registered Soil Mod"); } public class BlockBehaviorImmersivePackedDirt : BlockBehavior { public BlockBehaviorImmersivePackedDirt(Block block) : base(block) { } public AssetLocation packSound = new AssetLocation("game", "thud"); public AssetLocation packedDirt = new AssetLocation("game", "packeddirt"); public BlockSelection targetBlock; //TO DO: //> Show the player the option to shift right click while holding soil. How?? //> Double check correct audio is playing //> Remove Packed Dirt Recipe: "C:\Users\Nate\AppData\Roaming\Vintagestory\assets\survival\recipes\grid\packeddirt.json" public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode) { // Catches attempt to place a block while crouching holding soil, only allows if not crouching with dirt // with placement caught and prevented, only interaction is left. handling = EnumHandling.PreventDefault; ItemStack byItemStack = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack; if (byItemStack == null) return false; var heldBlock = world.BlockAccessor.GetBlock(byItemStack.Collectible.Code); if (byPlayer.Entity.Controls.Sneak && heldBlock.BlockMaterial == EnumBlockMaterial.Soil) { return false; } return true; } public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { //Exchanges block when interacted with ItemStack byItemStack = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack; if (byItemStack == null) return false; var heldBlock = world.BlockAccessor.GetBlock(byItemStack.Collectible.Code); world.Logger.Chat("Detected Place on Soil Block"); if (byPlayer.Entity.Controls.Sneak && heldBlock.BlockMaterial == EnumBlockMaterial.Soil) { world.Logger.Chat("Detected sneaking while holding soil material block"); handling = EnumHandling.PreventDefault; world.Logger.Chat("ExchangePosition: " + blockSel.Position); world.BlockAccessor.SetBlock(world.GetBlock(packedDirt).BlockId, blockSel.Position); world.PlaySoundAt(packSound, byPlayer.Entity); world.Logger.Chat("Finished"); return true; } return false; } } } }