feat(villagers): Use feature implementation by enjarai
Some checks failed
ci/woodpecker/push/jfmod Pipeline failed
Some checks failed
ci/woodpecker/push/jfmod Pipeline failed
This commit is contained in:
parent
d8a3e48931
commit
ce34f7cc1a
@ -2,18 +2,18 @@ plugins {
|
|||||||
id("jfmod") version "1.5-SNAPSHOT"
|
id("jfmod") version "1.5-SNAPSHOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "io.gitlab.jfronny"
|
allprojects { group = "io.gitlab.jfronny" }
|
||||||
base.archivesName = "yescheat"
|
base.archivesName = "yescheat"
|
||||||
|
|
||||||
jfMod {
|
jfMod {
|
||||||
minecraftVersion = "1.20.1"
|
minecraftVersion = "1.20.1"
|
||||||
yarn("build.9")
|
yarn("build.9")
|
||||||
loaderVersion = "0.14.21"
|
loaderVersion = "0.14.21"
|
||||||
libJfVersion = "3.9.0"
|
libJfVersion = "3.9.2"
|
||||||
|
|
||||||
modrinth {
|
modrinth {
|
||||||
projectId = "yescheat"
|
projectId = "yescheat"
|
||||||
requiredDependencies.add("libjf")
|
requiredDependencies.addAll("libjf", "fabric-api")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ dependencies {
|
|||||||
val fabricVersion = "0.85.0+${jfMod.minecraftVersion.get()}"
|
val fabricVersion = "0.85.0+${jfMod.minecraftVersion.get()}"
|
||||||
|
|
||||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${jfMod.libJfVersion.get()}")
|
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${jfMod.libJfVersion.get()}")
|
||||||
include(modImplementation(fabricApi.module("fabric-transitive-access-wideners-v1", fabricVersion))!!)
|
modImplementation("net.fabricmc.fabric-api:fabric-api:0.85.0+${jfMod.minecraftVersion.get()}")
|
||||||
|
|
||||||
// Dev env
|
// Dev env
|
||||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${jfMod.libJfVersion.get()}")
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${jfMod.libJfVersion.get()}")
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package io.gitlab.jfronny.yescheat;
|
package io.gitlab.jfronny.yescheat;
|
||||||
|
|
||||||
import io.gitlab.jfronny.yescheat.mixin.*;
|
|
||||||
import io.gitlab.jfronny.yescheat.mixin.UncapEnchants;
|
|
||||||
import io.gitlab.jfronny.yescheat.mixin.UnlockMendingInfinity;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class Plugin implements IMixinConfigPlugin {
|
public class Plugin implements IMixinConfigPlugin {
|
||||||
@Override
|
@Override
|
||||||
@ -19,32 +17,24 @@ public class Plugin implements IMixinConfigPlugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ReferenceToMixin")
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||||
final String prefix = "io.gitlab.jfronny.yescheat.mixin.";
|
final String prefix = "io.gitlab.jfronny.yescheat.mixin.";
|
||||||
if (!mixinClassName.startsWith(prefix)) throw new IllegalArgumentException("Mixin in unexpected package: " + mixinClassName);
|
if (!mixinClassName.startsWith(prefix)) throw new IllegalArgumentException("Mixin in unexpected package: " + mixinClassName);
|
||||||
mixinClassName = mixinClassName.substring(prefix.length());
|
mixinClassName = mixinClassName.substring(prefix.length());
|
||||||
|
|
||||||
if (Objects.equals(mixinClassName, "UnblockChests"))
|
if (mixinClassName.startsWith("Debug")) return true;
|
||||||
return Cfg.unblockChests;
|
return switch (mixinClassName) {
|
||||||
else if (Objects.equals(mixinClassName, "UncapEnchants"))
|
case "UnblockChests" -> Cfg.unblockChests;
|
||||||
return Cfg.uncapEnchants;
|
case "UncapEnchants" -> Cfg.uncapEnchants;
|
||||||
else if (Objects.equals(mixinClassName, "IgnoreEula"))
|
case "IgnoreEula" -> true;
|
||||||
return true;
|
case "DistantContainers3x3", "DistantContainerXx9" -> Cfg.distantContainers;
|
||||||
else if (Objects.equals(mixinClassName, "DistantContainers3x3")
|
case "UnlockMendingInfinity" -> Cfg.unlockMending;
|
||||||
|| Objects.equals(mixinClassName, "DistantContainerXx9"))
|
case "DistantBreaking" -> Cfg.distantBreaking;
|
||||||
return Cfg.distantContainers;
|
case "RemoveRubberbanding" -> Cfg.antiRubberband;
|
||||||
else if (Objects.equals(mixinClassName, "UnlockMendingInfinity"))
|
case "VillagersFollowEmeralds1", "VillagersFollowEmeralds2" -> Cfg.villagersFollowEmeralds;
|
||||||
return Cfg.unlockMending;
|
default -> throw new IllegalArgumentException("Unrecognized mixin: " + mixinClassName + "! This should never happen");
|
||||||
else if (Objects.equals(mixinClassName, "DistantBreaking"))
|
};
|
||||||
return Cfg.distantBreaking;
|
|
||||||
else if (Objects.equals(mixinClassName, "RemoveRubberbanding"))
|
|
||||||
return Cfg.antiRubberband;
|
|
||||||
else if (Objects.equals(mixinClassName, "VillagersFollowEmeralds"))
|
|
||||||
return Cfg.villagersFollowEmeralds;
|
|
||||||
else
|
|
||||||
throw new IllegalArgumentException("Unrecognized mixin: " + mixinClassName + "! This should never happen");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
35
src/main/java/io/gitlab/jfronny/yescheat/YesCheat.java
Normal file
35
src/main/java/io/gitlab/jfronny/yescheat/YesCheat.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package io.gitlab.jfronny.yescheat;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.minecraft.entity.ai.brain.sensor.SensorType;
|
||||||
|
import net.minecraft.entity.ai.brain.sensor.TemptationsSensor;
|
||||||
|
import net.minecraft.recipe.Ingredient;
|
||||||
|
import net.minecraft.registry.*;
|
||||||
|
import net.minecraft.registry.tag.TagKey;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class YesCheat implements ModInitializer {
|
||||||
|
public static final String MOD_ID = "yescheat";
|
||||||
|
|
||||||
|
private static final Identifier TEMPTATIONS_ID = new Identifier(MOD_ID, "villager_temptations");
|
||||||
|
public static SensorType<TemptationsSensor> VILLAGER_TEMPTATIONS;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
System.out.println("Ae");
|
||||||
|
if (Cfg.villagersFollowEmeralds) {
|
||||||
|
villagersFollowEmeraldsInit();
|
||||||
|
Registry.register(Registries.SENSOR_TYPE, TEMPTATIONS_ID, VILLAGER_TEMPTATIONS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void villagersFollowEmeraldsInit() {
|
||||||
|
if (!Cfg.villagersFollowEmeralds) throw new IllegalStateException("villagersFollowEmeralds is not enabled but its initializer is called");
|
||||||
|
if (VILLAGER_TEMPTATIONS == null) {
|
||||||
|
VILLAGER_TEMPTATIONS =
|
||||||
|
new SensorType<>(() -> new TemptationsSensor((Ingredient.fromTag(
|
||||||
|
TagKey.of(RegistryKeys.ITEM, TEMPTATIONS_ID)
|
||||||
|
))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +0,0 @@
|
|||||||
package io.gitlab.jfronny.yescheat.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.ai.goal.TemptGoal;
|
|
||||||
import net.minecraft.entity.passive.MerchantEntity;
|
|
||||||
import net.minecraft.entity.passive.VillagerEntity;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.recipe.Ingredient;
|
|
||||||
import net.minecraft.village.VillagerType;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
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.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(VillagerEntity.class)
|
|
||||||
public abstract class VillagersFollowEmeralds extends MerchantEntity {
|
|
||||||
public VillagersFollowEmeralds(EntityType<? extends MerchantEntity> entityType, World world) {
|
|
||||||
super(entityType, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;Lnet/minecraft/village/VillagerType;)V", at = @At(value = "TAIL"))
|
|
||||||
private void inject(EntityType<? extends VillagerEntity> entityType, World world, VillagerType type, CallbackInfo ci) {
|
|
||||||
this.goalSelector.add(2, new TemptGoal(this, .4D, Ingredient.ofItems(Items.EMERALD_BLOCK, Items.EMERALD_ORE, Items.DEEPSLATE_EMERALD_ORE), false));
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,36 @@
|
|||||||
|
package io.gitlab.jfronny.yescheat.mixin;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import io.gitlab.jfronny.yescheat.YesCheat;
|
||||||
|
import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||||
|
import net.minecraft.entity.ai.brain.sensor.Sensor;
|
||||||
|
import net.minecraft.entity.ai.brain.sensor.SensorType;
|
||||||
|
import net.minecraft.entity.passive.VillagerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.*;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Mixin(VillagerEntity.class)
|
||||||
|
public abstract class VillagersFollowEmeralds1 {
|
||||||
|
@Mutable @Shadow @Final private static ImmutableList<MemoryModuleType<?>> MEMORY_MODULES;
|
||||||
|
@Mutable @Shadow @Final private static ImmutableList<SensorType<? extends Sensor<? super VillagerEntity>>> SENSORS;
|
||||||
|
|
||||||
|
@Inject(method = "<clinit>", at = @At("TAIL"))
|
||||||
|
private static void addRequiredMemoryModulesAndSensors(CallbackInfo ci) {
|
||||||
|
YesCheat.villagersFollowEmeraldsInit();
|
||||||
|
|
||||||
|
var newMemoryModules = new ArrayList<>(MEMORY_MODULES);
|
||||||
|
newMemoryModules.add(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS);
|
||||||
|
newMemoryModules.add(MemoryModuleType.IS_TEMPTED);
|
||||||
|
newMemoryModules.add(MemoryModuleType.TEMPTING_PLAYER);
|
||||||
|
newMemoryModules.add(MemoryModuleType.IS_PANICKING);
|
||||||
|
MEMORY_MODULES = ImmutableList.copyOf(newMemoryModules);
|
||||||
|
|
||||||
|
var newSensors = new ArrayList<>(SENSORS);
|
||||||
|
newSensors.add(YesCheat.VILLAGER_TEMPTATIONS);
|
||||||
|
SENSORS = ImmutableList.copyOf(newSensors);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package io.gitlab.jfronny.yescheat.mixin;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||||
|
import net.minecraft.entity.ai.brain.task.*;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
|
@Mixin(VillagerTaskListProvider.class)
|
||||||
|
public abstract class VillagersFollowEmeralds2 {
|
||||||
|
@ModifyArg(method = "createCoreTasks", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;", remap = false))
|
||||||
|
private static Object[] addTemptationAsCoreTask(Object[] original) {
|
||||||
|
Object[] modified = new Object[original.length + 2];
|
||||||
|
System.arraycopy(original, 0, modified, 0, original.length);
|
||||||
|
modified[original.length] = Pair.of(0, new TemptTask(e -> 0.5f));
|
||||||
|
modified[original.length + 1] = Pair.of(0, new TemptationCooldownTask(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS));
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
}
|
@ -5,15 +5,16 @@
|
|||||||
"compatibilityLevel": "JAVA_16",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"plugin": "io.gitlab.jfronny.yescheat.Plugin",
|
"plugin": "io.gitlab.jfronny.yescheat.Plugin",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"UnblockChests",
|
"DistantBreaking",
|
||||||
"UncapEnchants",
|
|
||||||
"IgnoreEula",
|
|
||||||
"DistantContainers3x3",
|
"DistantContainers3x3",
|
||||||
"DistantContainerXx9",
|
"DistantContainerXx9",
|
||||||
"UnlockMendingInfinity",
|
"IgnoreEula",
|
||||||
"RemoveRubberbanding",
|
"RemoveRubberbanding",
|
||||||
"DistantBreaking",
|
"UnblockChests",
|
||||||
"VillagersFollowEmeralds"
|
"UncapEnchants",
|
||||||
|
"UnlockMendingInfinity",
|
||||||
|
"VillagersFollowEmeralds1",
|
||||||
|
"VillagersFollowEmeralds2"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"values": [
|
||||||
|
"minecraft:emerald_block",
|
||||||
|
"minecraft:emerald_ore",
|
||||||
|
"minecraft:deepslate_emerald_ore",
|
||||||
|
"#c:emeralds"
|
||||||
|
]
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
"icon": "assets/yescheat/icon.png",
|
"icon": "assets/yescheat/icon.png",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
|
"main": ["io.gitlab.jfronny.yescheat.YesCheat"],
|
||||||
"libjf:config": ["io.gitlab.jfronny.yescheat.JFC_Cfg"]
|
"libjf:config": ["io.gitlab.jfronny.yescheat.JFC_Cfg"]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
Loading…
Reference in New Issue
Block a user