Skip to content

Commit

Permalink
Added density check to limit how many crystals grow.
Browse files Browse the repository at this point in the history
  • Loading branch information
LtxProgrammer committed Sep 17, 2024
1 parent 1e5bdf7 commit 6ec83bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.ltxprogrammer.changed.init.ChangedBlocks;
import net.ltxprogrammer.changed.init.ChangedGameRules;
import net.ltxprogrammer.changed.init.ChangedItems;
import net.ltxprogrammer.changed.init.ChangedTags;
import net.ltxprogrammer.changed.item.AbstractLatexItem;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -51,7 +53,11 @@ public void latexTick(@NotNull BlockState state, @NotNull ServerLevel level, @No
boolean isAboveAir = level.getBlockState(above).is(Blocks.AIR);
boolean isAbove2Air = level.getBlockState(above2).is(Blocks.AIR);
if (isAboveAir && canSupportRigidBlock(level, position)) { // Do growth event
if (random.nextFloat() < 0.5f) return;
long crystalCount = level.getBlockStates(new AABB(position).inflate(3.0))
.filter(neighbor -> neighbor.is(ChangedTags.Blocks.LATEX_CRYSTAL))
.count();

if (crystalCount > 6) return;

if (random.nextFloat() < 0.75f || !isAbove2Air) {
level.setBlockAndUpdate(above, Util.getRandom(SMALL_CRYSTALS, random).get().defaultBlockState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static class Blocks {
public static final TagKey<Block> DUCT_EXIT = create("duct_exit");
public static final TagKey<Block> GAS = create("gas");
public static final TagKey<Block> AIR_CONDITIONER = create("air_conditioner");
public static final TagKey<Block> LATEX_CRYSTAL = create("latex_crystal");

private static TagKey<Block> create(String name) {
return TagKey.create(Registry.BLOCK_REGISTRY, Changed.modResource(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public Biome build() {

ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_MALE, 100, 1, 4, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_FEMALE, 100, 1, 4, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_PARTIAL, 1, 1, 4, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_PUP, 30, 1, 1, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_PARTIAL, 1, 1, 1, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_WOLF_PUP, 30, 1, 4, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.DARK_LATEX_YUFENG, 40, 1, 3, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.PHAGE_LATEX_WOLF_MALE, 20, 1, 2, 0.7, 0.15);
ChangedBiomeInterface.addSpawn(spawnBuilder, ChangedMobCategories.CHANGED, ChangedEntities.PHAGE_LATEX_WOLF_FEMALE, 20, 1, 2, 0.7, 0.15);
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/data/changed/tags/blocks/latex_crystal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"replace": false,
"values": [
"changed:beifeng_crystal",
"changed:beifeng_crystal_small",
"changed:dark_dragon_crystal",
"changed:dark_latex_crystal_large",
"changed:latex_crystal",
"changed:latex_pup_crystal",
"changed:wolf_crystal",
"changed:wolf_crystal_small"
]
}

0 comments on commit 6ec83bc

Please sign in to comment.