Forge works!

This commit is contained in:
samolego 2021-01-26 13:54:38 +01:00
parent 6e5257514e
commit 6c8d80ac20
7 changed files with 51 additions and 11 deletions

View File

@ -11,16 +11,17 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.samo_lego.simpleauth.storage.PlayerCache;
import org.samo_lego.simpleauth.utils.PlatformSpecific;
import org.samo_lego.simpleauth.utils.PlayerAuth;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.samo_lego.simpleauth.SimpleAuth.*;
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;
@Mixin(ServerPlayerEntity.class)
@ -29,10 +30,9 @@ public class MixinServerPlayerEntity implements PlayerAuth {
private final ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
// * 20 for 20 ticks in second
@Unique
private int kickTimer = config.main.kickTime * 20;
private final boolean isRunningCarpet = false;//FabricLoader.getInstance().isModLoaded("carpet"); //todo
@Final
@Shadow
public MinecraftServer server;
@ -158,8 +158,7 @@ public class MixinServerPlayerEntity implements PlayerAuth {
*/
@Override
public boolean canSkipAuth() {
// We ask CarpetHelper class since it has the imports needed
return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.main.premiumAutologin);
return PlatformSpecific.isPlayerFake(this.player) || (isUsingMojangAccount() && config.main.premiumAutologin);
}
/**

View File

@ -0,0 +1,12 @@
package org.samo_lego.simpleauth.utils;
import me.shedaniel.architectury.annotations.ExpectPlatform;
import net.minecraft.entity.player.PlayerEntity;
public class PlatformSpecific {
@ExpectPlatform
public static boolean isPlayerFake(PlayerEntity player) {
// Replaced by Architectury
throw new AssertionError();
}
}

View File

@ -1,17 +1,16 @@
package org.samo_lego.simpleauth.utils;
//import carpet.patches.EntityPlayerMPFake;
import carpet.patches.EntityPlayerMPFake;
import net.minecraft.entity.player.PlayerEntity;
public class CarpetHelper {
/**
* Checks if player is actually a fake one.
* Fake players are counted as ones, summoned with Carpet mod.
*
* @param player player to check
* @return true if it's fake, otherwise false
*/
public static boolean isPlayerCarpetFake(PlayerEntity player) {
return false;//player instanceof EntityPlayerMPFake;
public static boolean isPlayerFake(PlayerEntity player) {
return player instanceof EntityPlayerMPFake;
}
}

View File

@ -0,0 +1,17 @@
package org.samo_lego.simpleauth.utils.fabric;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import org.samo_lego.simpleauth.utils.CarpetHelper;
public class PlatformSpecificImpl {
/**
* Checks if player is actually a fake one.
*
* @param player player to check
* @return true if it's fake, otherwise false
*/
public static boolean isPlayerFake(PlayerEntity player) {
return FabricLoader.getInstance().isModLoaded("carpet") && CarpetHelper.isPlayerFake(player);
}
}

View File

@ -3,6 +3,7 @@ package org.samo_lego.simpleauth;
import com.mojang.brigadier.CommandDispatcher;
import me.shedaniel.architectury.platform.forge.EventBuses;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@ -15,8 +16,9 @@ import org.samo_lego.simpleauth.commands.*;
public class SimpleAuthForge {
public SimpleAuthForge() {
// Submit our event bus to let architectury register our content on the right time
EventBuses.registerModEventBus(SimpleAuth.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
//EventBuses.registerModEventBus(SimpleAuth.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
SimpleAuth.init(FMLPaths.GAMEDIR.get());
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent

View File

@ -0,0 +1,11 @@
package org.samo_lego.simpleauth.utils.forge;
import net.minecraft.entity.player.PlayerEntity;
public class PlatformSpecificImpl {
public static boolean isPlayerFake(PlayerEntity player) {
// Are there any forge mods with NPCs that don't work with SimpleAuth?
// Let me know!
return false;
}
}

View File

@ -14,7 +14,7 @@ forge_version=36.0.4
# Mod Properties
mod_version = 1.7.4
mod_version = 1.7.5
maven_group = org.samo_lego
archives_base_name = simpleauth