feat: use AnvilLib beardifier
This commit is contained in:
parent
44dadab184
commit
f222651ce9
|
@ -11,7 +11,7 @@ dependencies {
|
|||
// Do NOT use other classes from fabric loader
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
|
||||
modImplementation("net.anvilcraft:anvillib-18:0.2.0") {transitive = false}
|
||||
modImplementation("net.anvilcraft:anvillib-18:1.1.0") {transitive = false}
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
// modApi "dev.architectury:architectury:${rootProject.architectury_version}"
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ public class WBStructures {
|
|||
new AdvancedStructurePoolFeatureConfig(
|
||||
AncientCityStructurePieces.START,
|
||||
7,
|
||||
116
|
||||
116,
|
||||
true
|
||||
),
|
||||
WBBiomeTags.HAS_ANCIENT_CITY,
|
||||
true,
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package com.cursedcauldron.wildbackport.core.mixinhelper;
|
||||
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
|
||||
public record BeardifierLocals(
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
StructurePiece structurePiece,
|
||||
BoundingBox boundingBox,
|
||||
int l,
|
||||
int m
|
||||
) {}
|
|
@ -30,7 +30,7 @@ dependencies {
|
|||
// modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"
|
||||
modImplementation("com.github.glitchfiend:TerraBlender-fabric:${minecraft_version}-${terrablender_version}")
|
||||
|
||||
modImplementation("net.anvilcraft:anvillib-18-fabric:0.2.0") {transitive = false}
|
||||
modImplementation("net.anvilcraft:anvillib-18-fabric:1.1.0") {transitive = false}
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
package com.cursedcauldron.wildbackport.core.mixin.fabric.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
import com.cursedcauldron.wildbackport.common.worldgen.features.AncientCityFeature;
|
||||
import com.cursedcauldron.wildbackport.core.mixinhelper.BeardifierLocals;
|
||||
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.levelgen.Beardifier;
|
||||
import net.minecraft.world.level.levelgen.DensityFunction;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
|
||||
/**
|
||||
* This mixin is responsible for reimplementing 1.19's BEARD_BOX which causes terrain
|
||||
* to be removed around ancient city structures.
|
||||
*/
|
||||
@Mixin(Beardifier.class)
|
||||
public class BeardifierMixin {
|
||||
private static ThreadLocal<BeardifierLocals> currentLocals = new ThreadLocal<>();
|
||||
@Unique
|
||||
private Map<Object, StructureFeature<?>> featureMap = new HashMap<>();
|
||||
|
||||
@ModifyArgs(
|
||||
method = "method_38319",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lit/unimi/dsi/fastutil/objects/ObjectList;add(Ljava/lang/Object;)Z"
|
||||
),
|
||||
remap = false
|
||||
)
|
||||
private void
|
||||
addStructurePieceToMap(
|
||||
Args args, ChunkPos alec1, int alec2, int alec3, StructureStart ss
|
||||
) {
|
||||
featureMap.put(args.get(0), ss.getFeature().feature);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "compute",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target
|
||||
= "Lnet/minecraft/world/level/levelgen/structure/StructurePiece;getNoiseEffect()Lnet/minecraft/world/level/levelgen/feature/NoiseEffect;"
|
||||
),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void
|
||||
collectVariables(
|
||||
DensityFunction.FunctionContext alec1,
|
||||
CallbackInfoReturnable<Double> ci,
|
||||
int i,
|
||||
int j,
|
||||
int k,
|
||||
double alec2,
|
||||
StructurePiece structurePiece,
|
||||
BoundingBox boundingBox,
|
||||
int l,
|
||||
int m
|
||||
) {
|
||||
currentLocals.set(new BeardifierLocals(i, j, k, structurePiece, boundingBox, l, m)
|
||||
);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
private static double getBeardContribution(int l, int m, int n) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "compute",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target
|
||||
= "Lnet/minecraft/world/level/levelgen/Beardifier;getBeardContribution(III)D"
|
||||
)
|
||||
)
|
||||
private double
|
||||
beardContribution(int l, int m, int n) {
|
||||
BeardifierLocals locals = currentLocals.get();
|
||||
if (locals == null)
|
||||
return getBeardContribution(l, m, n);
|
||||
currentLocals.remove();
|
||||
|
||||
StructureFeature<?> sf = this.featureMap.get(locals.structurePiece());
|
||||
if (sf == null /* WTF */ || !(sf instanceof AncientCityFeature))
|
||||
return getBeardContribution(l, m, n);
|
||||
|
||||
int q = Math.max(0, Math.max(-m, locals.y() - locals.boundingBox().maxY()));
|
||||
|
||||
return getAncientCityBeardContribution(l, q, n, m);
|
||||
}
|
||||
|
||||
private static double getAncientCityBeardContribution(int i, int j, int k, int l) {
|
||||
int m = i + 12;
|
||||
int n = j + 12;
|
||||
int o = k + 12;
|
||||
if (!(m >= 0 && m < 24 && n >= 0 && n < 24 && o >= 0 && o < 24)) {
|
||||
return 0.0;
|
||||
}
|
||||
double d = (double) l + 0.5;
|
||||
double e = Mth.lengthSquared(i, d, k);
|
||||
double f = -d * Mth.fastInvSqrt(e / 2.0) / 2.0;
|
||||
return f * (double) computeBeardContribution(o - 12, m - 12, n - 12);
|
||||
}
|
||||
|
||||
private static double computeBeardContribution(int i, double d, int j) {
|
||||
double e = Mth.lengthSquared(i, d, j);
|
||||
double f = Math.pow(Math.E, -e / 16.0);
|
||||
return f;
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@
|
|||
"fabricloader": ">=0.14.8",
|
||||
"minecraft": ">=1.18.2",
|
||||
"terrablender": ">=1.0.0.59",
|
||||
"anvillib": ">=0.2.0"
|
||||
"anvillib": ">=1.1.0"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"package": "com.cursedcauldron.wildbackport.core.mixin.fabric",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"access.BiomeAccessor",
|
||||
"common.BeardifierMixin"
|
||||
"access.BiomeAccessor"
|
||||
],
|
||||
"client": [
|
||||
"client.FogRendererMixin",
|
||||
|
|
|
@ -37,7 +37,7 @@ dependencies {
|
|||
forge "net.minecraftforge:forge:${rootProject.forge_version}"
|
||||
modApi "com.github.glitchfiend:TerraBlender-forge:${minecraft_version}-${terrablender_version}"
|
||||
|
||||
modImplementation("net.anvilcraft:anvillib-18-forge:0.2.0") {transitive = false}
|
||||
modImplementation("net.anvilcraft:anvillib-18-forge:1.1.0") {transitive = false}
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
package com.cursedcauldron.wildbackport.core.mixin.forge.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import com.cursedcauldron.wildbackport.common.worldgen.features.AncientCityFeature;
|
||||
import com.cursedcauldron.wildbackport.core.mixinhelper.BeardifierLocals;
|
||||
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.levelgen.Beardifier;
|
||||
import net.minecraft.world.level.levelgen.DensityFunction;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
|
||||
/**
|
||||
* This mixin is responsible for reimplementing 1.19's BEARD_BOX which causes terrain
|
||||
* to be removed around ancient city structures.
|
||||
*/
|
||||
@Mixin(Beardifier.class)
|
||||
public class BeardifierMixin {
|
||||
private static ThreadLocal<BeardifierLocals> currentLocals = new ThreadLocal<>();
|
||||
@Unique
|
||||
private Map<Object, StructureFeature<?>> featureMap = new HashMap<>();
|
||||
|
||||
// This is different than the fabric implementation where this is @ModifyArgs, but
|
||||
// that's borked on Forge (as per usual).
|
||||
@Inject(
|
||||
// for this nonsense to work in the devenv, replace this with method_38319
|
||||
// for prod, use m_208194_
|
||||
// very elegant!
|
||||
method = "m_208194_",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lit/unimi/dsi/fastutil/objects/ObjectList;add(Ljava/lang/Object;)Z"
|
||||
),
|
||||
remap = false,
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void
|
||||
addStructurePieceToMap(
|
||||
ChunkPos alec1,
|
||||
int alec2,
|
||||
int alec3,
|
||||
StructureStart ss,
|
||||
CallbackInfo ci,
|
||||
Iterator<?> alec4,
|
||||
StructurePiece sp
|
||||
) {
|
||||
featureMap.put(sp, ss.getFeature().feature);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "compute",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target
|
||||
= "Lnet/minecraft/world/level/levelgen/structure/StructurePiece;getNoiseEffect()Lnet/minecraft/world/level/levelgen/feature/NoiseEffect;"
|
||||
),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void
|
||||
collectVariables(
|
||||
DensityFunction.FunctionContext alec1,
|
||||
CallbackInfoReturnable<Double> ci,
|
||||
int i,
|
||||
int j,
|
||||
int k,
|
||||
double alec2,
|
||||
StructurePiece structurePiece,
|
||||
BoundingBox boundingBox,
|
||||
int l,
|
||||
int m
|
||||
) {
|
||||
currentLocals.set(new BeardifierLocals(i, j, k, structurePiece, boundingBox, l, m)
|
||||
);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
protected static double getBeardContribution(int l, int m, int n) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "compute",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target
|
||||
= "Lnet/minecraft/world/level/levelgen/Beardifier;getBeardContribution(III)D"
|
||||
)
|
||||
)
|
||||
private double
|
||||
beardContribution(int l, int m, int n) {
|
||||
BeardifierLocals locals = currentLocals.get();
|
||||
if (locals == null)
|
||||
return getBeardContribution(l, m, n);
|
||||
currentLocals.remove();
|
||||
|
||||
StructureFeature<?> sf = this.featureMap.get(locals.structurePiece());
|
||||
if (sf == null /* WTF */ || !(sf instanceof AncientCityFeature))
|
||||
return getBeardContribution(l, m, n);
|
||||
|
||||
int q = Math.max(0, Math.max(-m, locals.y() - locals.boundingBox().maxY()));
|
||||
|
||||
return getAncientCityBeardContribution(l, q, n, m);
|
||||
}
|
||||
|
||||
private static double getAncientCityBeardContribution(int i, int j, int k, int l) {
|
||||
int m = i + 12;
|
||||
int n = j + 12;
|
||||
int o = k + 12;
|
||||
if (!(m >= 0 && m < 24 && n >= 0 && n < 24 && o >= 0 && o < 24)) {
|
||||
return 0.0;
|
||||
}
|
||||
double d = (double) l + 0.5;
|
||||
double e = Mth.lengthSquared(i, d, k);
|
||||
double f = -d * Mth.fastInvSqrt(e / 2.0) / 2.0;
|
||||
return f * (double) computeBeardContribution(o - 12, m - 12, n - 12);
|
||||
}
|
||||
|
||||
private static double computeBeardContribution(int i, double d, int j) {
|
||||
double e = Mth.lengthSquared(i, d, j);
|
||||
double f = Math.pow(Math.E, -e / 16.0);
|
||||
return f;
|
||||
}
|
||||
}
|
|
@ -36,6 +36,6 @@ license = "All Rights Reserved"
|
|||
[[dependencies.wildbackport]]
|
||||
modId="anvillib"
|
||||
mandatory=true
|
||||
versionRange="[0.2.0,)"
|
||||
versionRange="[1.1.0,)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
|
@ -3,9 +3,7 @@
|
|||
"minVersion": "0.8",
|
||||
"package": "com.cursedcauldron.wildbackport.core.mixin.forge",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"common.BeardifierMixin"
|
||||
],
|
||||
"mixins": [],
|
||||
"client": [],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
@ -4,7 +4,7 @@ minecraft_version=1.18.2
|
|||
enabled_platforms=fabric,forge
|
||||
|
||||
archives_base_name=wildbackport
|
||||
mod_version=2.0.0
|
||||
mod_version=2.1.0
|
||||
maven_group=com.cursedcauldron
|
||||
|
||||
fabric_loader_version=0.14.8
|
||||
|
|
Loading…
Reference in New Issue