mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add block material database
Taken from Bukkit's Material class, with credits. Allows to know types and properties of blocks. + Use database for "is solid" checks + Add "can harm players" method + Faster movements, falling seems natural now + Shorter error message when ping failed
This commit is contained in:
parent
5d8d42e3d1
commit
49702e30b8
6 changed files with 367 additions and 30 deletions
|
|
@ -46,13 +46,13 @@ namespace MinecraftClient.Mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the block can be passed through or not
|
/// Material of the block
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Solid
|
public Material Type
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return BlockId != 0;
|
return (Material)BlockId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,22 +71,18 @@ namespace MinecraftClient.Mapping
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a block of the specified type and metadata
|
/// Get a block of the specified type and metadata
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="typeAndMeta"></param>
|
/// <param name="typeAndMeta">Type and metadata packed in the same value</param>
|
||||||
public Block(ushort typeAndMeta)
|
public Block(ushort typeAndMeta)
|
||||||
{
|
{
|
||||||
this.blockIdAndMeta = typeAndMeta;
|
this.blockIdAndMeta = typeAndMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an empty block
|
/// Get a block of the specified type and metadata
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Block Air
|
/// <param name="type">Block type</param>
|
||||||
{
|
public Block(Material type, byte metadata = 0)
|
||||||
get
|
: this((short)type, metadata) { }
|
||||||
{
|
|
||||||
return new Block(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// String representation of the block
|
/// String representation of the block
|
||||||
|
|
|
||||||
346
MinecraftClient/Mapping/Material.cs
Normal file
346
MinecraftClient/Mapping/Material.cs
Normal file
|
|
@ -0,0 +1,346 @@
|
||||||
|
namespace MinecraftClient.Mapping
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents Minecraft Materials
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Mostly ported from CraftBukkit's Material class
|
||||||
|
/// </remarks>
|
||||||
|
/// <see href="https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/Material.java"/>
|
||||||
|
public enum Material
|
||||||
|
{
|
||||||
|
Air = 0,
|
||||||
|
Stone = 1,
|
||||||
|
Grass = 2,
|
||||||
|
Dirt = 3,
|
||||||
|
Cobblestone = 4,
|
||||||
|
Wood = 5,
|
||||||
|
Sapling = 6,
|
||||||
|
Bedrock = 7,
|
||||||
|
Water = 8,
|
||||||
|
StationaryWater = 9,
|
||||||
|
Lava = 10,
|
||||||
|
StationaryLava = 11,
|
||||||
|
Sand = 12,
|
||||||
|
Gravel = 13,
|
||||||
|
GoldOre = 14,
|
||||||
|
IronOre = 15,
|
||||||
|
CoalOre = 16,
|
||||||
|
Log = 17,
|
||||||
|
Leaves = 18,
|
||||||
|
Sponge = 19,
|
||||||
|
Glass = 20,
|
||||||
|
LapisOre = 21,
|
||||||
|
LapisBlock = 22,
|
||||||
|
Dispenser = 23,
|
||||||
|
Sandstone = 24,
|
||||||
|
NoteBlock = 25,
|
||||||
|
BedBlock = 26,
|
||||||
|
PoweredRail = 27,
|
||||||
|
DetectorRail = 28,
|
||||||
|
PistonStickyBase = 29,
|
||||||
|
Web = 30,
|
||||||
|
LongGrass = 31,
|
||||||
|
DeadBush = 32,
|
||||||
|
PistonBase = 33,
|
||||||
|
PistonExtension = 34,
|
||||||
|
Wool = 35,
|
||||||
|
PistonMovingPiece = 36,
|
||||||
|
YellowFlower = 37,
|
||||||
|
RedRose = 38,
|
||||||
|
BrownMushroom = 39,
|
||||||
|
RedMushroom = 40,
|
||||||
|
GoldBlock = 41,
|
||||||
|
IronBlock = 42,
|
||||||
|
DoubleStep = 43,
|
||||||
|
Step = 44,
|
||||||
|
Brick = 45,
|
||||||
|
Tnt = 46,
|
||||||
|
Bookshelf = 47,
|
||||||
|
MossyCobblestone = 48,
|
||||||
|
Obsidian = 49,
|
||||||
|
Torch = 50,
|
||||||
|
Fire = 51,
|
||||||
|
MobSpawner = 52,
|
||||||
|
WoodStairs = 53,
|
||||||
|
Chest = 54,
|
||||||
|
RedstoneWire = 55,
|
||||||
|
DiamondOre = 56,
|
||||||
|
DiamondBlock = 57,
|
||||||
|
Workbench = 58,
|
||||||
|
Crops = 59,
|
||||||
|
Soil = 60,
|
||||||
|
Furnace = 61,
|
||||||
|
BurningFurnace = 62,
|
||||||
|
SignPost = 63,
|
||||||
|
WoodenDoor = 64,
|
||||||
|
Ladder = 65,
|
||||||
|
Rails = 66,
|
||||||
|
CobblestoneStairs = 67,
|
||||||
|
WallSign = 68,
|
||||||
|
Lever = 69,
|
||||||
|
StonePlate = 70,
|
||||||
|
IronDoorBlock = 71,
|
||||||
|
WoodPlate = 72,
|
||||||
|
RedstoneOre = 73,
|
||||||
|
GlowingRedstoneOre = 74,
|
||||||
|
RedstoneTorchOff = 75,
|
||||||
|
RedstoneTorchOn = 76,
|
||||||
|
StoneButton = 77,
|
||||||
|
Snow = 78,
|
||||||
|
Ice = 79,
|
||||||
|
SnowBlock = 80,
|
||||||
|
Cactus = 81,
|
||||||
|
Clay = 82,
|
||||||
|
SugarCaneBlock = 83,
|
||||||
|
Jukebox = 84,
|
||||||
|
Fence = 85,
|
||||||
|
Pumpkin = 86,
|
||||||
|
Netherrack = 87,
|
||||||
|
SoulSand = 88,
|
||||||
|
Glowstone = 89,
|
||||||
|
Portal = 90,
|
||||||
|
JackOLantern = 91,
|
||||||
|
CakeBlock = 92,
|
||||||
|
DiodeBlockOff = 93,
|
||||||
|
DiodeBlockOn = 94,
|
||||||
|
StainedGlass = 95,
|
||||||
|
TrapDoor = 96,
|
||||||
|
MonsterEggs = 97,
|
||||||
|
SmoothBrick = 98,
|
||||||
|
HugeMushroom1 = 99,
|
||||||
|
HugeMushroom2 = 100,
|
||||||
|
IronFence = 101,
|
||||||
|
ThinGlass = 102,
|
||||||
|
MelonBlock = 103,
|
||||||
|
PumpkinStem = 104,
|
||||||
|
MelonStem = 105,
|
||||||
|
Vine = 106,
|
||||||
|
FenceGate = 107,
|
||||||
|
BrickStairs = 108,
|
||||||
|
SmoothStairs = 109,
|
||||||
|
Mycel = 110,
|
||||||
|
WaterLily = 111,
|
||||||
|
NetherBrick = 112,
|
||||||
|
NetherFence = 113,
|
||||||
|
NetherBrickStairs = 114,
|
||||||
|
NetherWarts = 115,
|
||||||
|
EnchantmentTable = 116,
|
||||||
|
BrewingStand = 117,
|
||||||
|
Cauldron = 118,
|
||||||
|
EnderPortal = 119,
|
||||||
|
EnderPortalFrame = 120,
|
||||||
|
EnderStone = 121,
|
||||||
|
DragonEgg = 122,
|
||||||
|
RedstoneLampOff = 123,
|
||||||
|
RedstoneLampOn = 124,
|
||||||
|
WoodDoubleStep = 125,
|
||||||
|
WoodStep = 126,
|
||||||
|
Cocoa = 127,
|
||||||
|
SandstoneStairs = 128,
|
||||||
|
EmeraldOre = 129,
|
||||||
|
EnderChest = 130,
|
||||||
|
TripwireHook = 131,
|
||||||
|
Tripwire = 132,
|
||||||
|
EmeraldBlock = 133,
|
||||||
|
SpruceWoodStairs = 134,
|
||||||
|
BirchWoodStairs = 135,
|
||||||
|
JungleWoodStairs = 136,
|
||||||
|
Command = 137,
|
||||||
|
Beacon = 138,
|
||||||
|
CobbleWall = 139,
|
||||||
|
FlowerPot = 140,
|
||||||
|
Carrot = 141,
|
||||||
|
Potato = 142,
|
||||||
|
WoodButton = 143,
|
||||||
|
Skull = 144,
|
||||||
|
Anvil = 145,
|
||||||
|
TrappedChest = 146,
|
||||||
|
GoldPlate = 147,
|
||||||
|
IronPlate = 148,
|
||||||
|
RedstoneComparatorOff = 149,
|
||||||
|
RedstoneComparatorOn = 150,
|
||||||
|
DaylightDetector = 151,
|
||||||
|
RedstoneBlock = 152,
|
||||||
|
QuartzOre = 153,
|
||||||
|
Hopper = 154,
|
||||||
|
QuartzBlock = 155,
|
||||||
|
QuartzStairs = 156,
|
||||||
|
ActivatorRail = 157,
|
||||||
|
Dropper = 158,
|
||||||
|
StainedClay = 159,
|
||||||
|
StainedGlassPane = 160,
|
||||||
|
Leaves2 = 161,
|
||||||
|
Log2 = 162,
|
||||||
|
AcaciaStairs = 163,
|
||||||
|
DarkOakStairs = 164,
|
||||||
|
HayBlock = 170,
|
||||||
|
Carpet = 171,
|
||||||
|
HardClay = 172,
|
||||||
|
CoalBlock = 173,
|
||||||
|
PackedIce = 174,
|
||||||
|
DoublePlant = 175
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines extension methods for the Material enumeration
|
||||||
|
/// </summary>
|
||||||
|
public static class MaterialExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the player cannot pass through the specified material
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="m">Material to test</param>
|
||||||
|
/// <returns>True if the material is harmful</returns>
|
||||||
|
public static bool IsSolid(this Material m)
|
||||||
|
{
|
||||||
|
switch (m)
|
||||||
|
{
|
||||||
|
case Material.Stone:
|
||||||
|
case Material.Grass:
|
||||||
|
case Material.Dirt:
|
||||||
|
case Material.Cobblestone:
|
||||||
|
case Material.Wood:
|
||||||
|
case Material.Bedrock:
|
||||||
|
case Material.Sand:
|
||||||
|
case Material.Gravel:
|
||||||
|
case Material.GoldOre:
|
||||||
|
case Material.IronOre:
|
||||||
|
case Material.CoalOre:
|
||||||
|
case Material.Log:
|
||||||
|
case Material.Leaves:
|
||||||
|
case Material.Sponge:
|
||||||
|
case Material.Glass:
|
||||||
|
case Material.LapisOre:
|
||||||
|
case Material.LapisBlock:
|
||||||
|
case Material.Dispenser:
|
||||||
|
case Material.Sandstone:
|
||||||
|
case Material.NoteBlock:
|
||||||
|
case Material.BedBlock:
|
||||||
|
case Material.PistonStickyBase:
|
||||||
|
case Material.PistonBase:
|
||||||
|
case Material.PistonExtension:
|
||||||
|
case Material.Wool:
|
||||||
|
case Material.PistonMovingPiece:
|
||||||
|
case Material.GoldBlock:
|
||||||
|
case Material.IronBlock:
|
||||||
|
case Material.DoubleStep:
|
||||||
|
case Material.Step:
|
||||||
|
case Material.Brick:
|
||||||
|
case Material.Tnt:
|
||||||
|
case Material.Bookshelf:
|
||||||
|
case Material.MossyCobblestone:
|
||||||
|
case Material.Obsidian:
|
||||||
|
case Material.MobSpawner:
|
||||||
|
case Material.WoodStairs:
|
||||||
|
case Material.Chest:
|
||||||
|
case Material.DiamondOre:
|
||||||
|
case Material.DiamondBlock:
|
||||||
|
case Material.Workbench:
|
||||||
|
case Material.Soil:
|
||||||
|
case Material.Furnace:
|
||||||
|
case Material.BurningFurnace:
|
||||||
|
case Material.SignPost:
|
||||||
|
case Material.WoodenDoor:
|
||||||
|
case Material.CobblestoneStairs:
|
||||||
|
case Material.WallSign:
|
||||||
|
case Material.StonePlate:
|
||||||
|
case Material.IronDoorBlock:
|
||||||
|
case Material.WoodPlate:
|
||||||
|
case Material.RedstoneOre:
|
||||||
|
case Material.GlowingRedstoneOre:
|
||||||
|
case Material.Ice:
|
||||||
|
case Material.SnowBlock:
|
||||||
|
case Material.Cactus:
|
||||||
|
case Material.Clay:
|
||||||
|
case Material.Jukebox:
|
||||||
|
case Material.Fence:
|
||||||
|
case Material.Pumpkin:
|
||||||
|
case Material.Netherrack:
|
||||||
|
case Material.SoulSand:
|
||||||
|
case Material.Glowstone:
|
||||||
|
case Material.JackOLantern:
|
||||||
|
case Material.CakeBlock:
|
||||||
|
case Material.StainedGlass:
|
||||||
|
case Material.TrapDoor:
|
||||||
|
case Material.MonsterEggs:
|
||||||
|
case Material.SmoothBrick:
|
||||||
|
case Material.HugeMushroom1:
|
||||||
|
case Material.HugeMushroom2:
|
||||||
|
case Material.IronFence:
|
||||||
|
case Material.ThinGlass:
|
||||||
|
case Material.MelonBlock:
|
||||||
|
case Material.FenceGate:
|
||||||
|
case Material.BrickStairs:
|
||||||
|
case Material.SmoothStairs:
|
||||||
|
case Material.Mycel:
|
||||||
|
case Material.NetherBrick:
|
||||||
|
case Material.NetherFence:
|
||||||
|
case Material.NetherBrickStairs:
|
||||||
|
case Material.EnchantmentTable:
|
||||||
|
case Material.BrewingStand:
|
||||||
|
case Material.Cauldron:
|
||||||
|
case Material.EnderPortalFrame:
|
||||||
|
case Material.EnderStone:
|
||||||
|
case Material.DragonEgg:
|
||||||
|
case Material.RedstoneLampOff:
|
||||||
|
case Material.RedstoneLampOn:
|
||||||
|
case Material.WoodDoubleStep:
|
||||||
|
case Material.WoodStep:
|
||||||
|
case Material.SandstoneStairs:
|
||||||
|
case Material.EmeraldOre:
|
||||||
|
case Material.EnderChest:
|
||||||
|
case Material.EmeraldBlock:
|
||||||
|
case Material.SpruceWoodStairs:
|
||||||
|
case Material.BirchWoodStairs:
|
||||||
|
case Material.JungleWoodStairs:
|
||||||
|
case Material.Command:
|
||||||
|
case Material.Beacon:
|
||||||
|
case Material.CobbleWall:
|
||||||
|
case Material.Anvil:
|
||||||
|
case Material.TrappedChest:
|
||||||
|
case Material.GoldPlate:
|
||||||
|
case Material.IronPlate:
|
||||||
|
case Material.DaylightDetector:
|
||||||
|
case Material.RedstoneBlock:
|
||||||
|
case Material.QuartzOre:
|
||||||
|
case Material.Hopper:
|
||||||
|
case Material.QuartzBlock:
|
||||||
|
case Material.QuartzStairs:
|
||||||
|
case Material.Dropper:
|
||||||
|
case Material.StainedClay:
|
||||||
|
case Material.HayBlock:
|
||||||
|
case Material.HardClay:
|
||||||
|
case Material.CoalBlock:
|
||||||
|
case Material.StainedGlassPane:
|
||||||
|
case Material.Leaves2:
|
||||||
|
case Material.Log2:
|
||||||
|
case Material.AcaciaStairs:
|
||||||
|
case Material.DarkOakStairs:
|
||||||
|
case Material.PackedIce:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if contact with the provided material can harm players
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="m">Material to test</param>
|
||||||
|
/// <returns>True if the material is harmful</returns>
|
||||||
|
public static bool CanHarmPlayers(this Material m)
|
||||||
|
{
|
||||||
|
switch (m)
|
||||||
|
{
|
||||||
|
case Material.Fire:
|
||||||
|
case Material.Cactus:
|
||||||
|
case Material.StationaryLava:
|
||||||
|
case Material.StationaryWater:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ namespace MinecraftClient.Mapping
|
||||||
if (chunk != null)
|
if (chunk != null)
|
||||||
return chunk.GetBlock(location);
|
return chunk.GetBlock(location);
|
||||||
}
|
}
|
||||||
return Block.Air;
|
return new Block(Material.Air);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ namespace MinecraftClient
|
||||||
private object locationLock = new object();
|
private object locationLock = new object();
|
||||||
private World world = new World();
|
private World world = new World();
|
||||||
private Location location;
|
private Location location;
|
||||||
private int updateTicks = 0;
|
|
||||||
|
|
||||||
private string host;
|
private string host;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
@ -452,23 +451,18 @@ namespace MinecraftClient
|
||||||
|
|
||||||
if (Settings.TerrainAndMovements)
|
if (Settings.TerrainAndMovements)
|
||||||
{
|
{
|
||||||
if (updateTicks >= 10)
|
lock (locationLock)
|
||||||
{
|
{
|
||||||
lock (locationLock)
|
Location onFoots = new Location(location.X, Math.Floor(location.Y), location.Z);
|
||||||
{
|
Location belowFoots = location + new Location(0, -1, 0);
|
||||||
Location onFoots = new Location(location.X, Math.Floor(location.Y), location.Z);
|
Block blockOnFoots = world.GetBlock(onFoots);
|
||||||
Location belowFoots = location + new Location(0, -1, 0);
|
Block blockBelowFoots = world.GetBlock(belowFoots);
|
||||||
Block blockOnFoots = world.GetBlock(onFoots);
|
handler.SendLocationUpdate(location, blockBelowFoots.Type.IsSolid());
|
||||||
Block blockBelowFoots = world.GetBlock(belowFoots);
|
if (!blockBelowFoots.Type.IsSolid())
|
||||||
handler.SendLocationUpdate(location, blockBelowFoots.Solid);
|
location = belowFoots;
|
||||||
if (!blockBelowFoots.Solid)
|
else if (!blockOnFoots.Type.IsSolid())
|
||||||
location = belowFoots;
|
location = onFoots;
|
||||||
else if (!blockOnFoots.Solid)
|
|
||||||
location = onFoots;
|
|
||||||
}
|
|
||||||
updateTicks = 0;
|
|
||||||
}
|
}
|
||||||
updateTicks++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@
|
||||||
<Compile Include="Mapping\Block.cs" />
|
<Compile Include="Mapping\Block.cs" />
|
||||||
<Compile Include="Mapping\Chunk.cs" />
|
<Compile Include="Mapping\Chunk.cs" />
|
||||||
<Compile Include="Mapping\ChunkColumn.cs" />
|
<Compile Include="Mapping\ChunkColumn.cs" />
|
||||||
|
<Compile Include="Mapping\Material.cs" />
|
||||||
<Compile Include="Mapping\World.cs" />
|
<Compile Include="Mapping\World.cs" />
|
||||||
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeClientState.cs" />
|
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeClientState.cs" />
|
||||||
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeDiscriminator.cs" />
|
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeDiscriminator.cs" />
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace MinecraftClient.Protocol
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
|
ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message));
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromSeconds(30)))
|
}, TimeSpan.FromSeconds(30)))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue