46 lines
1.3 KiB
C#

// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
using System;
using ClassicalSharp.Map;
#if USE16_BIT
using BlockID = System.UInt16;
#else
using BlockID = System.Byte;
#endif
namespace ClassicalSharp.Singleplayer {
public class OtherPhysics {
Game game;
World map;
public OtherPhysics(Game game, PhysicsBase physics) {
this.game = game;
map = game.World;
physics.OnPlace[Block.Slab] = HandleSlab;
physics.OnPlace[Block.CobblestoneSlab] = HandleCobblestoneSlab;
}
void HandleSlab(int index, BlockID block) {
if (index < map.Width * map.Length) return; // y < 1
if (map.blocks[index - map.Width * map.Length] != Block.Slab) return;
int x = index % map.Width;
int z = (index / map.Width) % map.Length;
int y = (index / map.Width) / map.Length;
game.UpdateBlock(x, y, z, Block.Air);
game.UpdateBlock(x, y - 1, z, Block.DoubleSlab);
}
void HandleCobblestoneSlab(int index, BlockID block) {
if (index < map.Width * map.Length) return; // y < 1
if (map.blocks[index - map.Width * map.Length] != Block.CobblestoneSlab) return;
int x = index % map.Width;
int z = (index / map.Width) % map.Length;
int y = (index / map.Width) / map.Length;
game.UpdateBlock(x, y, z, Block.Air);
game.UpdateBlock(x, y - 1, z, Block.Cobblestone);
}
}
}