Skip to content

Commit

Permalink
Add Continuity CTM patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Oct 27, 2023
1 parent 810a75e commit a83425f
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ Integrates ModMenu the config screen factory with Forge's mod list gui. Includes
[ModMenu API](https://github.com/TerraformersMC/ModMenu/tree/91460879c6d0693b14d1632baccea56bf3619f2e/src/main/java/com/terraformersmc/modmenu/api),
licensed under the MIT license.

### Continuity Compat

Fixes Continuity's connected textures for modded blocks. By default, Continuity builds a map of model IDs to
all registered blocks in its client initializer (`ModelWrappingHandler#createBlockStateModelIdMap`).
However, this is too soon as it happens before blocks of Forge mods are registered. As a results, CTM models will not
be created for Forge mod blocks. To fix this issue, we patch Continuity to move the block state map initialization from
Fabric's client entrypoint to FML's client setup event, which is fired after registration has completed.

## Get help

If you're having trouble using Connector Extras or believe it is not functioning correctly, ask us
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
includeProject("terrablender-bridge")
includeProject("geckolib-fabric-compat")
includeProject("modmenu-bridge")
includeProject("continuity-compat")

// Misc
modImplementation("curse.maven:mcpitanlibarch-682213:4723157")
Expand Down Expand Up @@ -164,6 +165,7 @@ publishMods {
optional { slug.set("terrablender") }
optional { slug.set("architectury-api") }
optional { slug.set("geckolib") }
optional { slug.set("continuity") }
}
modrinth {
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
Expand All @@ -178,5 +180,6 @@ publishMods {
optional { id.set("lhGA9TYQ") } // Architectury API
optional { id.set("8BmcQJ2H") } // Geckolib
optional { id.set("mOgUt4GM") } // Mod Menu
optional { id.set("1IjD5062") } // Continuity
}
}
22 changes: 22 additions & 0 deletions continuity-compat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("dev.architectury.loom")
}

val versionMc: String by rootProject
val versionForge: String by rootProject

loom {
forge {
mixinConfig("mixins.connectorextras_continuity_compat.json")
}
mixin {
defaultRefmapName.set("refmap.connectorextras_continuity_compat.json")
}
}

dependencies {
mappings(loom.officialMojangMappings())
forge(group = "net.minecraftforge", name = "forge", version = "$versionMc-$versionForge")

implementation(project(path = ":intermediary-deobf", configuration = "modRuntimeClasspathMainMapped"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.su5ed.sinytra.connectorextras.continuitycompat;

import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(ContinuityCompat.MODID)
public class ContinuityCompat {
public static final String MODID = "connectorextras_continuity_compat";
public static final String CONTINUITY_MODID = "continuity";

public ContinuityCompat() {
if (ModList.get().isLoaded(CONTINUITY_MODID)) {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus.addListener(ContinuityCompatSetup::onClientSetup);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.su5ed.sinytra.connectorextras.continuitycompat;

import com.google.common.base.Suppliers;
import net.minecraftforge.fml.loading.LoadingModList;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

public class ContinuityCompatMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> CONTINUITY_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById(ContinuityCompat.CONTINUITY_MODID) != null);

@Override
public void onLoad(String mixinPackage) {}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return CONTINUITY_LOADED.get();
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.su5ed.sinytra.connectorextras.continuitycompat;

import dev.su5ed.sinytra.connectorextras.continuitycompat.mixin.ModelWrappingHandlerAccessor;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

public class ContinuityCompatSetup {

public static void onClientSetup(FMLClientSetupEvent event) {
ModelWrappingHandlerAccessor.setBLOCK_STATE_MODEL_IDS(ModelWrappingHandlerAccessor.callCreateBlockStateModelIdMap());
}

private ContinuityCompatSetup() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.su5ed.sinytra.connectorextras.continuitycompat.mixin;

import com.google.common.collect.ImmutableMap;
import me.pepperbell.continuity.client.resource.ModelWrappingHandler;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ModelWrappingHandler.class)
public interface ModelWrappingHandlerAccessor {
@Accessor
@Mutable
static void setBLOCK_STATE_MODEL_IDS(ImmutableMap<ModelResourceLocation, BlockState> map) {
throw new UnsupportedOperationException();
}

@Invoker
static ImmutableMap<ModelResourceLocation, BlockState> callCreateBlockStateModelIdMap() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.su5ed.sinytra.connectorextras.continuitycompat.mixin;

import com.google.common.collect.ImmutableMap;
import me.pepperbell.continuity.client.resource.ModelWrappingHandler;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ModelWrappingHandler.class)
public class ModelWrappingHandlerMixin {
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lme/pepperbell/continuity/client/resource/ModelWrappingHandler;createBlockStateModelIdMap()Lcom/google/common/collect/ImmutableMap;"))
private static ImmutableMap<ModelResourceLocation, BlockState> onClinit() {
return ImmutableMap.of();
}
}
27 changes: 27 additions & 0 deletions continuity-compat/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
modLoader="javafml"
loaderVersion="[47,)"
license="MIT"
issueTrackerURL="https://github.com/Sinytra/ConnectorExtras/issues"

[[mods]]
modId="connectorextras_continuity_compat"
version="${file.jarVersion}"
displayName="Connector Extras Continuity Compat"
authors="Su5eD"
displayURL="https://github.com/Sinytra/ConnectorExtras"
description='''
Fixes Continuity's connected textures for modded blocks
'''
displayTest = 'IGNORE_ALL_VERSION'
[[dependencies.connectorextras_continuity_compat]]
modId="forge"
mandatory=true
versionRange="[47,)"
ordering="NONE"
side="BOTH"
[[dependencies.connectorextras_continuity_compat]]
modId="minecraft"
mandatory=true
versionRange="[1.20.1,1.21)"
ordering="NONE"
side="BOTH"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"minVersion": "0.8",
"compatibilityLevel": "JAVA_16",
"required": true,
"package": "dev.su5ed.sinytra.connectorextras.continuitycompat.mixin",
"plugin": "dev.su5ed.sinytra.connectorextras.continuitycompat.ContinuityCompatMixinPlugin",
"client": [
"ModelWrappingHandlerAccessor",
"ModelWrappingHandlerMixin"
]
}
6 changes: 6 additions & 0 deletions continuity-compat/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "The default data for connectorextras_continuity_compat",
"pack_format": 15
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ loom.platform=forge
# Versions
versionMc=1.20.1
versionForge=47.1.3
versionConnectorExtras=1.4.2
versionConnectorExtras=1.5.0

# Publishing
curseForgeId=913445
Expand Down
8 changes: 8 additions & 0 deletions intermediary-deobf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ repositories {
name = "GeckoLib"
url = uri("https://dl.cloudsmith.io/public/geckolib3/geckolib/maven")
}
maven {
name = "CurseMaven"
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
}
}

dependencies {
Expand All @@ -20,4 +27,5 @@ dependencies {
modImplementation(group = "software.bernie.geckolib", name = "geckolib-fabric-1.20.1", version = "4.2.2") {
isTransitive = false
}
modImplementation(group = "curse.maven", name = "continuity-531351", version = "4779473")
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ include(
"architectury-bridge",
"terrablender-bridge",
"geckolib-fabric-compat",
"modmenu-bridge"
"modmenu-bridge",
"continuity-compat"
)

0 comments on commit a83425f

Please sign in to comment.