-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working towards fixing Immersive Engineering
- Loading branch information
Showing
13 changed files
with
298 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...luspring/kilt/forgeinjects/world/level/block/entity/AbstractFurnaceBlockEntityInject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package xyz.bluspring.kilt.forgeinjects.world.level.block.entity; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.item.crafting.AbstractCookingRecipe; | ||
import net.minecraft.world.item.crafting.RecipeType; | ||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; | ||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ForgeCapabilities; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.wrapper.SidedInvWrapper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
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(AbstractFurnaceBlockEntity.class) | ||
public abstract class AbstractFurnaceBlockEntityInject extends BaseContainerBlockEntity { | ||
private RecipeType<? extends AbstractCookingRecipe> recipeType; | ||
|
||
protected AbstractFurnaceBlockEntityInject(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { | ||
super(blockEntityType, blockPos, blockState); | ||
} | ||
|
||
@Inject(method = "<init>", at = @At("TAIL")) | ||
private void kilt$initRecipeType(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState, RecipeType<? extends AbstractCookingRecipe> recipeType, CallbackInfo ci) { | ||
this.recipeType = recipeType; | ||
} | ||
|
||
LazyOptional<? extends IItemHandler>[] handlers = SidedInvWrapper.create((AbstractFurnaceBlockEntity) (Object) this, Direction.UP, Direction.DOWN, Direction.NORTH); | ||
|
||
@Override | ||
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { | ||
if (!this.remove && side != null && cap == ForgeCapabilities.ITEM_HANDLER) { | ||
if (side == Direction.UP) | ||
return handlers[0].cast(); | ||
else if (side == Direction.DOWN) | ||
return handlers[1].cast(); | ||
else | ||
return handlers[2].cast(); | ||
} | ||
return super.getCapability(cap, side); | ||
} | ||
|
||
@Override | ||
public void invalidateCaps() { | ||
super.invalidateCaps(); | ||
for (LazyOptional<? extends IItemHandler> handler : handlers) { | ||
handler.invalidate(); | ||
} | ||
} | ||
|
||
@Override | ||
public void reviveCaps() { | ||
super.reviveCaps(); | ||
this.handlers = SidedInvWrapper.create((AbstractFurnaceBlockEntity) (Object) this, Direction.UP, Direction.DOWN, Direction.NORTH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/cpw/mods/modlauncher/api/ILaunchHandlerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cpw.mods.modlauncher.api | ||
|
||
/** | ||
* A singleton instance of this is loaded by the system to designate the launch target | ||
*/ | ||
interface ILaunchHandlerService { | ||
fun name(): String | ||
|
||
@Deprecated("") | ||
fun configureTransformationClassLoader(builder: ITransformingClassLoaderBuilder) | ||
|
||
fun launchService(arguments: Array<String>, gameLayer: ModuleLayer): ServiceRunner | ||
|
||
fun getPaths(): Array<NamedPath> { | ||
return arrayOf() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/cpw/mods/modlauncher/api/ITransformingClassLoaderBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cpw.mods.modlauncher.api | ||
|
||
import java.net.URL | ||
import java.nio.file.Path | ||
import java.util.* | ||
import java.util.function.Function | ||
|
||
|
||
interface ITransformingClassLoaderBuilder { | ||
fun addTransformationPath(path: Path) | ||
|
||
fun setClassBytesLocator(additionalClassBytesLocator: Function<String, Optional<URL>>) | ||
|
||
fun setResourceEnumeratorLocator(resourceEnumeratorLocator: Function<String?, Enumeration<URL>>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cpw.mods.modlauncher.api | ||
|
||
import java.nio.file.Path | ||
|
||
class NamedPath( | ||
val name: String, | ||
vararg paths: Path | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cpw.mods.modlauncher.api | ||
|
||
fun interface ServiceRunner { | ||
@Throws(Throwable::class) | ||
fun run() | ||
|
||
companion object { | ||
@JvmField | ||
val NOOP = ServiceRunner {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/net/minecraftforge/fml/loading/targets/CommonLaunchHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package net.minecraftforge.fml.loading.targets | ||
|
||
import com.mojang.logging.LogUtils | ||
import cpw.mods.modlauncher.api.ILaunchHandlerService | ||
import cpw.mods.modlauncher.api.ITransformingClassLoaderBuilder | ||
import net.minecraftforge.api.distmarker.Dist | ||
import net.minecraftforge.fml.loading.LogMarkers | ||
import org.slf4j.Logger | ||
import java.io.File | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import java.util.* | ||
import java.util.function.BiPredicate | ||
import java.util.stream.Collectors | ||
|
||
|
||
abstract class CommonLaunchHandler : ILaunchHandlerService { | ||
data class LocatedPaths( | ||
val minecraftPaths: List<Path>, | ||
val minecraftFilter: BiPredicate<String, String>, | ||
val otherModPaths: List<List<Path>>, | ||
val otherArtifacts: List<Path> | ||
) | ||
|
||
abstract fun getDist(): Dist | ||
|
||
abstract fun getNaming(): String | ||
|
||
open fun isProduction(): Boolean { | ||
return false | ||
} | ||
|
||
open fun isData(): Boolean { | ||
return false | ||
} | ||
|
||
abstract fun getMinecraftPaths(): LocatedPaths | ||
|
||
override fun configureTransformationClassLoader(builder: ITransformingClassLoaderBuilder) {} | ||
|
||
protected fun getModClasses(): Map<String, List<Path>> { | ||
val modClasses: String = Optional.ofNullable(System.getenv("MOD_CLASSES")).orElse("") | ||
LOGGER.debug(LogMarkers.CORE, "Got mod coordinates {} from env", modClasses) | ||
data class ExplodedModPath(val modid: String, val path: Path) | ||
|
||
// "a/b/;c/d/;" -> "modid%%c:\fish\pepper;modid%%c:\fish2\pepper2\;modid2%%c:\fishy\bums;modid2%%c:\hmm" | ||
val modClassPaths = | ||
Arrays.stream(modClasses.split(File.pathSeparator.toRegex()).dropLastWhile { it.isEmpty() } | ||
.toTypedArray()) | ||
.map { inp -> inp.split("%%", limit = 2) } | ||
.map { splitString -> | ||
ExplodedModPath( | ||
if (splitString.size == 1) "defaultmodid" else splitString[0], | ||
Paths.get(splitString[splitString.size - 1]) | ||
) | ||
} | ||
.collect( | ||
Collectors.groupingBy( | ||
ExplodedModPath::modid, | ||
Collectors.mapping(ExplodedModPath::path, Collectors.toList()) | ||
) | ||
) | ||
LOGGER.debug(LogMarkers.CORE, "Found supplied mod coordinates [{}]", modClassPaths) | ||
|
||
//final var explodedTargets = ((Map<String, List<ExplodedDirectoryLocator.ExplodedMod>>)arguments).computeIfAbsent("explodedTargets", a -> new ArrayList<>()); | ||
//modClassPaths.forEach((modlabel,paths) -> explodedTargets.add(new ExplodedDirectoryLocator.ExplodedMod(modlabel, paths))); | ||
return modClassPaths | ||
} | ||
|
||
companion object { | ||
protected val LOGGER: Logger = LogUtils.getLogger() | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/net/minecraftforge/fml/loading/targets/KnotLaunchHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.minecraftforge.fml.loading.targets | ||
|
||
import cpw.mods.modlauncher.api.ServiceRunner | ||
import net.fabricmc.api.EnvType | ||
import net.fabricmc.loader.api.FabricLoader | ||
import net.minecraftforge.api.distmarker.Dist | ||
import xyz.bluspring.kilt.loader.remap.KiltRemapper | ||
|
||
class KnotLaunchHandler : CommonLaunchHandler() { | ||
override fun getDist(): Dist { | ||
return if (FabricLoader.getInstance().environmentType == EnvType.CLIENT) | ||
Dist.CLIENT | ||
else | ||
Dist.DEDICATED_SERVER | ||
} | ||
|
||
override fun getNaming(): String { | ||
return FabricLoader.getInstance().mappingResolver.currentRuntimeNamespace | ||
} | ||
|
||
private val paths = LocatedPaths( | ||
KiltRemapper.getGameClassPath().toList(), { _, _ -> | ||
true | ||
}, | ||
listOf(), listOf() | ||
) | ||
|
||
override fun getMinecraftPaths(): LocatedPaths { | ||
return paths | ||
} | ||
|
||
override fun name(): String { | ||
return "knot" | ||
} | ||
|
||
override fun launchService(arguments: Array<String>, gameLayer: ModuleLayer): ServiceRunner { | ||
return ServiceRunner.NOOP | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...main/kotlin/xyz/bluspring/kilt/loader/remap/fixers/CompatibleCapabilityWorkaroundFixer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package xyz.bluspring.kilt.loader.remap.fixers | ||
|
||
import net.fabricmc.loader.api.FabricLoader | ||
import org.objectweb.asm.Opcodes | ||
import org.objectweb.asm.tree.AbstractInsnNode | ||
import org.objectweb.asm.tree.ClassNode | ||
import org.objectweb.asm.tree.MethodInsnNode | ||
|
||
object CompatibleCapabilityWorkaroundFixer { | ||
private val mappingResolver = FabricLoader.getInstance().mappingResolver | ||
private val workaroundClasses = listOf( | ||
mappingResolver.mapClassName("intermediary", "net.minecraft.class_1799").replace(".", "/") | ||
) | ||
|
||
fun fixClass(classNode: ClassNode) { | ||
for (method in classNode.methods) { | ||
val newNodeMap = mutableMapOf<AbstractInsnNode, AbstractInsnNode>() | ||
|
||
for (insnNode in method.instructions) { | ||
// Target virtual invokes specifically | ||
if (insnNode is MethodInsnNode && insnNode.opcode == Opcodes.INVOKEVIRTUAL) { | ||
if (!workaroundClasses.contains(insnNode.owner)) | ||
continue | ||
|
||
if (insnNode.name != "areCapsCompatible") | ||
continue | ||
|
||
val node = MethodInsnNode(insnNode.opcode, insnNode.owner, insnNode.name, "(Lnet/minecraftforge/common/capabilities/ICapabilityProviderImpl;)Z") | ||
newNodeMap[insnNode] = node | ||
} | ||
} | ||
|
||
if (newNodeMap.isNotEmpty()) { | ||
for ((oldNode, newNode) in newNodeMap) { | ||
method.instructions.set(oldNode, newNode) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters