Skip to content

Commit d6efa80

Browse files
committed
corrected breaking speed with axe
1 parent 73a5e96 commit d6efa80

34 files changed

+306
-140
lines changed

src/MiNET/MiNET/Blocks/Barrel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public Barrel() : base(458)
4242
Hardness = 2.5f;
4343
}
4444

45+
public override bool IsBestTool(Item item)
46+
{
47+
return item is ItemAxe ? true : false;
48+
}
49+
4550

4651
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
4752
{

src/MiNET/MiNET/Blocks/Block.cs

Lines changed: 9 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -129,119 +129,12 @@ public int GetRuntimeId()
129129

130130
public virtual Item GetItem()
131131
{
132-
if (!BlockFactory.BlockStates.TryGetValue(GetState(), out BlockStateContainer stateFromPick)) return null;
133-
134-
if (stateFromPick.ItemInstance != null) return ItemFactory.GetItem(stateFromPick.ItemInstance.Id, stateFromPick.ItemInstance.Metadata);
135-
136-
// The rest of this code is to search for an state with the proper value. This is caused by blocks that have lots
137-
// of states, and no easy way to map 1-1 with meta. Expensive, but rare.
138-
139-
// Only compare with states that actually have the values we checking for, and have meta.
140-
var statesWithMeta = BlockFactory.BlockPalette.Values.Where(b => b.Name == stateFromPick.Name && b.Data != -1).ToList();
141-
foreach (IBlockState state in stateFromPick.States.ToArray())
142-
{
143-
bool remove = true;
144-
foreach (BlockStateContainer blockStateContainer in statesWithMeta)
145-
{
146-
foreach (IBlockState currentState in blockStateContainer.States)
147-
{
148-
if (currentState.Name != state.Name) continue;
149-
150-
if (!currentState.Equals(state))
151-
{
152-
remove = false;
153-
break;
154-
}
155-
}
156-
}
157-
if (remove) stateFromPick.States.Remove(state);
158-
}
159-
160-
foreach (BlockStateContainer blockStateContainer in statesWithMeta)
161-
{
162-
bool match = true;
163-
164-
foreach (IBlockState currentState in blockStateContainer.States)
165-
{
166-
if (stateFromPick.States.All(s => s.Name != currentState.Name)) continue;
167-
168-
if (stateFromPick.States.All(state => !state.Equals(currentState)))
169-
{
170-
Log.Debug($"State: {currentState.Name}, {currentState}");
171-
172-
match = false;
173-
break;
174-
}
175-
}
176-
if (match)
177-
{
178-
var id = blockStateContainer.Id;
179-
var meta = blockStateContainer.Data;
180-
181-
var statesWithMetaAndItem = statesWithMeta.Where(b => b.ItemInstance != null).ToList();
182-
var actualState = statesWithMetaAndItem.FirstOrDefault(s => s.Id == id && s.Data == meta && s.ItemInstance != null);
183-
if (actualState == null) break;
184-
return ItemFactory.GetItem(actualState.ItemInstance.Id, actualState.ItemInstance.Metadata);
185-
}
186-
}
187-
188-
// Ok that didn't give an item. Lets try more stuff.
189-
190-
// Remove states that repeat. They can not contribute to a meta-variant.
191-
//BUG: There might be states that have more than one. Don't know.
192-
foreach (BlockStateContainer stateContainer in statesWithMeta)
193-
{
194-
foreach (var state in stateContainer.States.ToArray())
195-
{
196-
var states = statesWithMeta.SelectMany(m => m.States).ToList();
197-
if (states.Count(s => s.Equals(state)) > 1)
198-
{
199-
if (stateFromPick.States.FirstOrDefault(s => s.Name == state.Name) != null)
200-
{
201-
stateFromPick.States.Remove(stateFromPick.States.First(s => s.Name == state.Name));
202-
}
203-
}
204-
}
205-
}
206-
207-
if(stateFromPick.States.Count == 0)
132+
var id = Id;
133+
if (id > 255)
208134
{
209-
var stateToPick = statesWithMeta.FirstOrDefault();
210-
if (stateToPick?.ItemInstance != null)
211-
{
212-
return ItemFactory.GetItem(stateToPick.ItemInstance.Id, stateToPick.ItemInstance.Metadata);
213-
}
214-
}
215-
216-
foreach (BlockStateContainer blockStateContainer in statesWithMeta)
217-
{
218-
bool match = true;
219-
220-
foreach (IBlockState currentState in blockStateContainer.States)
221-
{
222-
if (stateFromPick.States.All(s => s.Name != currentState.Name)) continue;
223-
224-
if (stateFromPick.States.All(state => !state.Equals(currentState)))
225-
{
226-
Log.Debug($"State: {currentState.Name}, {currentState}");
227-
228-
match = false;
229-
break;
230-
}
231-
}
232-
if (match)
233-
{
234-
var id = blockStateContainer.Id;
235-
var meta = blockStateContainer.Data;
236-
237-
var statesWithMetaAndItem = statesWithMeta.Where(b => b.ItemInstance != null).ToList();
238-
var actualState = statesWithMetaAndItem.FirstOrDefault(s => s.Id == id && s.Data == meta && s.ItemInstance != null);
239-
if (actualState == null) break;
240-
return ItemFactory.GetItem(actualState.ItemInstance.Id, actualState.ItemInstance.Metadata);
241-
}
135+
id = -(id - 255);
242136
}
243-
244-
return null;
137+
return ItemFactory.GetItem((short) id, Metadata, 1);
245138
}
246139

247140
public bool CanPlace(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face)
@@ -353,6 +246,11 @@ public virtual Item[] GetDrops(Item tool)
353246
return new[] {item};
354247
}
355248

249+
public virtual bool IsBestTool(Item item)
250+
{
251+
return false;
252+
}
253+
356254
public virtual Item GetSmelt()
357255
{
358256
return null;

src/MiNET/MiNET/Blocks/BlockFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public static Block GetBlockByName(string blockName)
155155
public static Block GetBlockById(int blockId, byte metadata)
156156
{
157157
int runtimeId = (int) GetRuntimeId(blockId, metadata);
158-
if (runtimeId < 0 || runtimeId >= BlockPalette.Count) return null;
159158
BlockStateContainer blockState = BlockPalette[runtimeId];
160159
Block block = GetBlockById(blockState.Id);
161160
block.SetState(blockState.States);

src/MiNET/MiNET/Blocks/BookShelf.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#endregion
2525

26+
using MiNET.Items;
27+
2628
namespace MiNET.Blocks
2729
{
2830
public partial class Bookshelf : Block
@@ -34,5 +36,10 @@ public Bookshelf() : base(47)
3436
Hardness = 1.5f;
3537
IsFlammable = true;
3638
}
39+
40+
public override bool IsBestTool(Item item)
41+
{
42+
return item is ItemAxe ? true : false;
43+
}
3744
}
3845
}

src/MiNET/MiNET/Blocks/Chest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public Chest() : base(54)
3737
{
3838
}
3939

40+
public override bool IsBestTool(Item item)
41+
{
42+
return item is ItemAxe ? true : false;
43+
}
44+
4045
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
4146
{
4247
FacingDirection = ItemBlock.GetFacingDirectionFromEntity(player);

src/MiNET/MiNET/Blocks/Composter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public Composter() : base(468)
1616
Hardness = 0.5f;
1717
}
1818

19+
public override bool IsBestTool(Item item)
20+
{
21+
return item is ItemAxe ? true : false;
22+
}
23+
1924
public override bool Interact(Level level, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
2025
{
2126
//todo: level add possibility

src/MiNET/MiNET/Blocks/Crops.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public override bool Interact(Level level, Player player, BlockCoordinates block
5252
var itemInHand = player.Inventory.GetItemInHand();
5353
if (Growth < MaxGrowth && itemInHand is ItemDye && itemInHand.Metadata == 15)
5454
{
55+
itemInHand.Count--;
56+
player.Inventory.SetInventorySlot(player.Inventory.InHandSlot, itemInHand);
5557
Growth += (byte) new Random().Next(2, 6);
5658
if (Growth > MaxGrowth) Growth = MaxGrowth;
5759

src/MiNET/MiNET/Blocks/DaylightDetector.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#endregion
2525

26+
using MiNET.Items;
27+
2628
namespace MiNET.Blocks
2729
{
2830
public partial class DaylightDetector : Block
@@ -33,5 +35,10 @@ public DaylightDetector() : base(151)
3335
BlastResistance = 1;
3436
Hardness = 0.2f;
3537
}
38+
39+
public override bool IsBestTool(Item item)
40+
{
41+
return item is ItemAxe ? true : false;
42+
}
3643
}
3744
}

src/MiNET/MiNET/Blocks/DoorBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
using System.Numerics;
2727
using log4net;
28+
using MiNET.Items;
2829
using MiNET.Sounds;
2930
using MiNET.Utils.Vectors;
3031
using MiNET.Worlds;
@@ -47,6 +48,7 @@ protected DoorBase(byte id) : base(id)
4748
Hardness = 3;
4849
}
4950

51+
5052
protected override bool CanPlace(Level world, Player player, BlockCoordinates blockCoordinates, BlockCoordinates targetCoordinates, BlockFace face)
5153
{
5254
if (fDirection == 1 || fDirection == 3)

src/MiNET/MiNET/Blocks/DoubleWoodenSlab.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public DoubleWoodenSlab() : base(157)
3636
IsFlammable = true;
3737
}
3838

39+
public override bool IsBestTool(Item item)
40+
{
41+
return item is ItemAxe ? true : false;
42+
}
43+
3944
public override Item[] GetDrops(Item tool)
4045
{
4146
var items = base.GetDrops(tool);

0 commit comments

Comments
 (0)