From 09ee0eccbada4691aa0423ef735d3f4cf7dee7c6 Mon Sep 17 00:00:00 2001 From: Astrashh Date: Fri, 24 Nov 2023 11:48:17 +1100 Subject: [PATCH] Invert exposed ore logic (#433) * Invert exposed ore logic * Bump ore addon version --- common/addons/config-ore/build.gradle.kts | 2 +- .../addons/ore/utils/VanillaOreUtils.java | 39 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/common/addons/config-ore/build.gradle.kts b/common/addons/config-ore/build.gradle.kts index 469635ee6..06718492e 100644 --- a/common/addons/config-ore/build.gradle.kts +++ b/common/addons/config-ore/build.gradle.kts @@ -1,4 +1,4 @@ -version = version("1.1.0") +version = version("1.1.1") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) diff --git a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/utils/VanillaOreUtils.java b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/utils/VanillaOreUtils.java index cfef65b57..f8ede8680 100644 --- a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/utils/VanillaOreUtils.java +++ b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/utils/VanillaOreUtils.java @@ -8,31 +8,24 @@ import com.dfsek.terra.api.world.WritableWorld; public class VanillaOreUtils { - protected static boolean shouldNotDiscard(Random random, double chance) { - if(chance <= 0.0F) { - return true; - } else if(chance >= 1.0F) { - return false; - } else { - return random.nextFloat() >= chance; - } + private static boolean shouldExpose(Random random, double exposedChance) { + if(exposedChance >= 1.0F) return true; + if(exposedChance <= 0.0F) return false; + return random.nextFloat() < exposedChance; } - public static boolean shouldPlace(MaterialSet replaceable, BlockType type, Double exposed, Random random, WritableWorld world, int x, + public static boolean shouldPlace(MaterialSet replaceable, BlockType type, Double exposedChance, Random random, WritableWorld world, + int x, int y, int z) { - if(!replaceable.contains(type)) { - return false; - } else if(shouldNotDiscard(random, exposed)) { - return true; - } else { - return !(world.getBlockState(x, y, z - 1).isAir() || - world.getBlockState(x, y, z + 1).isAir() || - world.getBlockState(x, y - 1, z).isAir() || - world.getBlockState(x, y + 1, z).isAir() || - world.getBlockState(x - 1, y, z).isAir() || - world.getBlockState(x + 1, y, z).isAir()); - } + if(!replaceable.contains(type)) return false; + if(shouldExpose(random, exposedChance)) return true; // Exposed blocks can be placed regardless of adjacency to air + // Adjacency is checked after determining not exposed rather than vice-versa, assuming block checks are more expensive + boolean adjacentAir = world.getBlockState(x, y, z - 1).isAir() || + world.getBlockState(x, y, z + 1).isAir() || + world.getBlockState(x, y - 1, z).isAir() || + world.getBlockState(x, y + 1, z).isAir() || + world.getBlockState(x - 1, y, z).isAir() || + world.getBlockState(x + 1, y, z).isAir(); + return !adjacentAir; // Exposed check did not pass earlier so only blocks not adjacent air should place } - } -