diff --git a/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/ClientPlayerEntityMixin.java b/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/network/ClientPlayerEntityMixin.java similarity index 91% rename from bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/ClientPlayerEntityMixin.java rename to bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/network/ClientPlayerEntityMixin.java index d1465f4..cc9da8a 100755 --- a/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/ClientPlayerEntityMixin.java +++ b/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/client/network/ClientPlayerEntityMixin.java @@ -1,4 +1,4 @@ -package dev.hugeblank.bouquet.mixin.client; +package dev.hugeblank.bouquet.mixin.client.network; import dev.hugeblank.bouquet.api.lib.ClientEventsLib; import net.minecraft.client.network.ClientPlayerEntity; diff --git a/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/server/integrated/IntegratedServerMixin.java b/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/server/integrated/IntegratedServerMixin.java new file mode 100644 index 0000000..4820c9f --- /dev/null +++ b/bouquet/src/client/java/dev/hugeblank/bouquet/mixin/server/integrated/IntegratedServerMixin.java @@ -0,0 +1,17 @@ +package dev.hugeblank.bouquet.mixin.server.integrated; + +import dev.hugeblank.bouquet.api.lib.DefaultEventsLib; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.integrated.IntegratedServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(IntegratedServer.class) +public class IntegratedServerMixin { + @Inject(at = @At("TAIL"), method = "setupServer") + private void init(CallbackInfoReturnable cir) { + DefaultEventsLib.SERVER_START.invoker().onServerStart((MinecraftServer) (Object) this); + } +} diff --git a/bouquet/src/client/resources/bouquet.client.mixins.json b/bouquet/src/client/resources/bouquet.client.mixins.json index 4cd8833..04dd3c6 100644 --- a/bouquet/src/client/resources/bouquet.client.mixins.json +++ b/bouquet/src/client/resources/bouquet.client.mixins.json @@ -1,10 +1,11 @@ { "required": true, - "package": "dev.hugeblank.bouquet.mixin.client", + "package": "dev.hugeblank.bouquet.mixin", "compatibilityLevel": "JAVA_21", "client": [ - "ClientPlayerEntityMixin", - "gui.hud.InGameHudMixin" + "client.gui.hud.InGameHudMixin", + "client.network.ClientPlayerEntityMixin", + "server.integrated.IntegratedServerMixin" ], "injectors": { "defaultRequire": 1 diff --git a/bouquet/src/main/java/dev/hugeblank/bouquet/BouquetModInitializer.java b/bouquet/src/main/java/dev/hugeblank/bouquet/BouquetModInitializer.java index 2e8fcd4..d6d42c8 100644 --- a/bouquet/src/main/java/dev/hugeblank/bouquet/BouquetModInitializer.java +++ b/bouquet/src/main/java/dev/hugeblank/bouquet/BouquetModInitializer.java @@ -11,10 +11,11 @@ public class BouquetModInitializer implements ModInitializer { @Override public void onInitialize() { - /* TODO: Missing APIs + /* TODO: Missing/nerfed APIs - Resource Pack - Recipes Library - Config Library (maybe it's better that it's gone?) + - Game Library (some stuff now requires scripts to get the MinecraftServer instance) */ } } \ No newline at end of file diff --git a/bouquet/src/main/java/dev/hugeblank/bouquet/api/event/CommonEventHandlers.java b/bouquet/src/main/java/dev/hugeblank/bouquet/api/event/CommonEventHandlers.java index 63ffd55..fca3b59 100755 --- a/bouquet/src/main/java/dev/hugeblank/bouquet/api/event/CommonEventHandlers.java +++ b/bouquet/src/main/java/dev/hugeblank/bouquet/api/event/CommonEventHandlers.java @@ -2,6 +2,7 @@ import net.minecraft.block.BlockState; import net.minecraft.entity.damage.DamageSource; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Hand; @@ -37,8 +38,12 @@ public interface PlayerBlockInteract { void onPlayerBlockInteraction(BlockState state, ServerWorld world, BlockPos pos, ServerPlayerEntity player, Hand hand, BlockHitResult hitResult); } - public interface Tick { - void onServerTick(); + public interface ServerTick { + void onServerTick(MinecraftServer server); + } + + public interface ServerStart { + void onServerStart(MinecraftServer server); } public interface CommandRegistration { diff --git a/bouquet/src/main/java/dev/hugeblank/bouquet/api/lib/DefaultEventsLib.java b/bouquet/src/main/java/dev/hugeblank/bouquet/api/lib/DefaultEventsLib.java index 0be14bf..a71cb0b 100755 --- a/bouquet/src/main/java/dev/hugeblank/bouquet/api/lib/DefaultEventsLib.java +++ b/bouquet/src/main/java/dev/hugeblank/bouquet/api/lib/DefaultEventsLib.java @@ -16,8 +16,9 @@ public class DefaultEventsLib implements WrappedLuaLibrary { @LuaWrapped public static final SimpleEventType PLAYER_BLOCK_COLLISION; // player collides with a block @LuaWrapped public static final SimpleEventType PLAYER_DEATH; // player dies @LuaWrapped public static final SimpleEventType BLOCK_INTERACT; // player interacts (right clicks) with a block - @LuaWrapped public static final SimpleEventType TICK; // server gets ticked + @LuaWrapped public static final SimpleEventType SERVER_TICK; // server gets ticked @LuaWrapped public static final SimpleEventType COMMAND_REGISTER; // the result of a registered command + @LuaWrapped public static final SimpleEventType SERVER_START; // server has started static { CHAT_MESSAGE = new SimpleEventType<>(Identifier.of("allium:chat_message")); @@ -27,8 +28,9 @@ public class DefaultEventsLib implements WrappedLuaLibrary { PLAYER_BLOCK_COLLISION = new SimpleEventType<>(Identifier.of("allium:player_block_collision")); PLAYER_DEATH = new SimpleEventType<>(Identifier.of("allium:player_death")); BLOCK_INTERACT = new SimpleEventType<>(Identifier.of("allium:block_interact")); - TICK = new SimpleEventType<>(Identifier.of("allium:server_tick")); + SERVER_TICK = new SimpleEventType<>(Identifier.of("allium:server_tick")); COMMAND_REGISTER = new SimpleEventType<>(Identifier.of("allium:command_register")); + SERVER_START = new SimpleEventType<>(Identifier.of("allium:server_start")); } } diff --git a/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerMixin.java b/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerMixin.java index 8ea164e..02fe135 100755 --- a/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerMixin.java +++ b/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerMixin.java @@ -1,34 +1,19 @@ package dev.hugeblank.bouquet.mixin.server; -import com.mojang.datafixers.DataFixer; import dev.hugeblank.bouquet.api.lib.DefaultEventsLib; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.resource.ResourcePackManager; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.SaveLoader; -import net.minecraft.server.WorldGenerationProgressListenerFactory; -import net.minecraft.util.ApiServices; -import net.minecraft.world.level.storage.LevelStorage; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.net.Proxy; import java.util.function.BooleanSupplier; @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { - @Shadow public abstract DynamicRegistryManager.Immutable getRegistryManager(); - - @Inject(at = @At("TAIL"), method = "") - private void init(Thread serverThread, LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, Proxy proxy, DataFixer dataFixer, ApiServices apiServices, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory, CallbackInfo ci) { - // TODO: Server start event - } @Inject(at = @At("TAIL"), method = "tick") private void tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { - DefaultEventsLib.TICK.invoker().onServerTick(); + DefaultEventsLib.SERVER_TICK.invoker().onServerTick((MinecraftServer) (Object) this); } } diff --git a/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerSubclassMixin.java b/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerSubclassMixin.java new file mode 100644 index 0000000..9696701 --- /dev/null +++ b/bouquet/src/main/java/dev/hugeblank/bouquet/mixin/server/MinecraftServerSubclassMixin.java @@ -0,0 +1,18 @@ +package dev.hugeblank.bouquet.mixin.server; + +import dev.hugeblank.bouquet.api.lib.DefaultEventsLib; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.dedicated.MinecraftDedicatedServer; +import net.minecraft.test.TestServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = {MinecraftDedicatedServer.class, TestServer.class}) +public class MinecraftServerSubclassMixin { + @Inject(at = @At("TAIL"), method = "setupServer") + private void init(CallbackInfoReturnable cir) { + DefaultEventsLib.SERVER_START.invoker().onServerStart((MinecraftServer) (Object) this); + } +} diff --git a/bouquet/src/main/resources/bouquet.mixins.json b/bouquet/src/main/resources/bouquet.mixins.json index 778c79a..3ee90f4 100644 --- a/bouquet/src/main/resources/bouquet.mixins.json +++ b/bouquet/src/main/resources/bouquet.mixins.json @@ -11,6 +11,7 @@ "entity.EntityMixin", "resource.ResourcePackManagerMixin", "server.MinecraftServerMixin", + "server.MinecraftServerSubclassMixin", "server.PlayerManagerMixin", "server.network.ServerPlayerEntityMixin" ],