Added support for placing redstone dust, part 2

This commit is contained in:
Ross L 2015-05-08 18:18:07 -04:00
parent 763a789adc
commit 5e707876d8

View File

@ -10,11 +10,6 @@ namespace TrueCraft.Core.Logic.Items
{
public class RedstoneItem : ItemProvider
{
/// <summary>
/// Redstone cannot be placed on any of the following BlockIDs
/// </summary>
protected static byte[] cannotPlace = { RedstoneDustBlock.BlockID, GlassBlock.BlockID, AirBlock.BlockID };
public static readonly short ItemID = 0x14B;
public override short ID { get { return 0x14B; } }
@ -23,24 +18,11 @@ namespace TrueCraft.Core.Logic.Items
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
// TODO: Running backwards and spamming redstone dust sometimes causes redstone to be placed on redstone
coordinates += MathHelper.BlockFaceToCoordinates(face);
IBlockProvider supportingBlock = world.BlockRepository.GetBlockProvider(world.GetBlockID(coordinates + Coordinates3D.Down));
if (face != BlockFace.PositiveY)
if (supportingBlock.Opaque)
{
// Redstone dust cannot be placed anywhere but the top of a block
return;
}
IBlockProvider clickedBlock = world.BlockRepository.GetBlockProvider(world.GetBlockID(coordinates));
if (null != clickedBlock)
{
if (cannotPlace.Any(b => b == clickedBlock.ID))
{
return;
}
coordinates += MathHelper.BlockFaceToCoordinates(face);
world.SetBlockID(coordinates, RedstoneDustBlock.BlockID);
item.Count--;
user.Inventory[user.SelectedSlot] = item;