From f7e91937d8857e8872e6f4885d0492e81b2af90d Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 24 May 2019 14:51:58 +1000 Subject: [PATCH] Setup for climate-based ocean biomes --- .../common/world/BOPLayerUtil.java | 4 +- .../world/layer/GenLayerMixOceansBOP.java | 84 +++++++++++++++++++ .../common/world/layer/GenLayerShoreBOP.java | 5 +- .../world/layer/traits/IAreaTransformer3.java | 35 ++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/world/layer/GenLayerMixOceansBOP.java create mode 100644 src/main/java/biomesoplenty/common/world/layer/traits/IAreaTransformer3.java diff --git a/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java b/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java index ac98f794d..19cab0bb2 100644 --- a/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java +++ b/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java @@ -159,7 +159,9 @@ public class BOPLayerUtil // Mix rivers into the biomes branch biomesFactory = GenLayerRiverMix.INSTANCE.apply(contextFactory.apply(100L), biomesFactory, riversInitFactory); - biomesFactory = GenLayerMixOceans.INSTANCE.apply(contextFactory.apply(100L), biomesFactory, oceanBiomeFactory); + + climateFactory = LayerUtil.repeat(2001L, GenLayerZoom.NORMAL, oceanBiomeFactory, 6, contextFactory); + biomesFactory = GenLayerMixOceansBOP.INSTANCE.apply(contextFactory.apply(100L), biomesFactory, oceanBiomeFactory, climateFactory); // Finish biomes with Voroni zoom IAreaFactory voroniZoomBiomesFactory = GenLayerVoronoiZoom.INSTANCE.apply(contextFactory.apply(10L), biomesFactory); diff --git a/src/main/java/biomesoplenty/common/world/layer/GenLayerMixOceansBOP.java b/src/main/java/biomesoplenty/common/world/layer/GenLayerMixOceansBOP.java new file mode 100644 index 000000000..a94fed826 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/layer/GenLayerMixOceansBOP.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright 2014-2019, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.common.world.layer; + +import biomesoplenty.api.enums.BOPClimates; +import biomesoplenty.common.world.BOPLayerUtil; +import biomesoplenty.common.world.layer.traits.IAreaTransformer3; +import net.minecraft.world.gen.IContext; +import net.minecraft.world.gen.area.AreaDimension; +import net.minecraft.world.gen.area.IArea; +import net.minecraft.world.gen.layer.traits.IDimOffset0Transformer; + +public enum GenLayerMixOceansBOP implements IAreaTransformer3, IDimOffset0Transformer +{ + INSTANCE; + + @Override + public int apply(IContext context, AreaDimension dimension, IArea biomeArea, IArea oceanArea, IArea climateArea, int x, int z) + { + int biomeId = biomeArea.getValue(x, z); + int oceanId = oceanArea.getValue(x, z); + int climateVal = climateArea.getValue(x, z); + BOPClimates climate = BOPClimates.lookup(climateVal); + + if (!BOPLayerUtil.isOcean(biomeId)) + { + return biomeId; + } + else + { + // When far from land, warm oceans should become lukewarm and frozen oceans should become cold + for (int xOff = -8; xOff <= 8; xOff += 4) + { + for (int zOff = -8; zOff <= 8; zOff += 4) + { + int offsetBiomeId = biomeArea.getValue(x + xOff, z + zOff); + + if (!BOPLayerUtil.isOcean(offsetBiomeId)) + { + if (oceanId == BOPLayerUtil.WARM_OCEAN) + { + return BOPLayerUtil.LUKEWARM_OCEAN; + } + + if (oceanId == BOPLayerUtil.FROZEN_OCEAN) + { + return BOPLayerUtil.COLD_OCEAN; + } + } + } + } + + if (biomeId == BOPLayerUtil.DEEP_OCEAN) + { + if (oceanId == BOPLayerUtil.LUKEWARM_OCEAN) + { + return BOPLayerUtil.DEEP_LUKEWARM_OCEAN; + } + + if (oceanId == BOPLayerUtil.OCEAN) + { + return BOPLayerUtil.DEEP_OCEAN; + } + + if (oceanId == BOPLayerUtil.COLD_OCEAN) + { + return BOPLayerUtil.DEEP_COLD_OCEAN; + } + + if (oceanId == BOPLayerUtil.FROZEN_OCEAN) + { + return BOPLayerUtil.DEEP_FROZEN_OCEAN; + } + } + + return oceanId; + } + } +} diff --git a/src/main/java/biomesoplenty/common/world/layer/GenLayerShoreBOP.java b/src/main/java/biomesoplenty/common/world/layer/GenLayerShoreBOP.java index e2c6fe3f6..0b9a00b95 100644 --- a/src/main/java/biomesoplenty/common/world/layer/GenLayerShoreBOP.java +++ b/src/main/java/biomesoplenty/common/world/layer/GenLayerShoreBOP.java @@ -43,6 +43,7 @@ public enum GenLayerShoreBOP implements ICastleTransformer private static final int SWAMP = IRegistry.BIOME.getId(Biomes.SWAMP); private static final int TAIGA = IRegistry.BIOME.getId(Biomes.TAIGA); + @Override public int apply(IContext context, int northBiomeId, int eastBiomeId, int southBiomeId, int westBiomeId, int biomeId) { Biome biome = IRegistry.BIOME.get(biomeId); @@ -92,7 +93,7 @@ public enum GenLayerShoreBOP implements ICastleTransformer return BEACH; } } - else if (!BOPLayerUtil.isOcean(northBiomeId) && !BOPLayerUtil.isOcean(eastBiomeId) && !BOPLayerUtil.isOcean(southBiomeId) && !BOPLayerUtil.isOcean(westBiomeId) && (!this.isMesa(northBiomeId) || !this.isMesa(eastBiomeId) || !this.isMesa(southBiomeId) || !this.isMesa(westBiomeId))) + else if (!BOPLayerUtil.isOcean(northBiomeId) && !BOPLayerUtil.isOcean(eastBiomeId) && !BOPLayerUtil.isOcean(southBiomeId) && !BOPLayerUtil.isOcean(westBiomeId) && (!isMesa(northBiomeId) || !isMesa(eastBiomeId) || !isMesa(southBiomeId) || !isMesa(westBiomeId))) { return DESERT; } @@ -117,7 +118,7 @@ public enum GenLayerShoreBOP implements ICastleTransformer } } - private boolean isMesa(int biomeId) + private static boolean isMesa(int biomeId) { return biomeId == BADLANDS || biomeId == WOODED_BADLANDS_PLATEAU || biomeId == BADLANDS_PLATEAU || biomeId == ERODED_BADLANDS || biomeId == MODIFIED_WOODED_BADLANDS_PLATEAU || biomeId == MODIFIED_BADLANDS_PLATEAU; } diff --git a/src/main/java/biomesoplenty/common/world/layer/traits/IAreaTransformer3.java b/src/main/java/biomesoplenty/common/world/layer/traits/IAreaTransformer3.java new file mode 100644 index 000000000..d9ab35213 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/layer/traits/IAreaTransformer3.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2014-2019, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.common.world.layer.traits; + +import net.minecraft.world.gen.IContext; +import net.minecraft.world.gen.IContextExtended; +import net.minecraft.world.gen.area.AreaDimension; +import net.minecraft.world.gen.area.IArea; +import net.minecraft.world.gen.area.IAreaFactory; +import net.minecraft.world.gen.layer.traits.IDimTransformer; + +public interface IAreaTransformer3 extends IDimTransformer +{ + default IAreaFactory apply(IContextExtended context, IAreaFactory areaFactory1, IAreaFactory areaFactory2, IAreaFactory areaFactory3) + { + return (areaDimension) -> + { + R area1 = areaFactory1.make(this.apply(areaDimension)); + R area2 = areaFactory2.make(this.apply(areaDimension)); + R area3 = areaFactory3.make(this.apply(areaDimension)); + return context.makeArea(areaDimension, (x, z) -> + { + context.setPosition((long)(x + areaDimension.getStartX()), (long)(z + areaDimension.getStartZ())); + return this.apply(context, areaDimension, area1, area2, area3, x, z); + }); + }; + } + + int apply(IContext context, AreaDimension dimension, IArea area1, IArea area2, IArea area3, int x, int z); +}