fix mixins

This commit is contained in:
iceBear67 committed 2026-07-18 11:41:37 +08:00
1 parent e9901af08e
commit c7cd4acc63
17 files changed
+35 -41

No files matched your search

+6 -3
View File
@@ -29,9 +29,11 @@ dependencies {
// modImplementation so Loom loads it as a mod in the dev runtime; plain // modImplementation so Loom loads it as a mod in the dev runtime; plain
// implementation only adds it to the classpath, so Loader can't find the `fabric` mod. // implementation only adds it to the classpath, so Loader can't find the `fabric` mod.
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
shadow('com.maxmind.geoip2:geoip2:4.2.0') shadow('com.maxmind.geoip2:geoip2:5.2.0')
shadow("io.javalin:javalin:6.4.0") shadow("io.javalin:javalin:7.2.2") {
include(implementation "io.ib67.kiwi:lang:1.2.3-SNAPSHOT") exclude group: "org.eclipse.jetty.ee10", module: "jetty-ee10-annotations"
}
shadow("io.ib67.kiwi:lang:1.2.3-SNAPSHOT")
shadow('com.github.houbb:pinyin:0.4.0') shadow('com.github.houbb:pinyin:0.4.0')
shadow('com.google.inject:guice:7.0.0') { shadow('com.google.inject:guice:7.0.0') {
exclude group: 'com.google.guava', module: 'guava' exclude group: 'com.google.guava', module: 'guava'
@@ -44,6 +46,7 @@ configurations.implementation.extendsFrom(configurations.shadow)
shadowJar { shadowJar {
configurations = [project.configurations.shadow] configurations = [project.configurations.shadow]
exclude("META-INF") exclude("META-INF")
relocate 'kotlin', 'sfcraft-kotlin'
} }
processResources { processResources {
@@ -40,19 +40,19 @@ public class MaxMindGeoIPService implements Module, GeoIPService {
@Override @Override
@SneakyThrows @SneakyThrows
public Clock clockOf(InetAddress address) throws GeoIp2Exception { public Clock clockOf(InetAddress address) throws GeoIp2Exception {
return Clock.system(TimeZone.getTimeZone(databaseReader.city(address).getLocation().getTimeZone()).toZoneId()); return Clock.system(TimeZone.getTimeZone(databaseReader.city(address).location().timeZone()).toZoneId());
} }
@Override @Override
@SneakyThrows @SneakyThrows
public City cityOf(InetAddress address) throws GeoIp2Exception { public City cityOf(InetAddress address) throws GeoIp2Exception {
return databaseReader.city(address).getCity(); return databaseReader.city(address).city();
} }
@Override @Override
@SneakyThrows @SneakyThrows
public Country countryOf(InetAddress address) throws GeoIp2Exception { public Country countryOf(InetAddress address) throws GeoIp2Exception {
return databaseReader.country(address).getCountry(); return databaseReader.country(address).country();
} }
@SneakyThrows @SneakyThrows
@@ -1,7 +1,6 @@
package io.ib67.sfcraft.mixin.common; package io.ib67.sfcraft.mixin.common;
import net.minecraft.world.entity.monster.zombie.Zombie; import net.minecraft.world.entity.monster.zombie.Zombie;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -1,12 +0,0 @@
package io.ib67.sfcraft.mixin.common.bridge;
import net.minecraft.core.Holder;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(Item.class)
public interface ItemBridge {
@Accessor
void setBuiltInRegistryHolder(Holder.Reference<Item> value);
}
@@ -8,5 +8,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ServerLevel.class) @Mixin(ServerLevel.class)
public interface ServerWorldBridge { public interface ServerWorldBridge {
@Accessor @Accessor
SleepStatus getDEEPSLATE_BRICKS(); SleepStatus getSleepStatus();
} }
@@ -40,7 +40,7 @@ public abstract class AbstractFurnaceBlockMixin extends BaseEntityBlock {
var world = (ServerLevel) _world; var world = (ServerLevel) _world;
AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity); AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity);
int i = world.getGameRules().get(GameRules.PLAYERS_SLEEPING_PERCENTAGE); int i = world.getGameRules().get(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
if (((ServerWorldBridge) world).getDEEPSLATE_BRICKS().areEnoughSleeping(i)) { if (((ServerWorldBridge) world).getSleepStatus().areEnoughSleeping(i)) {
AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity); //todo: config support? AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity); //todo: config support?
AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity); AbstractFurnaceBlockEntity.serverTick(world, pos, state, blockEntity);
} }
@@ -24,12 +24,12 @@ public abstract class ServerPlayNetworkHandlerMixin {
* @author icybear * @author icybear
* @reason small method, overwrite to reduce overhead * @reason small method, overwrite to reduce overhead
*/ */
@Redirect(method = "method_44900", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getChatDecorator()Lnet/minecraft/network/chat/ChatDecorator;")) @Redirect(method = "lambda$handleChat$0", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getChatDecorator()Lnet/minecraft/network/chat/ChatDecorator;"))
public ChatDecorator getMessageDecorator(MinecraftServer instance) { public ChatDecorator getMessageDecorator(MinecraftServer instance) {
return SFCraft.getInjector().getInstance(SimpleMessageDecorator.class); return SFCraft.getInjector().getInstance(SimpleMessageDecorator.class);
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;disconnect(Lnet/minecraft/network/chat/Component;)V", ordinal = 2)) @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;disconnect(Lnet/minecraft/network/chat/Component;)V"))
public void onPlayerIdling(ServerGamePacketListenerImpl instance, Component text) { public void onPlayerIdling(ServerGamePacketListenerImpl instance, Component text) {
((ServerPlayerBridge) instance.player).setLastActionTime(Long.MAX_VALUE); ((ServerPlayerBridge) instance.player).setLastActionTime(Long.MAX_VALUE);
SFCallbacks.PLAYER_IDLE.invoker().onSwitchIdle(instance.player, true); SFCallbacks.PLAYER_IDLE.invoker().onSwitchIdle(instance.player, true);
@@ -12,7 +12,7 @@ public abstract class ServerWorldMixin {
@ModifyArg(method = "tickTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/ServerLevelData;setGameTime(J)V")) @ModifyArg(method = "tickTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/ServerLevelData;setGameTime(J)V"))
public long setTimeOfDay(long timeOfDay) { public long setTimeOfDay(long timeOfDay) {
int i = ((ServerLevel) (Object) this).getGameRules().get(GameRules.PLAYERS_SLEEPING_PERCENTAGE); int i = ((ServerLevel) (Object) this).getGameRules().get(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
if (((ServerWorldBridge) this).getDEEPSLATE_BRICKS().areEnoughSleeping(i)) { if (((ServerWorldBridge) this).getSleepStatus().areEnoughSleeping(i)) {
MixinHelper.spedUp = true; MixinHelper.spedUp = true;
return timeOfDay + 10; return timeOfDay + 10;
} }
@@ -3,6 +3,7 @@ package io.ib67.sfcraft.mixin.server.subserver;
import com.mojang.datafixers.DataFixer; import com.mojang.datafixers.DataFixer;
import io.ib67.sfcraft.module.RoomModule; import io.ib67.sfcraft.module.RoomModule;
import io.ib67.sfcraft.util.Helper; import io.ib67.sfcraft.util.Helper;
import net.minecraft.server.players.NameAndId;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -41,9 +42,9 @@ public class PlayerSaveHandlerMixin {
} }
} }
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/storage/PlayerDataStorage;playerDir:Ljava/io/File;"), method = "load(Lnet/minecraft/world/entity/player/Player;Ljava/lang/String;)Ljava/util/Optional;") @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/storage/PlayerDataStorage;playerDir:Ljava/io/File;"), method = "Lnet/minecraft/world/level/storage/PlayerDataStorage;load(Lnet/minecraft/server/players/NameAndId;Ljava/lang/String;)Ljava/util/Optional;")
private File sf$saveGetPlayerFolder(PlayerDataStorage instance, Player player) { private File sf$saveGetPlayerFolder(PlayerDataStorage instance, NameAndId player) {
if (RoomModule.isVirtual(player.getUUID())) { if (RoomModule.isVirtual(player.id())) {
return virtualPlayerFolder; return virtualPlayerFolder;
} else { } else {
return this.playerDir; return this.playerDir;
@@ -27,14 +27,14 @@ public class BackModule extends ServerModule {
private void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) { private void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) {
dispatcher.register(LiteralArgumentBuilder.<CommandSourceStack>literal("back") dispatcher.register(LiteralArgumentBuilder.<CommandSourceStack>literal("back")
.requires(it -> this.isEnabled()) .requires(it -> this.isEnabled())
.requires(it -> it.getPlayer() != null) .requires(it -> it.getPlayer() != null && it.getPlayer().getLastDeathLocation().isPresent())
.requires(it -> it.getPlayer().getLastDeathLocation().isPresent())
.requires(it -> SFConsts.COMMAND_BACK.hasPermission(it.getPlayer())) .requires(it -> SFConsts.COMMAND_BACK.hasPermission(it.getPlayer()))
.executes(this::onBack)); .executes(this::onBack));
} }
public int onBack(CommandContext<CommandSourceStack> it) { public int onBack(CommandContext<CommandSourceStack> it) {
var player = it.getSource().getPlayer(); var player = it.getSource().getPlayer();
if (player == null) return 0;
var pos = player.getLastDeathLocation().get(); var pos = player.getLastDeathLocation().get();
var wld = player.level().getServer().getLevel(pos.dimension()); var wld = player.level().getServer().getLevel(pos.dimension());
var _pos = pos.pos(); var _pos = pos.pos();
@@ -72,7 +72,7 @@ public class ManagementModule extends ServerModule {
var city = geoIPService.cityOf(addr); var city = geoIPService.cityOf(addr);
src.sendSystemMessage( src.sendSystemMessage(
Component.literal(" - ") Component.literal(" - ")
.append(Component.literal("[" + city.getName() + "] ").withColor(CommonColors.BLUE)) .append(Component.literal("[" + city.name() + "] ").withColor(CommonColors.BLUE))
.append(Component.literal(serverPlayerEntity.getName().tryCollapseToString())) .append(Component.literal(serverPlayerEntity.getName().tryCollapseToString()))
.append(Component.literal(" (" + Helper.hideIp(addr) + ")").withColor(CommonColors.LIGHT_GRAY)) .append(Component.literal(" (" + Helper.hideIp(addr) + ")").withColor(CommonColors.LIGHT_GRAY))
); );
@@ -34,6 +34,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.CommonColors; import net.minecraft.util.CommonColors;
import net.minecraft.world.level.GameType; import net.minecraft.world.level.GameType;
import net.minecraft.world.level.gamerules.GameRules;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.awt.*; import java.awt.*;
@@ -2,7 +2,8 @@ package io.ib67.sfcraft.module.supervisor;
import io.ib67.sfcraft.ServerModule; import io.ib67.sfcraft.ServerModule;
import io.javalin.Javalin; import io.javalin.Javalin;
import io.javalin.config.JavalinConfig;
public abstract class WebHandler extends ServerModule { public abstract class WebHandler extends ServerModule {
protected abstract void register(Javalin javalin); protected abstract void register(JavalinConfig javalin);
} }
@@ -17,13 +17,14 @@ public class WebModule extends ServerModule {
@Override @Override
public void onEnable() { public void onEnable() {
javalin = Javalin.create(cfg -> cfg.useVirtualThreads = false);
var moduleManager = SFCraft.getInjector().getInstance(ModuleManager.class); var moduleManager = SFCraft.getInjector().getInstance(ModuleManager.class);
for (ServerModule module : moduleManager.getModules()) { javalin = Javalin.create(cfg -> {
if(module instanceof WebHandler webHandler) { for (ServerModule module : moduleManager.getModules()) {
webHandler.register(javalin); if(module instanceof WebHandler webHandler) {
webHandler.register(cfg);
}
} }
} });
Thread.ofVirtual().name("SFCraft API Web").start(() -> javalin.start(config.httpPort)); Thread.ofVirtual().name("SFCraft API Web").start(() -> javalin.start(config.httpPort));
} }
@@ -9,10 +9,9 @@ import io.ib67.sfcraft.inject.MinecraftServerSupplier;
import io.ib67.sfcraft.module.SignatureService; import io.ib67.sfcraft.module.SignatureService;
import io.ib67.sfcraft.module.supervisor.WebHandler; import io.ib67.sfcraft.module.supervisor.WebHandler;
import io.ib67.sfcraft.util.Helper; import io.ib67.sfcraft.util.Helper;
import io.ib67.sfcraft.util.Permission;
import io.ib67.sfcraft.util.SFConsts; import io.ib67.sfcraft.util.SFConsts;
import io.ib67.sfcraft.util.litematic.LitematicConverterV3; import io.ib67.sfcraft.util.litematic.LitematicConverterV3;
import io.javalin.Javalin; import io.javalin.config.JavalinConfig;
import io.javalin.http.Context; import io.javalin.http.Context;
import io.javalin.http.UploadedFile; import io.javalin.http.UploadedFile;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@@ -75,8 +74,8 @@ public class SchematicUploader extends WebHandler {
} }
@Override @Override
public void register(Javalin javalin) { public void register(JavalinConfig javalin) {
javalin.options("/api/schematics/{name}", this::onUploadOptions).put("/api/schematics/{name}", this::uploadSchematic); javalin.routes.options("/api/schematics/{name}", this::onUploadOptions).put("/api/schematics/{name}", this::uploadSchematic);
} }
public String generateSchematicUrl(String issuer) { public String generateSchematicUrl(String issuer) {
@@ -15,6 +15,7 @@ public record Permission<T extends Entity>(String key, boolean byDefault) {
} }
public boolean hasPermission(T t) { public boolean hasPermission(T t) {
if(t == null) return false;
if (check(t, SFConsts.SPECIAL_SUDO)) return true; if (check(t, SFConsts.SPECIAL_SUDO)) return true;
if (byDefault) { if (byDefault) {
return !check(t, "-"+key); return !check(t, "-"+key);
@@ -23,6 +24,7 @@ public record Permission<T extends Entity>(String key, boolean byDefault) {
} }
private boolean check(T t, String permission){ private boolean check(T t, String permission){
if(t == null) return false;
if(t instanceof Player player) { if(t instanceof Player player) {
if (player.entityTags().contains(permission)){ if (player.entityTags().contains(permission)){
return true; return true;
-1
View File
@@ -13,7 +13,6 @@
"common.PlayerEntityMixin", "common.PlayerEntityMixin",
"common.ZombieMixin", "common.ZombieMixin",
"common.bridge.EntityBridge", "common.bridge.EntityBridge",
"common.bridge.ItemBridge",
"common.bridge.ServerChunkManagerBridge", "common.bridge.ServerChunkManagerBridge",
"common.bridge.ServerPlayerBridge", "common.bridge.ServerPlayerBridge",
"common.bridge.ServerWorldBridge", "common.bridge.ServerWorldBridge",