feat: add FourKit plugin host with dual server build

Adds the FourKit .NET 10 plugin host as a second dedicated server
build flavour alongside the existing vanilla server. Both flavours
build from the same source tree, with FourKit gated by the
MINECRAFT_SERVER_FOURKIT_BUILD preprocessor define.

Build layout:

  Minecraft.Server         vanilla, no plugin support, no .NET dep
  Minecraft.Server.FourKit FourKit-enabled, ships with bundled
                           .NET 10 self-contained runtime in runtime/
                           and an empty plugins/ folder

Both produce a Minecraft.Server.exe in their own per-target output
dir. The variant identity lives in the directory name, not the
binary name, so either flavour can be shipped as a drop-in.

Native bridge (Minecraft.Server/FourKit*.{cpp,h}):

* FourKitRuntime: hosts CoreCLR via hostfxr's command-line init API
  (the runtime-config API does not support self-contained components)
* FourKitBridge: ~50 Fire* event entry points, with inline no-op
  stubs for the standalone build so gameplay code can call them
  unconditionally
* FourKitNatives: ~80 native callbacks the managed side invokes
  for player/world/inventory mutations
* FourKitMappers: type and enum mapping helpers

Managed plugin host (Minecraft.Server.FourKit/):

* Bukkit-style API: Player, World, Block, Inventory, Command,
  Listener, EventHandler attribute, ~54 event classes
* PluginLoader with per-plugin AssemblyLoadContext
* FourKitHost as the [UnmanagedCallersOnly] entry point table
* Runtime resolves plugins relative to the host process so they
  always live next to Minecraft.Server.exe regardless of where the
  managed assembly itself is loaded from

Engine hooks (Minecraft.Client/, Minecraft.World/):

* Player lifecycle (PreLogin, Login, Join, Quit, Kick, Move,
  Teleport, Portal, Death) wired into PendingConnection and
  PlayerConnection without disturbing the cipher handshake or
  identity-token security flow
* Inventory open/click/drop hooks across every container menu type
* Block place/break/grow/burn/spread/from-to hooks across the
  full tile family
* Bed enter/leave, sign change, entity damage/death, ender pearl
  teleport hooks

Regression fixes preserved while applying donor diffs:

* ServerPlayer::die() retains the LCE-Revelations hardcore branch
  (setGameMode(ADVENTURE) + banPlayerForHardcoreDeath) in both the
  FourKit and non-FourKit code paths
* ServerLevel::entityAdded() retains the sub-entity ID reassignment
  loop required by the client's handleAddMob offset, fixing Ender
  Dragon and Wither boss multi-part hit detection
* LivingEntity::travel() retains the raw Player* cast and the
  cached frictionTile, both Revelations perf wins that the donor
  silently reverted
* ServerLogger.cpp keeps the file-logging code donor stripped
* PlayerList.cpp end portal transition fix and UIScene_EndPoem
  bounds-check are intact

Build system:

* Top-level CMakeLists.txt adds the Minecraft.Server.FourKit
  subdirectory and pulls in the new shared cmake/ServerTarget.cmake
  helper
* Minecraft.Server/cmake/sources/Common.cmake is now location
  independent (uses CMAKE_CURRENT_LIST_DIR) so the source list
  can be consumed from either server target's CMakeLists.txt
* The seven FourKit*.cpp/h files live in their own
  _MINECRAFT_SERVER_COMMON_SERVER_FOURKIT variable so the
  standalone target omits them
* configure-time .NET 10 SDK check fails fast with a clear
  download link if the SDK is missing
* global.json pins the SDK to 10.0.100 with latestFeature
  rollforward

Sample plugin (samples/HelloPlugin/) demonstrates the loader and
the PlayerJoinEvent listener pattern.

CI:

* nightly.yml builds both server flavours, ships
  LCE-Revelations-Server-Win64.zip and
  LCE-Revelations-Server-Win64-FourKit.zip, attests both, and
  updates release notes for the dual-flavour layout
* pull-request.yml pulls in actions/setup-dotnet so the FourKit
  publish step works in PR validation
* All zip artifacts and the client zip are renamed from
  LCREWindows64 to LCE-Revelations-{Client,Server}-Win64

Documentation:

* COMPILE.md gets a VS 2022 quick start, .NET 10 prereq section,
  server flavours explanation, and a troubleshooting section
* docs/FOURKIT_PORT_RECON.md captures the file-by-file recon that
  drove the port
* docs/FOURKIT_PARITY.md is the canonical reference for which
  events FourKit fires

Docker:

* docker-compose.dedicated-server.yml MC_RUNTIME_DIR default points
  at the vanilla CMake output. The FourKit Docker image is
  intentionally NOT shipped yet because hosting .NET 10 self
  contained inside Wine has not been smoke-tested
This commit is contained in:
itsRevela
2026-04-08 03:02:48 -05:00
parent 5d56f5080f
commit 42a582fb9f
197 changed files with 20946 additions and 788 deletions
@@ -0,0 +1,50 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
using Minecraft.Server.FourKit.Entity;
/// <summary>
/// Called when a block is broken by a player.
///
/// If you wish to have the block drop experience, you must set the experience
/// value above 0. By default, experience will be set in the event if:
/// <list type="bullet">
/// <item><description>The player is not in creative or adventure mode</description></item>
/// <item><description>The player can loot the block (ie: does not destroy it completely, by using the correct tool)</description></item>
/// <item><description>The player does not have silk touch</description></item>
/// <item><description>The block drops experience in vanilla Minecraft</description></item>
/// </list>
///
/// Note: Plugins wanting to simulate a traditional block drop should set the
/// block to air and utilize their own methods for determining what the default
/// drop for the block being broken is and what to do about it, if anything.
///
/// If a Block Break event is cancelled, the block will not break and experience
/// will not drop.
/// </summary>
public class BlockBreakEvent : BlockExpEvent, Cancellable
{
private readonly Player _player;
private bool _cancel;
internal BlockBreakEvent(Block block, Player player, int exp)
: base(block, exp)
{
_player = player;
_cancel = false;
}
/// <summary>
/// Gets the Player that is breaking the block involved in this event.
/// </summary>
/// <returns>The Player that is breaking the block involved in this event.</returns>
public Player getPlayer() => _player;
/// <inheritdoc/>
public bool isCancelled() => _cancel;
/// <inheritdoc/>
public void setCancelled(bool cancel)
{
_cancel = cancel;
}
}
@@ -0,0 +1,30 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a block is destroyed as a result of being burnt by fire.
///
/// <para>If a Block Burn event is cancelled, the block will not be destroyed
/// as a result of being burnt by fire.</para>
/// </summary>
public class BlockBurnEvent : BlockEvent, Cancellable
{
private bool _cancel;
internal BlockBurnEvent(Block block) : base(block)
{
_cancel = false;
}
/// <inheritdoc />
public bool isCancelled() => _cancel;
/// <inheritdoc />
public void setCancelled(bool cancel)
{
_cancel = cancel;
}
}
@@ -0,0 +1,22 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Represents a Block-related event.
/// </summary>
public abstract class BlockEvent : Event
{
private readonly Block _block;
internal protected BlockEvent(Block block)
{
_block = block;
}
/// <summary>
/// Gets the block involved in this event.
/// </summary>
/// <returns>The Block which is involved in this event.</returns>
public Block getBlock() => _block;
}
@@ -0,0 +1,31 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// An event that is called when a block yields experience.
/// </summary>
public class BlockExpEvent : BlockEvent
{
private int _exp;
internal BlockExpEvent(Block block, int exp)
: base(block)
{
_exp = exp;
}
/// <summary>
/// Get the experience dropped by the block after the event has processed.
/// </summary>
/// <returns>The experience to drop.</returns>
public int getExpToDrop() => _exp;
/// <summary>
/// Set the amount of experience dropped by the block after the event has processed.
/// </summary>
/// <param name="exp">1 or higher to drop experience, else nothing will drop.</param>
public void setExpToDrop(int exp)
{
_exp = exp;
}
}
@@ -0,0 +1,23 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a block is formed or spreads based on world conditions.
/// Use <see cref="BlockSpreadEvent"/> to catch blocks that actually spread
/// and don't just "randomly" form.
///
/// <para>Examples:</para>
/// <list type="bullet">
/// <item><description>Snow forming due to a snow storm.</description></item>
/// <item><description>Ice forming in a snowy Biome like Taiga or Tundra.</description></item>
/// </list>
///
/// <para>If a Block Form event is cancelled, the block will not be formed.</para>
/// </summary>
public class BlockFormEvent : BlockGrowEvent, Cancellable
{
internal BlockFormEvent(Block block, BlockState newState) : base(block, newState)
{
}
}
@@ -0,0 +1,59 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Represents events with a source block and a destination block, currently
/// only applies to liquid (lava and water) and teleporting dragon eggs.
///
/// <para>If a Block From To event is cancelled, the block will not move
/// (the liquid will not flow).</para>
/// </summary>
public class BlockFromToEvent : BlockEvent, Cancellable
{
private readonly Block _to;
private readonly BlockFace _face;
private bool _cancel;
internal BlockFromToEvent(Block block, BlockFace face) : base(block)
{
_face = face;
_to = block.getRelative(face);
_cancel = false;
}
internal BlockFromToEvent(Block block, Block toBlock) : base(block)
{
_to = toBlock;
_face = BlockFace.SELF;
_cancel = false;
}
internal BlockFromToEvent(Block block, Block toBlock, BlockFace face) : base(block)
{
_to = toBlock;
_face = face;
_cancel = false;
}
/// <summary>
/// Gets the BlockFace that the block is moving to.
/// </summary>
/// <returns>The BlockFace that the block is moving to.</returns>
public BlockFace getFace() => _face;
/// <summary>
/// Convenience method for getting the faced Block.
/// </summary>
/// <returns>The faced Block.</returns>
public Block getToBlock() => _to;
/// <inheritdoc/>
public bool isCancelled() => _cancel;
/// <inheritdoc/>
public void setCancelled(bool cancel)
{
_cancel = cancel;
}
}
@@ -0,0 +1,44 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a block grows naturally in the world.
///
/// <para>Examples:</para>
/// <list type="bullet">
/// <item><description>Wheat</description></item>
/// <item><description>Sugar Cane</description></item>
/// <item><description>Cactus</description></item>
/// <item><description>Watermelon</description></item>
/// <item><description>Pumpkin</description></item>
/// </list>
///
/// <para>If a Block Grow event is cancelled, the block will not grow.</para>
/// </summary>
public class BlockGrowEvent : BlockEvent, Cancellable
{
private bool _cancel;
private readonly BlockState _newState;
internal BlockGrowEvent(Block block, BlockState newState) : base(block)
{
_cancel = false;
_newState = newState;
}
/// <summary>
/// Gets the state of the block where it will form or spread to.
/// </summary>
/// <returns>The block state for this events block.</returns>
public BlockState getNewState() => _newState;
/// <inheritdoc/>
public bool isCancelled() => _cancel;
/// <inheritdoc/>
public void setCancelled(bool cancel)
{
_cancel = cancel;
}
}
@@ -0,0 +1,45 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a piston block is triggered.
/// </summary>
public abstract class BlockPistonEvent : BlockEvent, Cancellable
{
private bool _cancel;
private readonly BlockFace _direction;
internal protected BlockPistonEvent(Block block, BlockFace direction) : base(block)
{
_direction = direction;
_cancel = false;
}
/// <inheritdoc />
public bool isCancelled() => _cancel;
/// <inheritdoc />
public void setCancelled(bool cancelled)
{
_cancel = cancelled;
}
/// <summary>
/// Returns true if the Piston in the event is sticky.
/// </summary>
/// <returns>Stickiness of the piston.</returns>
public bool isSticky()
{
var type = getBlock().getType();
return type == Material.PISTON_STICKY_BASE;
}
/// <summary>
/// Return the direction in which the piston will operate.
/// </summary>
/// <returns>Direction of the piston.</returns>
public BlockFace getDirection() => _direction;
}
@@ -0,0 +1,46 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a piston extends.
/// </summary>
public class BlockPistonExtendEvent : BlockPistonEvent
{
private readonly int _length;
internal BlockPistonExtendEvent(Block block, int length, BlockFace direction)
: base(block, direction)
{
_length = length;
}
/// <summary>
/// Get the amount of blocks which will be moved while extending.
/// </summary>
/// <returns>The amount of moving blocks.</returns>
public int getLength() => _length;
/// <summary>
/// Get an immutable list of the blocks which will be moved by the extending.
/// </summary>
/// <returns>Immutable list of the moved blocks.</returns>
public List<Block> getBlocks()
{
var blocks = new List<Block>();
var world = getBlock().getWorld();
int x = getBlock().getX();
int y = getBlock().getY();
int z = getBlock().getZ();
var dir = getDirection();
for (int i = 0; i < _length; i++)
{
x += dir.getModX();
y += dir.getModY();
z += dir.getModZ();
blocks.Add(new Block(world, x, y, z));
}
return blocks.AsReadOnly().ToList();
}
}
@@ -0,0 +1,30 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a piston retracts.
/// </summary>
public class BlockPistonRetractEvent : BlockPistonEvent
{
internal BlockPistonRetractEvent(Block block, BlockFace direction)
: base(block, direction)
{
}
/// <summary>
/// Gets the location where the possible moving block might be if the
/// retracting piston is sticky.
/// </summary>
/// <returns>The possible location of the possibly moving block.</returns>
public Location getRetractLocation()
{
var block = getBlock();
var dir = getDirection();
return new Location(
block.getWorld(),
block.getX() + dir.getModX() * 2,
block.getY() + dir.getModY() * 2,
block.getZ() + dir.getModZ() * 2);
}
}
@@ -0,0 +1,58 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
using Minecraft.Server.FourKit.Entity;
using Minecraft.Server.FourKit.Inventory;
/// <summary>
/// Called when a block is placed by a player.
/// </summary>
public class BlockPlaceEvent : BlockEvent, Cancellable
{
protected Block placedAgainst;
protected ItemStack itemInHand;
protected Player player;
protected bool canBuild;
protected bool cancel;
internal BlockPlaceEvent(Block placedBlock, Block placedAgainst, ItemStack itemInHand, Player thePlayer, bool canBuild)
: base(placedBlock)
{
this.placedAgainst = placedAgainst;
this.itemInHand = itemInHand;
this.player = thePlayer;
this.canBuild = canBuild;
this.cancel = false;
}
/// <summary>
/// Gets the player who placed the block involved in this event.
/// </summary>
/// <returns>The Player who placed the block involved in this event.</returns>
public Player getPlayer() => player;
/// <summary>
/// Clarity method for getting the placed block. Not really needed except
/// for reasons of clarity.
/// </summary>
/// <returns>The Block that was placed.</returns>
public Block getBlockPlaced() => getBlock();
/// <summary>
/// Gets the block that this block was placed against.
/// </summary>
/// <returns>Block the block that the new block was placed against.</returns>
public Block getBlockAgainst() => placedAgainst;
/// <summary>
/// Gets the item in the player's hand when they placed the block.
/// </summary>
/// <returns>The ItemStack for the item in the player's hand when they placed the block.</returns>
public ItemStack getItemInHand() => itemInHand;
/// <inheritdoc />
public bool isCancelled() => cancel;
/// <inheritdoc />
public void setCancelled(bool cancel) => this.cancel = cancel;
}
@@ -0,0 +1,32 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
/// <summary>
/// Called when a block spreads based on world conditions.
/// Use <see cref="BlockFormEvent"/> to catch blocks that "randomly" form
/// instead of actually spread.
///
/// <para>Examples:</para>
/// <list type="bullet">
/// <item><description>Mushrooms spreading.</description></item>
/// <item><description>Fire spreading.</description></item>
/// </list>
///
/// <para>If a Block Spread event is cancelled, the block will not spread.</para>
/// </summary>
public class BlockSpreadEvent : BlockFormEvent, Cancellable
{
private readonly Block _source;
internal BlockSpreadEvent(Block block, Block source, BlockState newState) : base(block, newState)
{
_source = source;
}
/// <summary>
/// Gets the source block involved in this event.
/// </summary>
/// <returns>The Block for the source block involved in this event.</returns>
public Block getSource() => _source;
}
@@ -0,0 +1,65 @@
namespace Minecraft.Server.FourKit.Event.Block;
using Minecraft.Server.FourKit.Block;
using Minecraft.Server.FourKit.Entity;
/// <summary>
/// Called when a sign is changed by a player.
/// </summary>
public class SignChangeEvent : BlockEvent, Cancellable
{
private readonly Player _player;
private readonly string[] _lines;
private bool _cancel;
internal SignChangeEvent(Block theBlock, Player thePlayer, string[] theLines)
: base(theBlock)
{
_player = thePlayer;
_lines = theLines;
_cancel = false;
}
/// <summary>
/// Gets the player changing the sign involved in this event.
/// </summary>
/// <returns>The Player involved in this event.</returns>
public Player getPlayer() => _player;
/// <summary>
/// Gets all of the lines of text from the sign involved in this event.
/// </summary>
/// <returns>The String array for the sign's lines new text.</returns>
public string[] getLines() => _lines;
/// <summary>
/// Gets a single line of text from the sign involved in this event.
/// </summary>
/// <param name="index">Index of the line to get.</param>
/// <returns>The String containing the line of text associated with the provided index.</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when the provided index is &gt; 3 or &lt; 0.</exception>
public string getLine(int index)
{
if (index < 0 || index > 3)
throw new IndexOutOfRangeException($"Line index must be between 0 and 3, got {index}");
return _lines[index];
}
/// <summary>
/// Sets a single line for the sign involved in this event.
/// </summary>
/// <param name="index">Index of the line to set.</param>
/// <param name="line">Text to set.</param>
/// <exception cref="IndexOutOfRangeException">Thrown when the provided index is &gt; 3 or &lt; 0.</exception>
public void setLine(int index, string line)
{
if (index < 0 || index > 3)
throw new IndexOutOfRangeException($"Line index must be between 0 and 3, got {index}");
_lines[index] = line;
}
/// <inheritdoc />
public bool isCancelled() => _cancel;
/// <inheritdoc />
public void setCancelled(bool cancel) => _cancel = cancel;
}