Skip to content

Commit

Permalink
feat: dragon roost worldgen cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX authored and TheBv committed Dec 26, 2023
1 parent af5b1ff commit 2e70e2e
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 569 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -17,56 +16,28 @@

public class BlockReturningState extends Block {
public static final BooleanProperty REVERTS = BooleanProperty.create("revert");
public Item itemBlock;
private final BlockState returnState;

/* public BlockReturningState(float hardness, float resistance, SoundType sound, BlockState returnToState) {
super(
BlockBehaviour.Properties
.of()
.sound(sound)
.strength(hardness, resistance)
.randomTicks()
);
this.returnState = returnToState;
this.registerDefaultState(this.stateDefinition.any().setValue(REVERTS, Boolean.FALSE));
}*/

public static BlockReturningState builder(float hardness, float resistance, SoundType sound, boolean slippery, MapColor color, NoteBlockInstrument instrument, PushReaction reaction, boolean ignited, BlockState returnToState) {
BlockBehaviour.Properties props = BlockBehaviour.Properties.of().mapColor(color).sound(sound).strength(hardness, resistance).friction(0.98F).randomTicks();
if (instrument != null) {
props.instrument(instrument);
}
if (reaction != null) {
props.pushReaction(reaction);
}
if (ignited) {
BlockBehaviour.Properties props = BlockBehaviour.Properties.of().mapColor(color).instrument(instrument).pushReaction(reaction).sound(sound).strength(hardness, resistance).friction(0.98F).randomTicks();
if (ignited)
props.ignitedByLava();
}
return new BlockReturningState(props, returnToState);
}
public static BlockReturningState builder(float hardness, float resistance, SoundType sound, MapColor color, NoteBlockInstrument instrument, PushReaction reaction, boolean ignited, BlockState returnToState) {
BlockBehaviour.Properties props = BlockBehaviour.Properties.of().mapColor(color).sound(sound).strength(hardness, resistance).randomTicks();
if (instrument != null) {
props.instrument(instrument);
}
if (reaction != null) {
props.pushReaction(reaction);
}
if (ignited) {
BlockBehaviour.Properties props = BlockBehaviour.Properties.of().mapColor(color).instrument(instrument).pushReaction(reaction).sound(sound).strength(hardness, resistance).randomTicks();
if (ignited)
props.ignitedByLava();
}
return new BlockReturningState(props, returnToState);
}


public BlockReturningState(BlockBehaviour.Properties props, BlockState returnToState) {
super(props);
this.returnState = returnToState;
this.registerDefaultState(this.stateDefinition.any().setValue(REVERTS, Boolean.FALSE));
}

// FIXME :: Unused because isRandomlyTicking is not used -> The chunk check might be a performance problem anyway (and potentially not needed)
@Override
public void tick(@NotNull BlockState state, ServerLevel worldIn, @NotNull BlockPos pos, @NotNull RandomSource rand) {
if (!worldIn.isClientSide) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.alexthe666.iceandfire.util;

import com.github.alexthe666.iceandfire.world.IafWorldData;
import com.github.alexthe666.iceandfire.world.IafWorldRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
Expand All @@ -9,7 +10,6 @@
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.*;
Expand Down Expand Up @@ -225,7 +225,11 @@ public static boolean isInWorldHeight(final int yBlock, final Level world) {
}

public static boolean canGenerate(int configChance, final WorldGenLevel level, final RandomSource random, final BlockPos origin, final String id, boolean checkFluid) {
boolean canGenerate = random.nextInt(configChance) == 0 && IafWorldRegistry.isFarEnoughFromSpawn(level, origin) && IafWorldRegistry.isFarEnoughFromDangerousGen(level, origin, id);
return canGenerate(configChance, level, random, origin, id, IafWorldData.FeatureType.SURFACE, checkFluid);
}

public static boolean canGenerate(int configChance, final WorldGenLevel level, final RandomSource random, final BlockPos origin, final String id, final IafWorldData.FeatureType type, boolean checkFluid) {
boolean canGenerate = random.nextInt(configChance) == 0 && IafWorldRegistry.isFarEnoughFromSpawn(level, origin) && IafWorldRegistry.isFarEnoughFromDangerousGen(level, origin, id, type);

if (canGenerate && checkFluid) {
if (!level.getFluidState(origin.below()).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

public interface TypedFeature {
IafWorldData.FeatureType getFeatureType();

String getId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public WorldGenCyclopsCave(final Codec<NoneFeatureConfiguration> configuration)

@Override
public boolean place(final FeaturePlaceContext<NoneFeatureConfiguration> context) {
if (!WorldUtil.canGenerate(IafConfig.spawnCyclopsCaveChance, context.level(), context.random(), context.origin(), "cyclopes_cave", true)) {
if (!WorldUtil.canGenerate(IafConfig.spawnCyclopsCaveChance, context.level(), context.random(), context.origin(), getId(), true)) {
return false;
}

Expand Down Expand Up @@ -261,4 +261,9 @@ private BlockState getFenceState(final LevelAccessor level, final BlockPos posit
public IafWorldData.FeatureType getFeatureType() {
return IafWorldData.FeatureType.SURFACE;
}

@Override
public String getId() {
return "cyclops_cave";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel worldIn = context.level();
RandomSource rand = context.random();
BlockPos position = context.origin();
if (rand.nextInt(IafConfig.generateDragonDenChance) != 0 || !IafWorldRegistry.isFarEnoughFromSpawn(worldIn, position) || !IafWorldRegistry.isFarEnoughFromDangerousGen(worldIn, position, "dragon_cave", IafWorldData.FeatureType.UNDERGROUND)) {
if (rand.nextInt(IafConfig.generateDragonDenChance) != 0 || !IafWorldRegistry.isFarEnoughFromSpawn(worldIn, position) || !IafWorldRegistry.isFarEnoughFromDangerousGen(worldIn, position, getId(), getFeatureType())) {
return false;
}
isMale = rand.nextBoolean();
Expand Down Expand Up @@ -220,7 +220,7 @@ public void setGoldPile(LevelAccessor world, BlockPos pos, RandomSource rand) {
}

private EntityDragonBase createDragon(final WorldGenLevel worldGen, final RandomSource random, final BlockPos position, int dragonAge) {
EntityDragonBase dragon = getType().create(worldGen.getLevel());
EntityDragonBase dragon = getDragonType().create(worldGen.getLevel());
dragon.setGender(isMale);
dragon.growDragon(dragonAge);
dragon.setAgingDisabled(true);
Expand All @@ -233,7 +233,7 @@ private EntityDragonBase createDragon(final WorldGenLevel worldGen, final Random
return dragon;
}

public abstract EntityType<? extends EntityDragonBase> getType();
public abstract EntityType<? extends EntityDragonBase> getDragonType();

private static class SphereInfo {
int radius;
Expand All @@ -249,4 +249,9 @@ private SphereInfo(int radius, BlockPos pos) {
public IafWorldData.FeatureType getFeatureType() {
return IafWorldData.FeatureType.UNDERGROUND;
}

@Override
public String getId() {
return "dragon_cave";
}
}

0 comments on commit 2e70e2e

Please sign in to comment.