now drop the correct blocks

This commit is contained in:
UnknownShadow200 2017-01-20 10:40:58 +11:00
parent c16dd2f6a3
commit 3f308e2c35

View File

@ -9,6 +9,7 @@ namespace ClassicalSharp.Mode {
Game game;
int score = 0;
byte[] invCount = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 10 };
Random rnd = new Random();
public bool HandlesKeyDown(Key key) { return false; }
@ -16,8 +17,7 @@ namespace ClassicalSharp.Mode {
Vector3I pos = game.SelectedPos.BlockPos;
game.UpdateBlock(pos.X, pos.Y, pos.Z, 0);
game.UserEvents.RaiseBlockChanged(pos, old, 0);
AddToHotbar(old);
HandleDelete(old);
}
public void PickMiddle(byte old) {
@ -39,7 +39,29 @@ namespace ClassicalSharp.Mode {
game.Events.RaiseHeldBlockChanged();
}
void AddToHotbar(byte block) {
void HandleDelete(byte old) {
if (old == Block.Log) {
AddToHotbar(Block.Wood, rnd.Next(3, 6));
} else if (old == Block.CoalOre) {
AddToHotbar(Block.Slab, rnd.Next(1, 4));
} else if (old == Block.IronOre) {
AddToHotbar(Block.Iron, 1);
} else if (old == Block.GoldOre) {
AddToHotbar(Block.Gold, 1);
} else if (old == Block.Grass) {
AddToHotbar(Block.Dirt, 1);
} else if (old == Block.Stone) {
AddToHotbar(Block.Cobblestone, 1);
} else if (old == Block.Leaves) {
if (rnd.Next(1, 16) == 1) { // TODO: is this chance accurate?
AddToHotbar(Block.Sapling, 1);
}
}else {
AddToHotbar(old, 1);
}
}
void AddToHotbar(byte block, int count) {
int index = -1;
byte[] hotbar = game.Inventory.Hotbar;
@ -52,10 +74,14 @@ namespace ClassicalSharp.Mode {
if (hotbar[i] == Block.Invalid) index = i;
}
}
if (index == -1) return; // no free slots
if (index == -1 || invCount[index] >= 99) return; // no free space
hotbar[index] = block;
invCount[index]++; // TODO: do we need to raise an event if changing held block still?
for (int j = 0; j < count; j++) {
if (invCount[index] >= 99) return; // no more count
hotbar[index] = block;
invCount[index]++; // TODO: do we need to raise an event if changing held block still?
// TODO: we need to spawn block models instead
}
}