Skip to content

Commit

Permalink
Properly update and rebase everything to LexForge 47.3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Nov 30, 2024
1 parent df826cf commit 141bd91
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 52 deletions.
2 changes: 1 addition & 1 deletion forge
Submodule forge updated 423 files
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<E extends LivingEntity> implements BrainInjection<E> {
@Shadow @Final private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories;

@Shadow @Final private Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors;

@Shadow @Final private Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority;

@Shadow public abstract Schedule getSchedule();

@Shadow @Final private Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements;

@Shadow @Final private Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped;

@Shadow private Set<Activity> coreActivities;

@Shadow private Activity defaultActivity;

@Shadow @Final private Set<Activity> activeActivities;

@Shadow public abstract void setDefaultActivity(Activity newFallbackActivity);

@Shadow public abstract void setCoreActivities(Set<Activity> newActivities);

@Shadow public abstract void setSchedule(Schedule newSchedule);

@Override
public BrainBuilder<E> createBuilder() {
var builder = new BrainBuilder<>((Brain<E>) (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<E> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<E extends LivingEntity> {
default BrainBuilder<E> createBuilder() {
throw new IllegalStateException();
}

default void copyFromBuilder(BrainBuilder<E> builder) {
throw new IllegalStateException();
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/net/minecraftforge/fml/IExtensionPoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import java.util.function.Supplier
interface IExtensionPoint<T : Record> {
@JvmRecord
data class DisplayTest(val suppliedVersion: Supplier<String>, val remoteVersionTest: BiPredicate<String, Boolean>) : IExtensionPoint<DisplayTest> {
constructor(version: String, remoteVersionTest: BiPredicate<String, Boolean>) : 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 } }
}
}
}
18 changes: 16 additions & 2 deletions src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IExtensionPoint.DisplayTest>) {
}

fun registerDisplayTest(version: String, remoteVersion: BiPredicate<String, Boolean>) {
}

fun registerDisplayTest(suppliedVersion: Supplier<String>, remoteVersion: BiPredicate<String, Boolean>) {
}

companion object {
// Mapped from Mod ID to ModLoadingContext
internal val contexts = ConcurrentHashMap<String, ModLoadingContext>()
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/net/minecraftforge/fml/VersionChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class VersionChecker {
fun isAnimated(): Boolean {
return false
}

fun isOutdated(): Boolean {
return this == OUTDATED || this == BETA_OUTDATED
}
}

@JvmRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/net/minecraftforge/fml/loading/FMLLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 15 additions & 32 deletions src/main/kotlin/xyz/bluspring/kilt/loader/KiltLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,32 +49,15 @@ 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
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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/kilt_forge_injects.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 141bd91

Please sign in to comment.