Skip to content

Commit

Permalink
Develop 1.21.1 beta 2 (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD authored Aug 17, 2024
2 parents 48e0ff0 + 0b2b43c commit 63011d8
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
Expand Down
28 changes: 14 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ val versionAdapterDefinition: String by project
val versionAdapterRuntime: String by project
val versionMc: String by project
val versionNeoForge: String by project
val versionParchmentMc: String by project
val versionParchment: String by project
val versionForgeAutoRenamingTool: String by project
val versionForgifiedFabricLoader: String by project
Expand Down Expand Up @@ -47,10 +48,7 @@ logger.lifecycle("Project version: $version")
val mod: SourceSet by sourceSets.creating
val test: SourceSet by sourceSets

val shade: Configuration by configurations.creating {
isTransitive = false
}
val legacyClasspath: Configuration by configurations.creating { isTransitive = false }
val shade: Configuration by configurations.creating
val adapterData: Configuration by configurations.creating

java {
Expand All @@ -72,7 +70,7 @@ configurations {
}

additionalRuntimeClasspath {
extendsFrom(legacyClasspath)
extendsFrom(shade)
}
}

Expand All @@ -87,7 +85,7 @@ neoForge {

parchment {
mappingsVersion = versionParchment
minecraftVersion = versionMc
minecraftVersion = versionParchmentMc
}

runs {
Expand Down Expand Up @@ -134,10 +132,9 @@ repositories {

dependencies {
shade(group = "org.sinytra", name = "forgified-fabric-loader", version = versionForgifiedFabricLoader)
legacyClasspath(group = "org.sinytra", name = "forgified-fabric-loader", version = versionForgifiedFabricLoader, classifier = "full")
legacyClasspath(shade(group = "net.fabricmc", name = "access-widener", version = versionAccessWidener))
legacyClasspath(shade(group = "org.sinytra", name = "ForgeAutoRenamingTool", version = versionForgeAutoRenamingTool))
legacyClasspath(shade(group = "org.sinytra.adapter", name = "definition", version = versionAdapterDefinition) { isTransitive = false })
shade(group = "net.fabricmc", name = "access-widener", version = versionAccessWidener) { isTransitive = false }
shade(group = "org.sinytra", name = "ForgeAutoRenamingTool", version = versionForgeAutoRenamingTool) { isTransitive = false }
shade(group = "org.sinytra.adapter", name = "definition", version = versionAdapterDefinition) { isTransitive = false }
adapterData(group = "org.sinytra.adapter", name = "adapter", version = versionAdapter)

jarJar(implementation(group = "org.sinytra.adapter", name = "runtime", version = versionAdapterRuntime))
Expand All @@ -148,6 +145,8 @@ dependencies {
"modCompileOnly"(sourceSets.main.get().output)

additionalRuntimeClasspath(files(tasks.jar))

implementation("curse.maven:connector-extras-913445:5618470")
}

val modJar: Jar by tasks.creating(Jar::class) {
Expand All @@ -160,10 +159,11 @@ localJarJar("modJarConfig", "org.sinytra:connector-mod", project.version.toStrin
val depsJar: ShadowJar by tasks.creating(ShadowJar::class) {
configurations = listOf(shade)

exclude("assets/fabricloader/**")
exclude("META-INF/*.SF")
exclude("META-INF/*.RSA")
exclude("META-INF/maven/**")
exclude(
"assets/fabricloader/**",
"META-INF/*.SF", "META-INF/*.RSA",
"META-INF/maven/**", "META-INF/jars/**", "META-INF/jarjar/**"
)
exclude("META-INF/services/net.neoforged.neoforgespi.language.IModLanguageLoader")
exclude("ui/**")
exclude("*.json", "*.html", "*.version")
Expand Down
19 changes: 10 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ org.gradle.caching=true
#org.gradle.configuration-cache=true

# Versions
versionConnector=2.0.0-beta.1
versionAdapter=1.13.1+1.21-20240719.094540
versionAdapterDefinition=1.13.16+1.21
versionAdapterRuntime=1.0.0+1.21
versionConnector=2.0.0-beta.2
versionAdapter=1.13.20+1.21.1-20240811.191740
versionAdapterDefinition=1.13.21+1.21.1
versionAdapterRuntime=1.0.0+1.21.1

versionMc=1.21
versionNeoForge=21.0.160
versionParchment=2024.06.23
versionMc=1.21.1
versionNeoForge=21.1.5
versionParchmentMc=1.21
versionParchment=2024.07.28
versionForgeAutoRenamingTool=1.0.12
versionForgifiedFabricLoader=2.5.29+0.16.0+1.21
versionForgifiedFabricLoader=2.5.33+0.16.0+1.21.1
versionAccessWidener=2.1.0
versionForgifiedFabricApi=0.100.7+2.0.8+1.21
versionForgifiedFabricApi=0.102.0+2.0.11+1.21.1

# Publishing
curseForgeId=890127
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/sinytra/connector/ConnectorCoremods.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
import net.neoforged.neoforgespi.coremod.ICoreMod;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.sinytra.adapter.patch.analysis.locals.LocalVariableLookup;
import org.slf4j.Logger;

import java.util.List;
Expand Down Expand Up @@ -113,12 +116,29 @@ public Iterable<? extends ITransformer<?>> getTransformers() {
}
}
);
ITransformer<?> expandLocalVarScope = new BaseTransformer<>(
TargetType.METHOD,
ITransformer.Target.targetMethod("net.minecraft.world.entity.LivingEntity", "forceAddEffect", "(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)V"),
input -> {
LocalVariableLookup lvt = new LocalVariableLookup(input);
LocalVariableNode mobEffect = lvt.getByTypedOrdinal(Type.getObjectType("net/minecraft/world/effect/MobEffectInstance"), 1).orElse(null);
if (mobEffect != null) {
mobEffect.start = lvt.getByIndex(0).start;
input.instructions.insert(mobEffect.start, ASMAPI.listOf(
new InsnNode(Opcodes.ACONST_NULL),
new VarInsnNode(Opcodes.ASTORE, mobEffect.index)
));
LOGGER.debug("Expanded local variable scope for LivingEntity#forceAddEffect index {}", mobEffect.index);
}
}
);

return ImmutableList.<ITransformer<?>>builder()
.add(keyMappingFieldTypeTransform, creativeModeTabConstructorTransform)
.addAll(addedFields)
.addAll(getFabricASMTransformers())
.add(missingOrderingCall)
.add(expandLocalVarScope)
.build();
}

Expand All @@ -128,7 +148,7 @@ private static ITransformer<?> addFieldToClass(String cls, String name, String d
ITransformer.Target.targetClass(cls),
input -> {
input.fields.add(new FieldNode(access, name, desc, null, null));

LOGGER.debug("Added field {} to class {}", name, cls);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public static List<Patch> getPatches() {
return Patch.Result.APPLY;
})
.build(),
// NeoForge moves this behaviour out completely with no viable replacement, so we disable it for now
Patch.builder()
.targetClass("net/minecraft/world/entity/animal/SnowGolem", "net/minecraft/world/entity/animal/Sheep", "net/minecraft/world/entity/animal/MushroomCow")
.targetMethod("mobInteract")
.targetInjectionPoint("Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")
.disable()
.build(),
// ======= Rendering patches
Patch.builder()
.targetClass("net/minecraft/client/renderer/ShaderInstance")
Expand Down Expand Up @@ -151,13 +158,6 @@ public static List<Patch> getPatches() {
})
.modifyInjectionPoint("Lnet/minecraft/client/renderer/entity/layers/ElytraLayer;shouldRender(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/LivingEntity;)Z")
.build(),
// ======= GUI Rendering patches TODO Can adapter automate these?
Patch.builder()
.targetClass("net/minecraft/client/gui/Gui")
.targetMethod("renderPlayerHealth")
.targetInjectionPoint("Lnet/minecraft/client/gui/Gui;renderHearts(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/entity/player/Player;IIIIFIIIZ)V")
.modifyTarget("renderHealthLevel")
.build(),
// ======= TODO Handle in adapter
Patch.builder()
.targetClass("net/minecraft/world/entity/vehicle/Boat")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.util.MethodQualifier;
Expand Down Expand Up @@ -105,20 +107,26 @@ protected void postProcess(ClassNode node) {
}

private void avoidAmbigousMappingRecursion(ClassNode classNode, MethodNode method) {
if (isOverridenMethod(classNode, method)) {
if (isAmbigousOverridenMethod(classNode, method)) {
for (AbstractInsnNode insn : method.instructions) {
if (insn instanceof MethodInsnNode minsn && minsn.owner.equals(classNode.name) && minsn.name.equals(method.name) && minsn.desc.equals(method.desc)) {
method.instructions.set(minsn, new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.superName, minsn.name, minsn.desc, minsn.itf));
if (insn instanceof MethodInsnNode minsn && minsn.getOpcode() == Opcodes.INVOKEVIRTUAL && minsn.owner.equals(classNode.name) && minsn.name.equals(method.name) && minsn.desc.equals(method.desc)) {
List<AbstractInsnNode> insns = MethodCallAnalyzer.findMethodCallParamInsns(method, minsn);
if (!insns.isEmpty() && insns.getFirst() instanceof VarInsnNode varInsn && varInsn.var == 0) {
method.instructions.set(minsn, new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.superName, minsn.name, minsn.desc, minsn.itf));
}
}
}
}
}

private boolean isOverridenMethod(ClassNode classNode, MethodNode method) {
return classNode.superName != null && ((MixinAwareEnhancedRemapper) this.remapper).getUpstreamProvider().getClass(classNode.superName)
.flatMap(m -> m.getMethod(method.name, method.desc))
.filter(m -> (m.getAccess() & (ACC_PRIVATE | ACC_STATIC)) == 0)
.isPresent();
private boolean isAmbigousOverridenMethod(ClassNode classNode, MethodNode method) {
return classNode.superName != null && this.remapper.getClass(classNode.name)
.map(c -> c.getMethods().stream()
.flatMap(Optional::stream)
.filter(m -> !m.getName().equals(m.getMapped()) && m.getMapped().equals(method.name) && method.desc.equals(this.remapper.mapMethodDesc(m.getDescriptor()))
&& (m.getAccess() & (ACC_PRIVATE | ACC_STATIC)) == 0)
.count() > 1)
.orElse(false);
}

private void processMixinAnnotation(AnnotationNode annotation, PostProcessRemapper postProcessRemapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LazyEntityAttributes {

public static void inject() {
for (Holder<Attribute> holder : ATTRIBUTES) {
Holder<Attribute> lazyAttribute = PLACEHOLDERS.computeIfAbsent(holder, s -> Holder.direct(new PlaceholderAttribute()));
Holder<Attribute> lazyAttribute = replaceAttribute(holder);
try {
DEFERRED_HOLDER_SET_VALUE.invoke(holder, lazyAttribute);
} catch (Throwable e) {
Expand All @@ -48,6 +48,10 @@ public static void release() {
}
}

public static Holder<Attribute> replaceAttribute(Holder<Attribute> original) {
return PLACEHOLDERS.computeIfAbsent(original, s -> Holder.direct(new PlaceholderAttribute()));
}

public static void initializeLazyAttributes(EntityAttributeModificationEvent event) {
updateAttributeSuppliers(ObfuscationReflectionHelper.getPrivateValue(DefaultAttributes.class, null, "SUPPLIERS"));
updateAttributeSuppliers(CommonHooks.getAttributesView());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.sinytra.connector.mod.mixin;

import net.minecraft.core.Holder;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import org.sinytra.connector.mod.ConnectorLoader;
import org.sinytra.connector.mod.compat.LazyEntityAttributes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(AttributeSupplier.Builder.class)
public abstract class AttributeSupplierBuilderMixin {

// Mitigates https://github.com/Sinytra/Connector/issues/1298
@ModifyVariable(method = "create", at = @At("HEAD"), argsOnly = true)
private Holder<Attribute> onCreate(Holder<Attribute> original) {
if (ConnectorLoader.isLoading()) {
try {
original.value();
} catch (NullPointerException n) {
// Likely a deferred holder that has not been initialized yet
return LazyEntityAttributes.replaceAttribute(original);
}
}
return original;
}
}
10 changes: 5 additions & 5 deletions src/mod/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ logoFile="logo.png"
authors="Su5eD"
displayURL="https://github.com/Sinytra/Connector"
description='''
Connector is a translation/compatibility layer that allows running Fabric mods on MinecraftForge.
Connector is a translation/compatibility layer that allows running Fabric mods on NeoForge.
Its goal is to bring the two platforms closer together, saving developers time and effort maintaining their mods for
multiple platforms at once, as well as allowing players to play all their favourite mods in one modpack.
'''
displayTest = 'IGNORE_ALL_VERSION' # Connector is optional for both sides
[[mixins]]
config="connector.mixins.json"
[[dependencies.connectormod]]
[[dependencies.connector]]
modId="neoforge"
mandatory=true
type="required"
versionRange="*"
ordering="NONE"
side="BOTH"
[[dependencies.connectormod]]
[[dependencies.connector]]
modId="minecraft"
mandatory=true
type="required"
versionRange="[1.21,1.22)"
ordering="NONE"
side="BOTH"
10 changes: 6 additions & 4 deletions src/mod/resources/connector.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"compatibilityLevel": "JAVA_17",
"plugin": "org.sinytra.connector.mod.ConnectorBootstrap",
"mixins": [
"AttributeSupplierBuilderMixin",
"ChunkGeneratorMixin",
"CommonHooksMixin",
"PlayerListMixin",
"ChunkGeneratorMixin",
"boot.DatagenModLoaderMixin",
"item.IItemExtensionMixin",
"item.ItemStackMixin",
Expand All @@ -17,21 +18,22 @@
"recipebook.RecipeBookManagerMixin",
"registries.DataPackRegistriesHooksAccessor",
"registries.MappedRegistryAccessor",
"registries.NeoForgeRegistriesSetupAccessor",
"registries.BuiltInRegistriesMixin",
"registries.EntityDataSerializersMixin",
"registries.NeoForgeRegistriesSetupAccessor",
"registries.ItemBlockRenderTypesMixin",
"registries.NeoForgeRegistriesSetupMixin",
"registries.NetworkRegistryMixin",
"registries.PoiTypesMixin",
"registries.RegistryDataLoaderMixin"
],
"client": [
"boot.MinecraftMixin",
"client.BlockColorsMixin",
"client.ForgeHooksClientMixin",
"client.ItemColorsMixin",
"client.ItemOverridesMixin",
"client.KeyMappingMixin",
"client.BlockColorsMixin",
"client.ItemColorsMixin",
"client.ParticleEngineMixin"
],
"server": [
Expand Down

0 comments on commit 63011d8

Please sign in to comment.