Implement special cases for block drops

This does not include things that require certain tools, such as
cobblestone.
This commit is contained in:
Drew DeVault 2015-02-01 14:30:02 -07:00
parent 12dea4d037
commit e3051a673c
7 changed files with 29 additions and 10 deletions

View File

@ -39,7 +39,7 @@ SharpDevelop or something equally idiot-proof.
## Get Involved ## Get Involved
If you want to keep up with development or contribute, join #truecraft on If you want to keep up with development or contribute, join #truecraft on
irc.esper.net. Pull request will be rejected from authors who have read any irc.esper.net. Pull requests will be rejected from authors who have read any
decompiled official Minecraft code. decompiled official Minecraft code.
## Roadmap ## Roadmap

View File

@ -12,6 +12,8 @@ namespace TrueCraft.API.Entities
Vector3 Position { get; set; } Vector3 Position { get; set; }
float Yaw { get; set; } float Yaw { get; set; }
float Pitch { get; set; } float Pitch { get; set; }
bool Despawned { get; set; }
DateTime SpawnTime { get; set; }
MetadataDictionary Metadata { get; } MetadataDictionary Metadata { get; }
Size Size { get; } Size Size { get; }
bool SendMetadataToClients { get; } bool SendMetadataToClients { get; }

View File

@ -19,7 +19,7 @@ namespace TrueCraft.Core.Entities
SpawnTime = DateTime.Now; SpawnTime = DateTime.Now;
} }
protected DateTime SpawnTime { get; set; } public DateTime SpawnTime { get; set; }
public int EntityID { get; set; } public int EntityID { get; set; }
@ -67,6 +67,8 @@ namespace TrueCraft.Core.Entities
} }
} }
public bool Despawned { get; set; }
public abstract Size Size { get; } public abstract Size Size { get; }
public abstract IPacket SpawnPacket { get; } public abstract IPacket SpawnPacket { get; }

View File

@ -19,13 +19,10 @@ namespace TrueCraft.Core.Entities
{ {
Position = position; Position = position;
Item = item; Item = item;
SpawnTime = DateTime.Now;
} }
public ItemStack Item { get; set; } public ItemStack Item { get; set; }
private DateTime SpawnTime { get; set; }
public override IPacket SpawnPacket public override IPacket SpawnPacket
{ {
get get
@ -109,6 +106,7 @@ namespace TrueCraft.Core.Entities
playerEntity.OnPickUpItem(this); playerEntity.OnPickUpItem(this);
entityManager.DespawnEntity(this); entityManager.DespawnEntity(this);
} }
/* TODO: Merging item entities (this code behaves strangely
var item = nearbyEntities.FirstOrDefault(e => e is ItemEntity var item = nearbyEntities.FirstOrDefault(e => e is ItemEntity
&& e != this && e != this
&& (DateTime.Now - (e as ItemEntity).SpawnTime).TotalSeconds > 1 && (DateTime.Now - (e as ItemEntity).SpawnTime).TotalSeconds > 1
@ -123,7 +121,7 @@ namespace TrueCraft.Core.Entities
newItem.Count += (item as ItemEntity).Item.Count; newItem.Count += (item as ItemEntity).Item.Count;
Item = newItem; Item = newItem;
OnPropertyChanged("Metadata"); OnPropertyChanged("Metadata");
} }*/
} }
} }

View File

@ -25,8 +25,11 @@ namespace TrueCraft.Core.Logic
public virtual void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user) public virtual void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
{ {
var entityManager = user.Server.GetEntityManagerForWorld(world); var entityManager = user.Server.GetEntityManagerForWorld(world);
entityManager.SpawnEntity(new ItemEntity(new Vector3(descriptor.Coordinates) + new Vector3(0.5), var items = GetDrop(descriptor);
new ItemStack(descriptor.ID, 1, descriptor.Metadata))); foreach (var item in items)
{
entityManager.SpawnEntity(new ItemEntity(new Vector3(descriptor.Coordinates) + new Vector3(0.5), item));
}
world.SetBlockID(descriptor.Coordinates, 0); world.SetBlockID(descriptor.Coordinates, 0);
} }
@ -40,6 +43,11 @@ namespace TrueCraft.Core.Logic
// This space intentionally left blank // This space intentionally left blank
} }
protected virtual ItemStack[] GetDrop(BlockDescriptor descriptor) // TODO: Include tools
{
return new[] { new ItemStack(descriptor.ID, 1, descriptor.Metadata) };
}
short IItemProvider.ID short IItemProvider.ID
{ {
get get

View File

@ -1,5 +1,7 @@
using System; using System;
using TrueCraft.API.Logic; using TrueCraft.API.Logic;
using TrueCraft.API;
using TrueCraft.API.World;
namespace TrueCraft.Core.Logic.Blocks namespace TrueCraft.Core.Logic.Blocks
{ {
@ -23,5 +25,10 @@ namespace TrueCraft.Core.Logic.Blocks
{ {
return new Tuple<int, int>(3, 0); return new Tuple<int, int>(3, 0);
} }
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
{
return new[] { new ItemStack(DirtBlock.BlockID, 1) };
}
} }
} }

View File

@ -145,7 +145,7 @@ namespace TrueCraft
public void SpawnEntity(IEntity entity) public void SpawnEntity(IEntity entity)
{ {
entity.SpawnTime = DateTime.Now;
entity.EntityID = NextEntityID++; entity.EntityID = NextEntityID++;
entity.PropertyChanged -= HandlePropertyChanged; entity.PropertyChanged -= HandlePropertyChanged;
entity.PropertyChanged += HandlePropertyChanged; entity.PropertyChanged += HandlePropertyChanged;
@ -168,6 +168,7 @@ namespace TrueCraft
public void DespawnEntity(IEntity entity) public void DespawnEntity(IEntity entity)
{ {
PendingDespawns.Add(entity); PendingDespawns.Add(entity);
entity.Despawned = true;
} }
public IEntity GetEntityByID(int id) public IEntity GetEntityByID(int id)
@ -184,7 +185,8 @@ namespace TrueCraft
{ {
foreach (var e in Entities) foreach (var e in Entities)
{ {
e.Update(this); if (!e.Despawned)
e.Update(this);
} }
} }
} }