Skip to content

Commit

Permalink
OldNoCubes improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiboo committed Sep 17, 2023
1 parent b148a3c commit dc44b00
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public static class Server {
public static boolean forceVisuals;
public static int extendFluidsRange;
public static boolean oldNoCubesSlopes;
public static float oldNoCubesInFluids;
public static float oldNoCubesRoughness;

static {
Expand All @@ -339,6 +340,7 @@ public static void bake(ModConfig config) {
Client.render = true;
extendFluidsRange = validateRange(0, 2, INSTANCE.extendFluidsRange.get(), "extendFluidsRange");
oldNoCubesSlopes = INSTANCE.oldNoCubesSlopes.get();
oldNoCubesInFluids = INSTANCE.oldNoCubesInFluids.get();
oldNoCubesRoughness = validateRange(0d, 1d, INSTANCE.oldNoCubesRoughness.get(), "oldNoCubesRoughness").floatValue();

if (Client.render && oldChunkRenderSettingsHash != hashChunkRenderSettings())
Expand Down Expand Up @@ -407,6 +409,7 @@ static class Impl {
final BooleanValue forceVisuals;
final IntValue extendFluidsRange;
final BooleanValue oldNoCubesSlopes;
final BooleanValue oldNoCubesInFluids;
final DoubleValue oldNoCubesRoughness;

private Impl(ForgeConfigSpec.Builder builder) {
Expand Down Expand Up @@ -461,6 +464,11 @@ private Impl(ForgeConfigSpec.Builder builder) {
)
.define("oldNoCubesSlopes", true);

oldNoCubesInFluids = builder
.translation(NoCubes.MOD_ID + ".config.oldNoCubesInFluids")
.comment("If slopes be generated inside fluids by OldNoCubes")
.define("oldNoCubesInFluids", true);

oldNoCubesRoughness = builder
.translation(NoCubes.MOD_ID + ".config.oldNoCubesRoughness")
.comment("How much pseudo-random roughness should be applied to mesh generated by OldNoCubes")
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/io/github/cadiboo/nocubes/mesh/OldNoCubes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.cadiboo.nocubes.util.ModUtil;
import io.github.cadiboo.nocubes.util.Vec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;

import java.util.function.Predicate;
Expand Down Expand Up @@ -129,11 +130,11 @@ private void generateInternal(Area area, Predicate<BlockState> isSmoothable, Ful
point.y += y;
point.z += z;

if (!doesPointIntersectWithManufactured(area, point, isSmoothable, pos)) {
if (!doesPointIntersectWithSolid(area, point, isSmoothable, pos)) {
if (NoCubesConfig.Server.oldNoCubesSlopes) {
if (pointIndex < 4 && doesPointBottomIntersectWithAir(area, point, pos))
if (pointIndex < 4 && doesPointBottomIntersectWithNonSolid(area, point, pos))
point.y = y + 1.0F - 0.0001F; // - 0.0001F to prevent z-fighting
else if (pointIndex >= 4 && doesPointTopIntersectWithAir(area, point, pos))
else if (pointIndex >= 4 && doesPointTopIntersectWithNonSolid(area, point, pos))
point.y = y + 0.0F + 0.0001F; // + 0.0001F to prevent z-fighting
}
givePointRoughness(roughness, area, point);
Expand Down Expand Up @@ -235,51 +236,55 @@ public static void givePointRoughness(float roughness, Area area, Vec point) {
point.z += ((float) (i >> 24 & 0xF) / 15.0F - 0.5F) * roughness;
}

public static boolean isBlockAirPlantOrSnowLayer(BlockState state) {
return state.isAir() || ModUtil.isPlant(state) || ModUtil.isSnowLayer(state);
/**
* Checks if the state should be connected to with a slope (rather than a full side) when it is next to a smooth block.
* Also used to decide if parts of a neighbouring smoothable block can extend into it if {@link NoCubesConfig.Server.oldNoCubesRoughness} is enabled.
*/
public static boolean isNonSolid(BlockState state) {
return state.isAir() || (NoCubesConfig.Server.oldNoCubesInFluids && state.getBlock() instanceof LiquidBlock && state.getFluidState().isSource()) || ModUtil.isPlant(state) || ModUtil.isSnowLayer(state);
}

public static boolean doesPointTopIntersectWithAir(Area area, Vec point, MutableBlockPos pos) {
public static boolean doesPointTopIntersectWithNonSolid(Area area, Vec point, MutableBlockPos pos) {
boolean intersects = false;
for (int i = 0; i < 4; i++) {
int x = (int) (point.x - (i & 0x1));
int y = (int) point.y;
int z = (int) (point.z - (i >> 1 & 0x1));
if (!isBlockAirPlantOrSnowLayer(area.getBlockState(pos.set(x, y, z))))
if (!isNonSolid(area.getBlockState(pos.set(x, y, z))))
return false;
if (isBlockAirPlantOrSnowLayer(area.getBlockState(pos.set(x, y - 1, z))))
if (isNonSolid(area.getBlockState(pos.set(x, y - 1, z))))
intersects = true;
}
return intersects;
}

public static boolean doesPointBottomIntersectWithAir(Area area, Vec point, MutableBlockPos pos) {
public static boolean doesPointBottomIntersectWithNonSolid(Area area, Vec point, MutableBlockPos pos) {
boolean intersects = false;
boolean notOnly = false;
for (int i = 0; i < 4; i++) {
int x = (int) (point.x - (i & 0x1));
int y = (int) point.y;
int z = (int) (point.z - (i >> 1 & 0x1));
if (!isBlockAirPlantOrSnowLayer(area.getBlockState(pos.set(x, y - 1, z))))
if (!isNonSolid(area.getBlockState(pos.set(x, y - 1, z))))
return false;
if (!isBlockAirPlantOrSnowLayer(area.getBlockState(pos.set(x, y + 1, z))))
if (!isNonSolid(area.getBlockState(pos.set(x, y + 1, z))))
notOnly = true;
if (isBlockAirPlantOrSnowLayer(area.getBlockState(pos.set(x, y, z))))
if (isNonSolid(area.getBlockState(pos.set(x, y, z))))
intersects = true;
}
return intersects && notOnly;
}

public static boolean doesPointIntersectWithManufactured(Area area, Vec point, Predicate<BlockState> isSmoothable, MutableBlockPos pos) {
public static boolean doesPointIntersectWithSolid(Area area, Vec point, Predicate<BlockState> isSmoothable, MutableBlockPos pos) {
for (int i = 0; i < 4; i++) {
int x = (int) (point.x - (i & 0x1));
int y = (int) point.y;
int z = (int) (point.z - (i >> 1 & 0x1));
BlockState state0 = area.getBlockState(pos.set(x, y, z));
if (!isBlockAirPlantOrSnowLayer(state0) && !isSmoothable.test(state0))
if (!isNonSolid(state0) && !isSmoothable.test(state0))
return true;
BlockState state1 = area.getBlockState(pos.set(x, y - 1, z));
if (!isBlockAirPlantOrSnowLayer(state1) && !isSmoothable.test(state1))
if (!isNonSolid(state1) && !isSmoothable.test(state1))
return true;
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/nocubes/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"nocubes.config.collisionsEnabled": "Custom collisions",
"nocubes.config.forceVisuals": "Force custom rendering for players",
"nocubes.config.extendFluidsRange": "Extended fluids range",
"nocubes.config.oldNoCubesSlopes": "OldNoCubes slopes",
"nocubes.config.oldNoCubesInFluids": "OldNoCubes in fluids",
"nocubes.config.oldNoCubesRoughness": "OldNoCubes roughness",

"nocubes.command.changeSmoothableNoPermission": "Unable to change block smoothness; no permission",
Expand Down

0 comments on commit dc44b00

Please sign in to comment.