Lessen limits on enchantments

This commit is contained in:
JFronny 2021-08-21 21:05:26 +02:00
parent 51b3ce0026
commit 9e74f7ff60
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
6 changed files with 34 additions and 83 deletions

View File

@ -8,6 +8,6 @@ public class YesCheat implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("yescheat"); public static final Logger LOGGER = LogManager.getLogger("yescheat");
@Override @Override
public void onInitialize() { public void onInitialize() {
System.out.println("YesCheat initialized, anticheat yeeted"); LOGGER.info("YesCheat initialized, anticheat yeeted");
} }
} }

View File

@ -1,80 +0,0 @@
package io.gitlab.jfronny.yescheat;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Set;
public class YesCheatPlugin implements IMixinConfigPlugin {
private Properties config;
FabricLoader loader = FabricLoader.getInstance();
private final File path = loader.getConfigDir().resolve("yescheat.properties").toFile();
@Override
public void onLoad(String s) {
config = new Properties();
try (FileInputStream fs = new FileInputStream(path)) {
config.load(fs);
} catch (IOException e) {
System.err.println("[YesCheat] Could not read config, using defaults");
e.printStackTrace();
}
}
private void save() {
try (FileOutputStream fs = new FileOutputStream(path)) {
config.store(fs, "YesCheat config, you can toggle individual mixins here");
} catch (IOException e) {
System.err.println("[YesCheat] Could not save config, using defaults");
e.printStackTrace();
}
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
String mixinPath = "io.gitlab.jfronny.yescheat.mixin";
if (!mixinClassName.startsWith(mixinPath)) {
System.err.println("[YesCheat] found foreign mixin " + mixinClassName + "for" + targetClassName + ", disabling");
return false;
}
String mixin = mixinClassName.substring(mixinPath.length() + 1, mixinClassName.length() - 5);
if (!config.containsKey(mixin)) {
System.err.println("[YesCheat] Could not load value for " + mixinClassName + ", using default");
config.put(mixin, true);
save();
}
return Boolean.parseBoolean((String) config.get(mixin));
}
@Override
public void acceptTargets(Set<String> set, Set<String> set1) {
}
@Override
public List<String> getMixins() {
return null;
}
@Override
public void preApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
}
@Override
public void postApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
}
}

View File

@ -17,5 +17,4 @@ public class DedicatedServerWatchdogMixin {
*/ */
@Overwrite @Overwrite
private void shutdown() {} private void shutdown() {}
} }

View File

@ -0,0 +1,14 @@
package io.gitlab.jfronny.yescheat.mixin;
import net.minecraft.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(EnchantmentHelper.class)
public class EnchantmentHelperMixin {
@ModifyArg(method = "getLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(III)I"), index = 2)
private static int injectMaxEnchantmentLevel(int val, int min, int max) {
return val;
}
}

View File

@ -0,0 +1,17 @@
package io.gitlab.jfronny.yescheat.mixin;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.InfinityEnchantment;
import net.minecraft.enchantment.MendingEnchantment;
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(InfinityEnchantment.class)
public class InfinityEnchantmentMixin {
@Inject(method = "canAccept", at = @At("HEAD"), cancellable = true)
private void differs(Enchantment other, CallbackInfoReturnable<Boolean> cir) {
if(other instanceof MendingEnchantment) cir.setReturnValue(true);
}
}

View File

@ -2,14 +2,15 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "io.gitlab.jfronny.yescheat.mixin", "package": "io.gitlab.jfronny.yescheat.mixin",
"plugin": "io.gitlab.jfronny.yescheat.YesCheatPlugin",
"compatibilityLevel": "JAVA_16", "compatibilityLevel": "JAVA_16",
"mixins": [ "mixins": [
"ChestBlockMixin", "ChestBlockMixin",
"DedicatedServerWatchdogMixin", "DedicatedServerWatchdogMixin",
"EnchantmentHelperMixin",
"EulaReaderMixin", "EulaReaderMixin",
"Generic3x3ContainerScreenHandlerMixin", "Generic3x3ContainerScreenHandlerMixin",
"GenericContainerScreenHandlerMixin", "GenericContainerScreenHandlerMixin",
"InfinityEnchantmentMixin",
"ServerPlayNetworkHandlerMixin" "ServerPlayNetworkHandlerMixin"
], ],
"injectors": { "injectors": {