Drop different items based on tool used to mine
For example, mining stone with your hand now drops nothing, and mining leaves with shears will drop the leaves.
This commit is contained in:
parent
0542b5eb62
commit
9d1f5377ef
@ -19,7 +19,7 @@ namespace TrueCraft.API.Logic
|
||||
string DisplayName { get; }
|
||||
BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware?
|
||||
Tuple<int, int> GetTextureMap(byte metadata);
|
||||
void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server);
|
||||
void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack heldItem);
|
||||
void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
|
@ -17,6 +17,9 @@ namespace TrueCraft.Core.Logic
|
||||
/// </summary>
|
||||
public abstract class BlockProvider : IItemProvider, IBlockProvider
|
||||
{
|
||||
public static IBlockRepository BlockRepository { get; set; }
|
||||
public static IItemRepository ItemRepository { get; set; }
|
||||
|
||||
public virtual void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
|
||||
{
|
||||
// This space intentionally left blank
|
||||
@ -34,18 +37,18 @@ namespace TrueCraft.Core.Logic
|
||||
|
||||
public virtual void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
|
||||
{
|
||||
GenerateDropEntity(descriptor, world, user.Server);
|
||||
GenerateDropEntity(descriptor, world, user.Server, user.SelectedItem);
|
||||
world.SetBlockID(descriptor.Coordinates, 0);
|
||||
}
|
||||
|
||||
public void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server)
|
||||
public void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack item)
|
||||
{
|
||||
var entityManager = server.GetEntityManagerForWorld(world);
|
||||
var items = GetDrop(descriptor);
|
||||
foreach (var item in items)
|
||||
var items = GetDrop(descriptor, item);
|
||||
foreach (var i in items)
|
||||
{
|
||||
if (item.Empty) continue;
|
||||
var entity = new ItemEntity(new Vector3(descriptor.Coordinates) + new Vector3(0.5), item);
|
||||
if (i.Empty) continue;
|
||||
var entity = new ItemEntity(new Vector3(descriptor.Coordinates) + new Vector3(0.5), i);
|
||||
entityManager.SpawnEntity(entity);
|
||||
}
|
||||
}
|
||||
@ -66,7 +69,7 @@ namespace TrueCraft.Core.Logic
|
||||
{
|
||||
if (!IsSupported(descriptor, server, world))
|
||||
{
|
||||
GenerateDropEntity(descriptor, world, server);
|
||||
GenerateDropEntity(descriptor, world, server, ItemStack.EmptyStack);
|
||||
world.SetBlockID(descriptor.Coordinates, 0);
|
||||
}
|
||||
}
|
||||
@ -76,7 +79,7 @@ namespace TrueCraft.Core.Logic
|
||||
// This space intentionally left blank
|
||||
}
|
||||
|
||||
protected virtual ItemStack[] GetDrop(BlockDescriptor descriptor) // TODO: Include tools
|
||||
protected virtual ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
short meta = 0;
|
||||
if (this is ICraftingRecipe)
|
||||
|
@ -27,7 +27,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(0, 0);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(6, 8);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(BedItem.ItemID) };
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(8, 4);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(ClayItem.ItemID, 4) };
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(2, 2);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(CoalItem.ItemID, 1, descriptor.Metadata) };
|
||||
}
|
||||
|
@ -28,9 +28,13 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(11, 0);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(StringItem.ItemID, 1, descriptor.Metadata) };
|
||||
var provider = ItemRepository.GetItemProvider(item.ID);
|
||||
if (provider is SwordItem)
|
||||
return new[] { new ItemStack(StringItem.ItemID, 1, descriptor.Metadata) };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(8, 5);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
if (descriptor.Metadata >= 7)
|
||||
return new[] { new ItemStack(WheatItem.ItemID), new ItemStack(SeedsItem.ItemID, (sbyte)MathHelper.Random.Next(3)) };
|
||||
@ -57,7 +57,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
{
|
||||
if (world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down) != FarmlandBlock.BlockID)
|
||||
{
|
||||
GenerateDropEntity(descriptor, world, server);
|
||||
GenerateDropEntity(descriptor, world, server, ItemStack.EmptyStack);
|
||||
world.SetBlockID(descriptor.Coordinates, 0);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(2, 3);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(DiamondItem.ItemID, 1, descriptor.Metadata) };
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
world.SetBlockID(descriptor.Coordinates, 0);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(ItemID) };
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
|
||||
public override string DisplayName { get { return "Farmland"; } }
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(DirtBlock.BlockID) };
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
}
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new ItemStack[0];
|
||||
}
|
||||
@ -151,7 +151,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
{
|
||||
// For each block we can flow into, generate an item entity if appropriate
|
||||
var provider = world.BlockRepository.GetBlockProvider(world.GetBlockID(target.TargetBlock));
|
||||
provider.GenerateDropEntity(new BlockDescriptor { Coordinates = target.TargetBlock, ID = provider.ID }, world, server);
|
||||
provider.GenerateDropEntity(new BlockDescriptor { Coordinates = target.TargetBlock, ID = provider.ID }, world, server, ItemStack.EmptyStack);
|
||||
// And overwrite the block with a new fluid block.
|
||||
world.SetBlockID(target.TargetBlock, FlowingID);
|
||||
world.SetMetadata(target.TargetBlock, target.Level);
|
||||
|
@ -27,7 +27,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(1, 3);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(9, 6);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(GlowstoneDustItem.ItemID, (sbyte)new Random().Next(2, 4), descriptor.Metadata) };
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(0, 0);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(DirtBlock.BlockID, 1) };
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(3, 1);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
//Gravel has a 10% chance of dropping flint.
|
||||
if (MathHelper.Random.Next(10) == 0)
|
||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(0, 10);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(DyeItem.ItemID, (sbyte)new Random().Next(4, 8), (short)DyeItem.DyeType.LapisLazuli) };
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using TrueCraft.API.Logic;
|
||||
using TrueCraft.API;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.Core.Logic.Items;
|
||||
|
||||
namespace TrueCraft.Core.Logic.Blocks
|
||||
{
|
||||
@ -28,12 +29,18 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(4, 3);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
if (MathHelper.Random.Next(20) == 0) // 5% chance
|
||||
return new[] { new ItemStack(SaplingBlock.BlockID, 1, descriptor.Metadata) };
|
||||
var provider = ItemRepository.GetItemProvider(item.ID);
|
||||
if (provider is ShearsItem)
|
||||
return base.GetDrop(descriptor, item);
|
||||
else
|
||||
return new ItemStack[0];
|
||||
{
|
||||
if (MathHelper.Random.Next(20) == 0) // 5% chance
|
||||
return new[] { new ItemStack(SaplingBlock.BlockID, 1, descriptor.Metadata) };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(1, 4);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(4, 10);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(RedstoneItem.ItemID, 1, descriptor.Metadata) };
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(3, 3);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(RedstoneItem.ItemID, (sbyte)new Random().Next(4, 5), descriptor.Metadata) };
|
||||
}
|
||||
|
@ -78,9 +78,13 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(2, 4);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(SnowballItem.ItemID) };
|
||||
var provider = ItemRepository.GetItemProvider(item.ID);
|
||||
if (provider is ShovelItem)
|
||||
return new[] { new ItemStack(SnowballItem.ItemID) };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using TrueCraft.API.Logic;
|
||||
using TrueCraft.API;
|
||||
using TrueCraft.Core.Logic.Items;
|
||||
|
||||
namespace TrueCraft.Core.Logic.Blocks
|
||||
{
|
||||
@ -23,9 +24,13 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(1, 0);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(CobblestoneBlock.BlockID, 1, descriptor.Metadata) };
|
||||
var provider = ItemRepository.GetItemProvider(item.ID);
|
||||
if (provider is PickaxeItem)
|
||||
return new[] { new ItemStack(CobblestoneBlock.BlockID, 1, descriptor.Metadata) };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(9, 4);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(SugarCanesItem.ItemID) };
|
||||
}
|
||||
@ -80,7 +80,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
{
|
||||
// Destroy self
|
||||
world.SetBlockID(descriptor.Coordinates, 0);
|
||||
GenerateDropEntity(descriptor, world, server);
|
||||
GenerateDropEntity(descriptor, world, server, ItemStack.EmptyStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
return new Tuple<int, int>(7, 2);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(SeedsItem.ItemID, (sbyte)MathHelper.Random.Next(2)) };
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
base.ItemUsedOnBlock(coordinates, item, face, world, user);
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(ID) };
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
world.SetMetadata(descriptor.Coordinates, (byte)(rotation / 22.5));
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(SignItem.ItemID) };
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
world.SetMetadata(descriptor.Coordinates, (byte)MathHelper.DirectionByRotationFlat(user.Entity.Yaw, true));
|
||||
}
|
||||
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||
protected override ItemStack[] GetDrop(BlockDescriptor descriptor, ItemStack item)
|
||||
{
|
||||
return new[] { new ItemStack(SignItem.ItemID) };
|
||||
}
|
||||
|
@ -91,6 +91,8 @@ namespace TrueCraft
|
||||
var itemRepository = new ItemRepository();
|
||||
itemRepository.DiscoverItemProviders();
|
||||
ItemRepository = itemRepository;
|
||||
BlockProvider.ItemRepository = ItemRepository;
|
||||
BlockProvider.BlockRepository = BlockRepository;
|
||||
var craftingRepository = new CraftingRepository();
|
||||
craftingRepository.DiscoverRecipes();
|
||||
CraftingRepository = craftingRepository;
|
||||
|
@ -51,8 +51,7 @@ namespace TrueCraft
|
||||
}
|
||||
catch
|
||||
{
|
||||
//world = new World("default", new StandardGenerator());
|
||||
world = new World("default", new FlatlandGenerator());
|
||||
world = new World("default", new StandardGenerator());
|
||||
world.BlockRepository = Server.BlockRepository;
|
||||
world.Save("world");
|
||||
Server.AddWorld(world);
|
||||
|
Loading…
x
Reference in New Issue
Block a user