From 141bd91373846721c6c561fea2ce90b1aafad1a7 Mon Sep 17 00:00:00 2001 From: Naz Date: Sun, 1 Dec 2024 06:17:40 +0800 Subject: [PATCH] Properly update and rebase everything to LexForge 47.3.12 --- forge | 2 +- .../gui/components/AbstractWidgetInject.java | 10 +-- .../model/MultiPartBakedModelInject.java | 7 -- .../world/entity/ai/BrainInject.java | 76 +++++++++++++++++++ .../world/entity/ai/BrainInjection.java | 14 ++++ .../net/minecraftforge/fml/IExtensionPoint.kt | 5 ++ .../minecraftforge/fml/ModLoadingContext.kt | 18 ++++- .../net/minecraftforge/fml/VersionChecker.kt | 4 + .../javafmlmod/FMLJavaModLoadingContext.kt | 2 +- .../minecraftforge/fml/loading/FMLLoader.kt | 5 ++ .../xyz/bluspring/kilt/loader/KiltLoader.kt | 47 ++++-------- .../resources/kilt_forge_injects.mixins.json | 1 + 12 files changed, 139 insertions(+), 52 deletions(-) create mode 100644 src/main/java/xyz/bluspring/kilt/forgeinjects/world/entity/ai/BrainInject.java create mode 100644 src/main/java/xyz/bluspring/kilt/injections/world/entity/ai/BrainInjection.java diff --git a/forge b/forge index 6fa017ee..7dad7b27 160000 --- a/forge +++ b/forge @@ -1 +1 @@ -Subproject commit 6fa017ee0e06465d95f0adfacf75d1bd66aa3d49 +Subproject commit 7dad7b2737914bb72f8eade79047a2344c68a69d diff --git a/src/main/java/xyz/bluspring/kilt/forgeinjects/client/gui/components/AbstractWidgetInject.java b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/gui/components/AbstractWidgetInject.java index 52159f4e..88719e5a 100644 --- a/src/main/java/xyz/bluspring/kilt/forgeinjects/client/gui/components/AbstractWidgetInject.java +++ b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/gui/components/AbstractWidgetInject.java @@ -2,24 +2,16 @@ package xyz.bluspring.kilt.forgeinjects.client.gui.components; import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraftforge.client.extensions.IAbstractWidgetExtension; 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.Redirect; import xyz.bluspring.kilt.helpers.mixin.CreateStatic; import xyz.bluspring.kilt.injections.client.gui.AbstractWidgetInjection; @Mixin(AbstractWidget.class) -public class AbstractWidgetInject implements AbstractWidgetInjection, IAbstractWidgetExtension { +public class AbstractWidgetInject implements AbstractWidgetInjection { @Shadow public boolean active; @Shadow protected int height; - @Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/AbstractWidget;onClick(DD)V")) - private void kilt$useForgeClick(AbstractWidget instance, double mouseX, double mouseY, double mx, double my, int button) { - this.onClick(mouseX, mouseY, button); - } - protected int packedFGColor = AbstractWidgetInjection.UNSET_FG_COLOR; @CreateStatic diff --git a/src/main/java/xyz/bluspring/kilt/forgeinjects/client/resources/model/MultiPartBakedModelInject.java b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/resources/model/MultiPartBakedModelInject.java index 7e549da1..9f65c1d3 100644 --- a/src/main/java/xyz/bluspring/kilt/forgeinjects/client/resources/model/MultiPartBakedModelInject.java +++ b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/resources/model/MultiPartBakedModelInject.java @@ -16,11 +16,9 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.MultiPartBakedModel; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.item.ItemDisplayContext; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.ChunkRenderTypeSet; import net.minecraftforge.client.model.IDynamicBakedModel; @@ -192,11 +190,6 @@ public boolean useAmbientOcclusion(BlockState state, RenderType renderType) { return this.defaultModel.useAmbientOcclusion(state, renderType); } - @Override - public @NotNull ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData) { - return MultipartModelData.create(selectors, this.getSelectors(state), level, pos, state, modelData); - } - @Override public TextureAtlasSprite getParticleIcon(@NotNull ModelData data) { return this.defaultModel.getParticleIcon(data); diff --git a/src/main/java/xyz/bluspring/kilt/forgeinjects/world/entity/ai/BrainInject.java b/src/main/java/xyz/bluspring/kilt/forgeinjects/world/entity/ai/BrainInject.java new file mode 100644 index 00000000..948f58cd --- /dev/null +++ b/src/main/java/xyz/bluspring/kilt/forgeinjects/world/entity/ai/BrainInject.java @@ -0,0 +1,76 @@ +package xyz.bluspring.kilt.forgeinjects.world.entity.ai; + +import com.mojang.datafixers.util.Pair; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.Brain; +import net.minecraft.world.entity.ai.behavior.BehaviorControl; +import net.minecraft.world.entity.ai.memory.ExpirableValue; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.ai.memory.MemoryStatus; +import net.minecraft.world.entity.ai.sensing.Sensor; +import net.minecraft.world.entity.ai.sensing.SensorType; +import net.minecraft.world.entity.schedule.Activity; +import net.minecraft.world.entity.schedule.Schedule; +import net.minecraftforge.common.util.BrainBuilder; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import xyz.bluspring.kilt.injections.world.entity.ai.BrainInjection; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +@Mixin(Brain.class) +public abstract class BrainInject implements BrainInjection { + @Shadow @Final private Map, Optional>> memories; + + @Shadow @Final private Map>, Sensor> sensors; + + @Shadow @Final private Map>>> availableBehaviorsByPriority; + + @Shadow public abstract Schedule getSchedule(); + + @Shadow @Final private Map, MemoryStatus>>> activityRequirements; + + @Shadow @Final private Map>> activityMemoriesToEraseWhenStopped; + + @Shadow private Set coreActivities; + + @Shadow private Activity defaultActivity; + + @Shadow @Final private Set activeActivities; + + @Shadow public abstract void setDefaultActivity(Activity newFallbackActivity); + + @Shadow public abstract void setCoreActivities(Set newActivities); + + @Shadow public abstract void setSchedule(Schedule newSchedule); + + @Override + public BrainBuilder createBuilder() { + var builder = new BrainBuilder<>((Brain) (Object) this); + builder.getMemoryTypes().addAll(this.memories.keySet()); + builder.getSensorTypes().addAll(this.sensors.keySet()); + builder.addAvailableBehaviorsByPriorityFrom(this.availableBehaviorsByPriority); + builder.setSchedule(this.getSchedule()); + builder.addActivityRequirementsFrom(this.activityRequirements); + builder.addActivityMemoriesToEraseWhenStoppedFrom(this.activityMemoriesToEraseWhenStopped); + builder.getCoreActivities().addAll(this.coreActivities); + builder.setDefaultActivity(this.defaultActivity); + builder.setActiveActivites(this.activeActivities); + + return builder; + } + + @Override + public void copyFromBuilder(BrainBuilder builder) { + builder.addAvailableBehaviorsByPriorityTo(this.availableBehaviorsByPriority); + this.setSchedule(builder.getSchedule()); + builder.addActivityRequirementsTo(this.activityRequirements); + builder.addActivityMemoriesToEraseWhenStoppedTo(this.activityMemoriesToEraseWhenStopped); + this.setCoreActivities(builder.getCoreActivities()); + this.setDefaultActivity(builder.getDefaultActivity()); + this.activeActivities.addAll(builder.getActiveActivites()); + } +} diff --git a/src/main/java/xyz/bluspring/kilt/injections/world/entity/ai/BrainInjection.java b/src/main/java/xyz/bluspring/kilt/injections/world/entity/ai/BrainInjection.java new file mode 100644 index 00000000..7e93e66f --- /dev/null +++ b/src/main/java/xyz/bluspring/kilt/injections/world/entity/ai/BrainInjection.java @@ -0,0 +1,14 @@ +package xyz.bluspring.kilt.injections.world.entity.ai; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraftforge.common.util.BrainBuilder; + +public interface BrainInjection { + default BrainBuilder createBuilder() { + throw new IllegalStateException(); + } + + default void copyFromBuilder(BrainBuilder builder) { + throw new IllegalStateException(); + } +} diff --git a/src/main/kotlin/net/minecraftforge/fml/IExtensionPoint.kt b/src/main/kotlin/net/minecraftforge/fml/IExtensionPoint.kt index 4906917d..0ad28e17 100644 --- a/src/main/kotlin/net/minecraftforge/fml/IExtensionPoint.kt +++ b/src/main/kotlin/net/minecraftforge/fml/IExtensionPoint.kt @@ -6,10 +6,15 @@ import java.util.function.Supplier interface IExtensionPoint { @JvmRecord data class DisplayTest(val suppliedVersion: Supplier, val remoteVersionTest: BiPredicate) : IExtensionPoint { + constructor(version: String, remoteVersionTest: BiPredicate) : this(Supplier { version }, remoteVersionTest) + companion object { // what the fuck is this @JvmField val IGNORESERVERONLY = "OHNOES\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31\\uD83D\\uDE31" + + @JvmField val IGNORE_SERVER_VERSION = Supplier { DisplayTest(IGNORESERVERONLY) { remoteVersion, isFromServer -> true } } + @JvmField val IGNORE_ALL_VERSION = Supplier { DisplayTest("") { remoteVersion, isFromServer -> true } } } } } \ No newline at end of file diff --git a/src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt b/src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt index 9ddcc287..5d05ae05 100644 --- a/src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt +++ b/src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt @@ -11,11 +11,12 @@ import xyz.bluspring.kilt.Kilt import xyz.bluspring.kilt.loader.KiltModContainer import xyz.bluspring.kilt.loader.mod.ForgeMod import java.util.concurrent.ConcurrentHashMap +import java.util.function.BiPredicate import java.util.function.Supplier -class ModLoadingContext(private val mod: ForgeMod) { +open class ModLoadingContext(protected val mod: ForgeMod) { // this should be Any, but we're only handling Java mods here so - private var languageExtension: FMLJavaModLoadingContext = FMLJavaModLoadingContext(mod) + private var languageExtension: FMLJavaModLoadingContext = if (this is FMLJavaModLoadingContext) this else FMLJavaModLoadingContext(mod) val activeContainer: ModContainer = KiltModContainer(mod) val activeNamespace: String @@ -43,6 +44,19 @@ class ModLoadingContext(private val mod: ForgeMod) { ForgeConfigRegistry.INSTANCE.register(modId, type, spec) } + // TODO: properly implement display tests? + fun registerDisplayTest(displayTest: IExtensionPoint.DisplayTest) { + } + + fun registerDisplayTest(displayTest: Supplier) { + } + + fun registerDisplayTest(version: String, remoteVersion: BiPredicate) { + } + + fun registerDisplayTest(suppliedVersion: Supplier, remoteVersion: BiPredicate) { + } + companion object { // Mapped from Mod ID to ModLoadingContext internal val contexts = ConcurrentHashMap() diff --git a/src/main/kotlin/net/minecraftforge/fml/VersionChecker.kt b/src/main/kotlin/net/minecraftforge/fml/VersionChecker.kt index f2c542be..3ff1d0c9 100644 --- a/src/main/kotlin/net/minecraftforge/fml/VersionChecker.kt +++ b/src/main/kotlin/net/minecraftforge/fml/VersionChecker.kt @@ -15,6 +15,10 @@ class VersionChecker { fun isAnimated(): Boolean { return false } + + fun isOutdated(): Boolean { + return this == OUTDATED || this == BETA_OUTDATED + } } @JvmRecord diff --git a/src/main/kotlin/net/minecraftforge/fml/javafmlmod/FMLJavaModLoadingContext.kt b/src/main/kotlin/net/minecraftforge/fml/javafmlmod/FMLJavaModLoadingContext.kt index f9ff0346..db0db8f3 100644 --- a/src/main/kotlin/net/minecraftforge/fml/javafmlmod/FMLJavaModLoadingContext.kt +++ b/src/main/kotlin/net/minecraftforge/fml/javafmlmod/FMLJavaModLoadingContext.kt @@ -4,7 +4,7 @@ import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.fml.ModLoadingContext import xyz.bluspring.kilt.loader.mod.ForgeMod -class FMLJavaModLoadingContext(private val mod: ForgeMod) { +class FMLJavaModLoadingContext(mod: ForgeMod) : ModLoadingContext(mod) { val modEventBus: IEventBus get() = mod.eventBus diff --git a/src/main/kotlin/net/minecraftforge/fml/loading/FMLLoader.kt b/src/main/kotlin/net/minecraftforge/fml/loading/FMLLoader.kt index 0d6251e6..e0a2f2a1 100644 --- a/src/main/kotlin/net/minecraftforge/fml/loading/FMLLoader.kt +++ b/src/main/kotlin/net/minecraftforge/fml/loading/FMLLoader.kt @@ -43,6 +43,11 @@ object FMLLoader { return VersionInfo } + @JvmStatic + fun getGameLayer(): ModuleLayer { + throw IllegalStateException("Tried accessing module layer, but none exist!") + } + @JvmStatic val gamePath: Path get() = FMLPaths.GAMEDIR.get() diff --git a/src/main/kotlin/xyz/bluspring/kilt/loader/KiltLoader.kt b/src/main/kotlin/xyz/bluspring/kilt/loader/KiltLoader.kt index e9168f66..3222b5f4 100644 --- a/src/main/kotlin/xyz/bluspring/kilt/loader/KiltLoader.kt +++ b/src/main/kotlin/xyz/bluspring/kilt/loader/KiltLoader.kt @@ -21,21 +21,12 @@ import net.minecraft.SharedConstants import net.minecraft.server.Bootstrap import net.minecraftforge.common.ForgeStatesProvider import net.minecraftforge.eventbus.api.Event -import net.minecraftforge.fml.ModList -import net.minecraftforge.fml.ModLoader -import net.minecraftforge.fml.ModLoadingContext -import net.minecraftforge.fml.ModLoadingPhase -import net.minecraftforge.fml.ModLoadingStage +import net.minecraftforge.fml.* import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.config.ConfigTracker import net.minecraftforge.fml.config.ModConfig -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent -import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent -import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent -import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent -import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent +import net.minecraftforge.fml.event.lifecycle.* +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext import net.minecraftforge.fml.loading.FMLPaths import net.minecraftforge.fml.loading.moddiscovery.ModAnnotation import net.minecraftforge.fml.loading.moddiscovery.ModClassVisitor @@ -58,15 +49,7 @@ import xyz.bluspring.kilt.loader.mod.ForgeMod import xyz.bluspring.kilt.loader.mod.LoaderModProvider import xyz.bluspring.kilt.loader.mod.fabric.FabricModProvider import xyz.bluspring.kilt.loader.remap.KiltRemapper -import xyz.bluspring.kilt.util.DeltaTimeProfiler -import xyz.bluspring.kilt.util.KiltHelper -import xyz.bluspring.kilt.util.buildGraph -import xyz.bluspring.kilt.util.collect -import xyz.bluspring.kilt.util.concurrent -import xyz.bluspring.kilt.util.filter -import xyz.bluspring.kilt.util.launchIn -import xyz.bluspring.kilt.util.map -import xyz.bluspring.kilt.util.onEach +import xyz.bluspring.kilt.util.* import java.net.URL import java.nio.file.Path import java.util.concurrent.ConcurrentLinkedQueue @@ -74,16 +57,7 @@ import java.util.function.Consumer import java.util.jar.JarFile import java.util.jar.Manifest import java.util.zip.ZipFile -import kotlin.io.path.createDirectories -import kotlin.io.path.createFile -import kotlin.io.path.div -import kotlin.io.path.exists -import kotlin.io.path.forEachDirectoryEntry -import kotlin.io.path.isDirectory -import kotlin.io.path.name -import kotlin.io.path.nameWithoutExtension -import kotlin.io.path.toPath -import kotlin.io.path.writeBytes +import kotlin.io.path.* import kotlin.system.exitProcess class KiltLoader { @@ -788,7 +762,16 @@ class KiltLoader { val clazz = launcher.loadIntoTarget(it.clazz.className) - mod.modObject = clazz.getDeclaredConstructor().newInstance() + try { + val constructor = clazz.getDeclaredConstructor(FMLJavaModLoadingContext::class.java) + val ctx = FMLJavaModLoadingContext(mod) + + ModLoadingContext.contexts[mod.modId] = ctx + mod.modObject = constructor.newInstance(ctx) + } catch (_: NoSuchMethodException) { + mod.modObject = clazz.getDeclaredConstructor().newInstance() + } + Kilt.logger.info("Initialized new instance of mod $modId.") ModLoadingContext.kiltActiveModId = null diff --git a/src/main/resources/kilt_forge_injects.mixins.json b/src/main/resources/kilt_forge_injects.mixins.json index bf2e5ae0..a4f37903 100644 --- a/src/main/resources/kilt_forge_injects.mixins.json +++ b/src/main/resources/kilt_forge_injects.mixins.json @@ -98,6 +98,7 @@ "world.entity.MobInject", "world.entity.SpawnPlacementsInject", "world.entity.SpawnPlacementsInject$TypeInject", + "world.entity.ai.BrainInject", "world.entity.ai.attributes.AttributeSupplierInject$BuilderInject", "world.entity.ai.attributes.DefaultAttributesInject", "world.entity.player.InventoryInject",