Removal of inner classes on mixins, factor them out
This commit is contained in:
parent
52f06e8567
commit
4c312026ef
|
|
@ -2,13 +2,12 @@ package org.embeddedt.modernfix.common.mixin.perf.worldgen_allocation;
|
|||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.PositionalRandomFactory;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
import net.minecraft.world.level.levelgen.placement.CaveSurface;
|
||||
import org.embeddedt.modernfix.world.gen.SurfaceConditionRecords;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
|
@ -16,7 +15,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Mixin(SurfaceRules.class)
|
||||
|
||||
public class SurfaceRulesMixin {
|
||||
@Mixin(value = SurfaceRules.BiomeConditionSource.class, priority = 100)
|
||||
public static final class BiomeConditionSource {
|
||||
|
|
@ -28,14 +27,8 @@ public class SurfaceRulesMixin {
|
|||
*/
|
||||
@Overwrite
|
||||
public SurfaceRules.Condition apply(final SurfaceRules.Context pContext) {
|
||||
class BiomeCondition implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.biome.get().is(biomeNameTest);
|
||||
}
|
||||
}
|
||||
|
||||
return new BiomeCondition();
|
||||
// Return the condition; this record is kept outside the class at embeddedt's wishes due to mixin compat concerns
|
||||
return new SurfaceConditionRecords.PerformantBiomeCondition(pContext, biomeNameTest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,20 +48,8 @@ public class SurfaceRulesMixin {
|
|||
public SurfaceRules.Condition apply(final SurfaceRules.Context pContext) {
|
||||
// Copied Vanilla variables
|
||||
final boolean flag = this.surfaceType == CaveSurface.CEILING;
|
||||
|
||||
class StoneDepthCondition implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
int i = flag ? pContext.stoneDepthBelow : pContext.stoneDepthAbove;
|
||||
int j = addSurfaceDepth ? pContext.surfaceDepth : 0;
|
||||
int k = secondaryDepthRange == 0
|
||||
? 0
|
||||
: (int) Mth.map(pContext.getSurfaceSecondary(), -1.0, 1.0, 0.0, secondaryDepthRange);
|
||||
return i <= 1 + offset + j + k;
|
||||
}
|
||||
}
|
||||
|
||||
return new StoneDepthCondition();
|
||||
// Return the condition; this record is kept outside the class at embeddedt's wishes due to mixin compat concerns
|
||||
return new SurfaceConditionRecords.PerformantStoneDepthCondition(pContext, offset, addSurfaceDepth, secondaryDepthRange, flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,25 +69,9 @@ public class SurfaceRulesMixin {
|
|||
// Copied Vanilla variables
|
||||
final int i = trueAtAndBelow.resolveY(pContext.context);
|
||||
final int j = falseAtAndAbove.resolveY(pContext.context);
|
||||
final PositionalRandomFactory positionalrandomfactory = pContext.randomState.getOrCreateRandomFactory(randomName);
|
||||
|
||||
class VerticalGradientCondition implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
int k = pContext.blockY;
|
||||
if (k <= i) {
|
||||
return true;
|
||||
} else if (k >= j) {
|
||||
return false;
|
||||
} else {
|
||||
double d0 = Mth.map(k, i, j, 1.0, 0.0);
|
||||
RandomSource randomsource = positionalrandomfactory.at(pContext.blockX, k, pContext.blockZ);
|
||||
return (double)randomsource.nextFloat() < d0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new VerticalGradientCondition();
|
||||
final PositionalRandomFactory positionalRandomFactory = pContext.randomState.getOrCreateRandomFactory(randomName);
|
||||
// Return the condition; this record is kept outside the class at embeddedt's wishes due to mixin compat concerns
|
||||
return new SurfaceConditionRecords.PerformantVerticalGradientCondition(pContext, i, j, positionalRandomFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,18 +88,8 @@ public class SurfaceRulesMixin {
|
|||
*/
|
||||
@Overwrite
|
||||
public SurfaceRules.Condition apply(final SurfaceRules.Context pContext) {
|
||||
class WaterCondition implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.waterHeight == Integer.MIN_VALUE
|
||||
|| pContext.blockY + (addStoneDepth ? pContext.stoneDepthAbove : 0)
|
||||
>= pContext.waterHeight
|
||||
+ offset
|
||||
+ pContext.surfaceDepth * surfaceDepthMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
return new WaterCondition();
|
||||
// Return the condition; this record is kept outside the class at embeddedt's wishes due to mixin compat concerns
|
||||
return new SurfaceConditionRecords.PerformantWaterCondition(pContext, offset, surfaceDepthMultiplier, addStoneDepth);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -151,16 +106,8 @@ public class SurfaceRulesMixin {
|
|||
*/
|
||||
@Overwrite
|
||||
public SurfaceRules.Condition apply(final SurfaceRules.Context pContext) {
|
||||
class YCondition implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.blockY + (addStoneDepth ? pContext.stoneDepthAbove : 0)
|
||||
>= anchor.resolveY(pContext.context)
|
||||
+ pContext.surfaceDepth * surfaceDepthMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
return new YCondition();
|
||||
// Return the condition; this record is kept outside the class at embeddedt's wishes due to mixin compat concerns
|
||||
return new SurfaceConditionRecords.PerformantYCondition(pContext, anchor, surfaceDepthMultiplier, addStoneDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package org.embeddedt.modernfix.world.gen;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.PositionalRandomFactory;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SurfaceConditionRecords {
|
||||
public record PerformantBiomeCondition(SurfaceRules.Context pContext, Predicate<ResourceKey<Biome>> biomeNameTest) implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.biome.get().is(biomeNameTest);
|
||||
}
|
||||
}
|
||||
|
||||
public record PerformantStoneDepthCondition(SurfaceRules.Context pContext, int offset, boolean addSurfaceDepth, int secondaryDepthRange, boolean flag) implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
int i = flag ? pContext.stoneDepthBelow : pContext.stoneDepthAbove;
|
||||
int j = addSurfaceDepth ? pContext.surfaceDepth : 0;
|
||||
int k = secondaryDepthRange == 0
|
||||
? 0
|
||||
: (int) Mth.map(pContext.getSurfaceSecondary(), -1.0, 1.0, 0.0, secondaryDepthRange);
|
||||
return i <= 1 + offset + j + k;
|
||||
}
|
||||
}
|
||||
|
||||
public record PerformantVerticalGradientCondition(SurfaceRules.Context pContext, int i, int j, PositionalRandomFactory positionalRandomFactory) implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
int k = pContext.blockY;
|
||||
if (k <= i) {
|
||||
return true;
|
||||
} else if (k >= j) {
|
||||
return false;
|
||||
} else {
|
||||
double d0 = Mth.map(k, i, j, 1.0, 0.0);
|
||||
RandomSource randomsource = positionalRandomFactory.at(pContext.blockX, k, pContext.blockZ);
|
||||
return (double)randomsource.nextFloat() < d0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public record PerformantWaterCondition(SurfaceRules.Context pContext, int offset, int surfaceDepthMultiplier, boolean addStoneDepth) implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.waterHeight == Integer.MIN_VALUE
|
||||
|| pContext.blockY + (addStoneDepth ? pContext.stoneDepthAbove : 0)
|
||||
>= pContext.waterHeight
|
||||
+ offset
|
||||
+ pContext.surfaceDepth * surfaceDepthMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
public record PerformantYCondition(SurfaceRules.Context pContext, VerticalAnchor anchor, int surfaceDepthMultiplier, boolean addStoneDepth) implements SurfaceRules.Condition {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return pContext.blockY + (addStoneDepth ? pContext.stoneDepthAbove : 0)
|
||||
>= anchor.resolveY(pContext.context)
|
||||
+ pContext.surfaceDepth * surfaceDepthMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user