Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Added some Blocks+Block functionality #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion source/Craft.Net.Logic/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public abstract class Block : Item
private static Dictionary<short, IsSolidOnFaceHandler> IsSolidOnFaceHandlers { get; set; }
private static Dictionary<short, BlockMinedHandler> BlockMinedHandlers { get; set; }
private static Dictionary<short, BlockRightClickedHandler> BlockRightClickedHandlers { get; set; }
//HarvestLevesl: 0=Hand, 1=Wooden Tool, 2= Stone Tool, 3= Iron Tool, 4= Diamond Tool
private int ToolQuality = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an enum please.

//Item Damagevalue, used for blocks to determine subtypes
private int MetaData = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Metadata" is better than "MetaData".


static Block()
{
Expand Down Expand Up @@ -73,7 +77,27 @@ protected void SetPlacementSoundEffect(string soundEffect)
{
BlockPlacementSoundEffects[BlockId] = soundEffect;
}


protected void SetToolQuality(int level)
{
ToolQuality = level;
}

public int GetToolQuality()
{
return ToolQuality;
}

protected void SetMetaData(int meta)
{
MetaData = meta;
}

public int GetMetaData()
{
return MetaData;
}

protected void SetBoundingBoxHandler(BoundingBoxHandler handler)
{
BoundingBoxHandlers[BlockId] = handler;
Expand Down
21 changes: 21 additions & 0 deletions source/Craft.Net.Logic/Blocks/BlockCobble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Craft.Net.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Craft.Net.Logic.Blocks
{
public class BlockCobble : Block
{
public static readonly short ID = 4;
public override short BlockId { get {return ID;}}

public BlockCobble()
: base("minecraft:cobblestone", hardness: 0.8)
{
base.SetToolQuality(1);
base.SetPlacementSoundEffect(SoundEffect.DigStone);
}
}
}
22 changes: 22 additions & 0 deletions source/Craft.Net.Logic/Blocks/BlockStone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Craft.Net.Logic;
using Craft.Net.Common;

namespace Craft.Net.Logic.Blocks
{
public class BlockStone : Block
{
public static readonly short ID = 1;
public override short BlockId { get { return ID; } }

public BlockStone() : base("minecraft:stone", hardness : 1.0)
{
base.SetToolQuality(1);
base.SetPlacementSoundEffect(SoundEffect.DigStone);
base.SetDropHandler((world, coordinates, info) => new[] { new ItemStack(BlockCobble.ID) });
}
}
}
2 changes: 2 additions & 0 deletions source/Craft.Net.Logic/Blocks/DecorativeGrassBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DecorativeGrassBlock : Block

public DecorativeGrassBlock() : base("minecraft:tallgrass")
{
base.SetToolQuality(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good default value is better than explicitly mentioning it for every block.

base.SetBoundingBoxHandler(BoundingBox);
//TODO: Once items are implemented, we need to drop seeds here
//SetDropHandler(Id, (world, coordinates, info) => new[] { new ItemStack(ItemSeeds.Id) });
Expand All @@ -28,6 +29,7 @@ public class TallGrassBlock : Block

public TallGrassBlock() : base("minecraft:tallgrass")
{
base.SetToolQuality(0);
base.SetBoundingBoxHandler(BoundingBox);
}

Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/DirtBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DirtBlock : Block

public DirtBlock() : base("minecraft:dirt", hardness: 0.5)
{
base.SetToolQuality(0);
base.SetPlacementSoundEffect(SoundEffect.DigGrass);
}
}
Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/FlowerBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class YellowFlowerBlock : Block

public YellowFlowerBlock() : base("minecraft:yellow_flower")
{
base.SetHarvestLevel(0);
base.SetBoundingBoxHandler(BoundingBox);
}

Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/GlassBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GlassBlock : Block

public GlassBlock() : base("minecraft:glass", hardness: 0.3)
{
base.SetToolQuality(0);
base.SetPlacementSoundEffect(SoundEffect.RandomGlass);
base.SetDropHandler((world, coordinates, info) => new ItemStack[] { });
}
Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/GrassBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GrassBlock : Block

public GrassBlock() : base("minecraft:grass", hardness: 0.6)
{
base.SetToolQuality(0);
base.SetPlacementSoundEffect(SoundEffect.DigGrass);
base.SetDropHandler((world, coordinates, info) => new[] { new ItemStack(DirtBlock.Id) });
}
Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/LadderBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Orientation

public LadderBlock() : base("minecraft:ladder")
{
base.SetToolQuality(0);
base.SetPlacementSoundEffect(SoundEffect.DigWood);
base.SetBoundingBoxHandler(BoundingBox);
base.SetItemUsedOnBlockHandler(ItemUsedOnBlock);
Expand Down
1 change: 1 addition & 0 deletions source/Craft.Net.Logic/Blocks/WheatBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class WheatBlock : Block

public WheatBlock() : base("minecraft:seeds")
{
base.SetToolQuality(0);
base.SetBoundingBoxHandler(BoundingBox);
}

Expand Down
2 changes: 2 additions & 0 deletions source/Craft.Net.Logic/Craft.Net.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Blocks\BlockCobble.cs" />
<Compile Include="Blocks\BlockStone.cs" />
<Compile Include="Blocks\GlassBlock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Windows\ArmorWindowArea.cs" />
Expand Down