From d8c2d4c4ceee08e0907a772305982ef8726bb5dd Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 9 Feb 2015 23:01:41 -0700 Subject: [PATCH] Allow water to destroy blocks with no hardness --- TrueCraft.API/Logic/IBlockProvider.cs | 1 + TrueCraft.Core/Logic/BlockProvider.cs | 2 +- TrueCraft.Core/Logic/Blocks/AirBlock.cs | 7 +++++++ TrueCraft.Core/Logic/Blocks/GlassBlock.cs | 6 ++++++ TrueCraft.Core/Logic/Blocks/WaterBlock.cs | 20 ++++++++++++++------ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/TrueCraft.API/Logic/IBlockProvider.cs b/TrueCraft.API/Logic/IBlockProvider.cs index e8562a8..4ea085c 100644 --- a/TrueCraft.API/Logic/IBlockProvider.cs +++ b/TrueCraft.API/Logic/IBlockProvider.cs @@ -16,6 +16,7 @@ namespace TrueCraft.API.Logic string DisplayName { get; } BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware? Tuple GetTextureMap(byte metadata); + void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server); bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user); void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user); void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user); diff --git a/TrueCraft.Core/Logic/BlockProvider.cs b/TrueCraft.Core/Logic/BlockProvider.cs index 6987aef..ad6367f 100644 --- a/TrueCraft.Core/Logic/BlockProvider.cs +++ b/TrueCraft.Core/Logic/BlockProvider.cs @@ -30,7 +30,7 @@ namespace TrueCraft.Core.Logic world.SetBlockID(descriptor.Coordinates, 0); } - protected void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server) + public void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server) { var entityManager = server.GetEntityManagerForWorld(world); var items = GetDrop(descriptor); diff --git a/TrueCraft.Core/Logic/Blocks/AirBlock.cs b/TrueCraft.Core/Logic/Blocks/AirBlock.cs index f9b8c72..f96ed79 100644 --- a/TrueCraft.Core/Logic/Blocks/AirBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/AirBlock.cs @@ -1,4 +1,6 @@ using System; +using TrueCraft.API; +using TrueCraft.API.Logic; namespace TrueCraft.Core.Logic.Blocks { @@ -22,5 +24,10 @@ namespace TrueCraft.Core.Logic.Blocks { return new Tuple(0, 0); } + + protected override ItemStack[] GetDrop(BlockDescriptor descriptor) + { + return new ItemStack[0]; + } } } \ No newline at end of file diff --git a/TrueCraft.Core/Logic/Blocks/GlassBlock.cs b/TrueCraft.Core/Logic/Blocks/GlassBlock.cs index add413d..bfcfc42 100644 --- a/TrueCraft.Core/Logic/Blocks/GlassBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/GlassBlock.cs @@ -1,5 +1,6 @@ using System; using TrueCraft.API.Logic; +using TrueCraft.API; namespace TrueCraft.Core.Logic.Blocks { @@ -23,5 +24,10 @@ namespace TrueCraft.Core.Logic.Blocks { return new Tuple(1, 3); } + + protected override ItemStack[] GetDrop(BlockDescriptor descriptor) + { + return new ItemStack[0]; + } } } \ No newline at end of file diff --git a/TrueCraft.Core/Logic/Blocks/WaterBlock.cs b/TrueCraft.Core/Logic/Blocks/WaterBlock.cs index 646d5c2..be65895 100644 --- a/TrueCraft.Core/Logic/Blocks/WaterBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/WaterBlock.cs @@ -193,8 +193,8 @@ namespace TrueCraft.Core.Logic.Blocks if (Math.Abs(z) + Math.Abs(x) > maxDistance) continue; var check = new Coordinates3D(x, -1, z); - var c = world.GetBlockID(check + coords); - if (c == 0 || c == WaterBlock.BlockID || c == StationaryWaterBlock.BlockID) + var c = world.BlockRepository.GetBlockProvider(world.GetBlockID(check + coords)); + if (!c.Opaque) { if (!LineOfSight(world, check + coords, coords)) continue; @@ -220,18 +220,26 @@ namespace TrueCraft.Core.Logic.Blocks { var location = extraLocations[i]; location.Clamp(1); - var xPotential = world.GetBlockID(new Coordinates3D(location.X, 0, 0) + coords); - if (xPotential == 0) + var xPotential = world.BlockRepository.GetBlockProvider(world.GetBlockID(new Coordinates3D(location.X, 0, 0) + coords)); + if (xPotential.Hardness == 0 && xPotential.ID != WaterBlock.BlockID && xPotential.ID != StationaryWaterBlock.BlockID) { if (PlaceWater(server, new Coordinates3D(location.X, 0, 0) + coords, world, (byte)(meta + 1))) + { spread = true; + xPotential.GenerateDropEntity(new BlockDescriptor + { Coordinates = new Coordinates3D(location.X, 0, 0) + coords, ID = xPotential.ID }, world, server); + } } - var zPotential = world.GetBlockID(new Coordinates3D(0, 0, location.Z) + coords); - if (zPotential == 0) + var zPotential = world.BlockRepository.GetBlockProvider(world.GetBlockID(new Coordinates3D(0, 0, location.Z) + coords)); + if (zPotential.Hardness == 0 && zPotential.ID != WaterBlock.BlockID && zPotential.ID != StationaryWaterBlock.BlockID) { if (PlaceWater(server, new Coordinates3D(0, 0, location.Z) + coords, world, (byte)(meta + 1))) + { spread = true; + zPotential.GenerateDropEntity(new BlockDescriptor + { Coordinates = new Coordinates3D(0, 0, location.Z) + coords, ID = zPotential.ID }, world, server); + } } } if (!spread)