Skip to content

Commit 8e26af8

Browse files
committed
fix: blending hopefully
1 parent 0b7231d commit 8e26af8

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ishland.c2me.opts.dfc.common.ducks;
2+
3+
public interface IBlendingAwareVisitor {
4+
5+
boolean c2me$isBlendingEnabled();
6+
7+
}

c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/CompiledDensityFunction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.base.Suppliers;
44
import com.ishland.c2me.opts.dfc.common.ast.EvalType;
55
import com.ishland.c2me.opts.dfc.common.ducks.IArrayCacheCapable;
6+
import com.ishland.c2me.opts.dfc.common.ducks.IBlendingAwareVisitor;
67
import com.ishland.c2me.opts.dfc.common.ducks.IFastCacheLike;
78
import com.ishland.c2me.opts.dfc.common.util.ArrayCache;
89
import com.ishland.c2me.opts.dfc.common.vif.EachApplierVanillaInterface;
@@ -32,6 +33,13 @@ private CompiledDensityFunction(CompiledEntry compiledEntry, Supplier<DensityFun
3233

3334
@Override
3435
public DensityFunction apply(DensityFunctionVisitor visitor) {
36+
if (visitor instanceof IBlendingAwareVisitor blendingAwareVisitor && blendingAwareVisitor.c2me$isBlendingEnabled()) {
37+
DensityFunction fallback1 = this.getFallback();
38+
if (fallback1 == null) {
39+
throw new IllegalStateException("blendingFallback is no more");
40+
}
41+
return fallback1.apply(visitor);
42+
}
3543
boolean modified = false;
3644
List<Object> args = this.compiledEntry.getArgs();
3745
for (ListIterator<Object> iterator = args.listIterator(); iterator.hasNext(); ) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.ishland.c2me.opts.dfc.common.gen;
2+
3+
import com.ishland.c2me.opts.dfc.common.ducks.IBlendingAwareVisitor;
4+
import net.minecraft.world.gen.densityfunction.DensityFunction;
5+
6+
import java.util.Objects;
7+
8+
public class DelegatingBlendingAwareVisitor implements IBlendingAwareVisitor, DensityFunction.DensityFunctionVisitor {
9+
10+
private final DensityFunction.DensityFunctionVisitor delegate;
11+
private final boolean blendingEnabled;
12+
13+
public DelegatingBlendingAwareVisitor(DensityFunction.DensityFunctionVisitor delegate, boolean blendingEnabled) {
14+
this.delegate = Objects.requireNonNull(delegate);
15+
this.blendingEnabled = blendingEnabled;
16+
}
17+
18+
@Override
19+
public DensityFunction apply(DensityFunction densityFunction) {
20+
return this.delegate.apply(densityFunction);
21+
}
22+
23+
@Override
24+
public DensityFunction.Noise apply(DensityFunction.Noise noiseDensityFunction) {
25+
return this.delegate.apply(noiseDensityFunction);
26+
}
27+
28+
@Override
29+
public boolean c2me$isBlendingEnabled() {
30+
return this.blendingEnabled;
31+
}
32+
}

c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/SubCompiledDensityFunction.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
import com.google.common.base.Suppliers;
44
import com.ishland.c2me.opts.dfc.common.ast.EvalType;
55
import com.ishland.c2me.opts.dfc.common.ducks.IArrayCacheCapable;
6+
import com.ishland.c2me.opts.dfc.common.ducks.IBlendingAwareVisitor;
67
import com.ishland.c2me.opts.dfc.common.ducks.ICoordinatesFilling;
78
import com.ishland.c2me.opts.dfc.common.util.ArrayCache;
89
import com.ishland.c2me.opts.dfc.common.vif.EachApplierVanillaInterface;
910
import net.minecraft.util.dynamic.CodecHolder;
1011
import net.minecraft.world.gen.chunk.Blender;
1112
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
1213
import net.minecraft.world.gen.densityfunction.DensityFunction;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1316

1417
import java.util.Objects;
1518
import java.util.function.Supplier;
1619

1720
public class SubCompiledDensityFunction implements DensityFunction {
1821

22+
private static final Logger LOGGER = LoggerFactory.getLogger(SubCompiledDensityFunction.class);
23+
1924
private final ISingleMethod singleMethod;
2025
private final IMultiMethod multiMethod;
2126
protected final Supplier<DensityFunction> blendingFallback;
@@ -35,7 +40,7 @@ private static Supplier<DensityFunction> unwrap(DensityFunction densityFunction)
3540
if (densityFunction instanceof SubCompiledDensityFunction scdf) {
3641
return scdf.blendingFallback;
3742
} else {
38-
return densityFunction != null ? () -> densityFunction : null;
43+
return densityFunction != null ? Suppliers.ofInstance(densityFunction) : null;
3944
}
4045
}
4146

@@ -91,6 +96,13 @@ public DensityFunction apply(DensityFunctionVisitor visitor) {
9196
if (this.getClass() != SubCompiledDensityFunction.class) {
9297
throw new AbstractMethodError();
9398
}
99+
if (visitor instanceof IBlendingAwareVisitor blendingAwareVisitor && blendingAwareVisitor.c2me$isBlendingEnabled()) {
100+
DensityFunction fallback1 = this.getFallback();
101+
if (fallback1 == null) {
102+
throw new IllegalStateException("blendingFallback is no more");
103+
}
104+
return fallback1.apply(visitor);
105+
}
94106
boolean modified = false;
95107
Supplier<DensityFunction> fallback = this.blendingFallback != null ? Suppliers.memoize(() -> {
96108
DensityFunction densityFunction = this.blendingFallback.get();
@@ -125,7 +137,7 @@ public CodecHolder<? extends DensityFunction> getCodecHolder() {
125137
throw new UnsupportedOperationException();
126138
}
127139

128-
private DensityFunction getFallback() {
140+
protected DensityFunction getFallback() {
129141
return this.blendingFallback != null ? this.blendingFallback.get() : null;
130142
}
131143
}

c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/mixin/MixinChunkNoiseSampler.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22

33
import com.ishland.c2me.opts.dfc.common.ducks.IArrayCacheCapable;
44
import com.ishland.c2me.opts.dfc.common.ducks.ICoordinatesFilling;
5+
import com.ishland.c2me.opts.dfc.common.gen.DelegatingBlendingAwareVisitor;
56
import com.ishland.c2me.opts.dfc.common.util.ArrayCache;
7+
import net.minecraft.world.gen.chunk.Blender;
68
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
79
import net.minecraft.world.gen.densityfunction.DensityFunction;
810
import net.minecraft.world.gen.densityfunction.DensityFunctionTypes;
11+
import org.jetbrains.annotations.NotNull;
912
import org.spongepowered.asm.mixin.Final;
1013
import org.spongepowered.asm.mixin.Mixin;
1114
import org.spongepowered.asm.mixin.Shadow;
15+
import org.spongepowered.asm.mixin.Unique;
1216
import org.spongepowered.asm.mixin.injection.At;
1317
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.ModifyArg;
1419
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1520

1621
@Mixin(ChunkNoiseSampler.class)
17-
public class MixinChunkNoiseSampler implements IArrayCacheCapable, ICoordinatesFilling {
22+
public abstract class MixinChunkNoiseSampler implements IArrayCacheCapable, ICoordinatesFilling {
1823

1924
@Shadow @Final private int verticalCellBlockCount;
2025
@Shadow @Final private int horizontalCellBlockCount;
2126
@Shadow private int startBlockY;
2227
@Shadow private int startBlockX;
2328
@Shadow private int startBlockZ;
2429
@Shadow private boolean isInInterpolationLoop;
30+
31+
@Shadow public abstract Blender getBlender();
32+
2533
private final ArrayCache c2me$arrayCache = new ArrayCache();
2634

2735
@Override
@@ -55,4 +63,20 @@ private void protectInterpolationLoop(DensityFunction function, CallbackInfoRetu
5563
throw new IllegalStateException("Cannot create more wrapping during interpolation loop");
5664
}
5765
}
66+
67+
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/noise/NoiseRouter;apply(Lnet/minecraft/world/gen/densityfunction/DensityFunction$DensityFunctionVisitor;)Lnet/minecraft/world/gen/noise/NoiseRouter;"))
68+
private DensityFunction.DensityFunctionVisitor modifyVisitor1(DensityFunction.DensityFunctionVisitor visitor) {
69+
return c2me$getDelegatingBlendingAwareVisitor(visitor);
70+
}
71+
72+
@Unique
73+
private @NotNull DelegatingBlendingAwareVisitor c2me$getDelegatingBlendingAwareVisitor(DensityFunction.DensityFunctionVisitor visitor) {
74+
return new DelegatingBlendingAwareVisitor(visitor, this.getBlender() != Blender.getNoBlending());
75+
}
76+
77+
@ModifyArg(method = {"<init>", "createMultiNoiseSampler"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/densityfunction/DensityFunction;apply(Lnet/minecraft/world/gen/densityfunction/DensityFunction$DensityFunctionVisitor;)Lnet/minecraft/world/gen/densityfunction/DensityFunction;"), require = 7, expect = 7)
78+
private DensityFunction.DensityFunctionVisitor modifyVisitor2(DensityFunction.DensityFunctionVisitor visitor) {
79+
return c2me$getDelegatingBlendingAwareVisitor(visitor);
80+
}
81+
5882
}

0 commit comments

Comments
 (0)