Skip to content

Commit

Permalink
Use different anomaly states in feature generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Forstride committed Jan 14, 2024
1 parent ee37884 commit 0fe33bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
23 changes: 1 addition & 22 deletions common/src/main/java/biomesoplenty/block/AnomalyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@
import biomesoplenty.block.entity.AnomalyBlockEntity;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.ComparatorMode;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand All @@ -47,17 +37,6 @@ protected MapCodec<? extends BaseEntityBlock> codec()
return CODEC;
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand $$4, BlockHitResult $$5) {
if (!player.getAbilities().mayBuild) {
return InteractionResult.PASS;
} else {
state = state.cycle(ANOMALY_TYPE);
level.setBlock(pos, state, 2);
return InteractionResult.sidedSuccess(level.isClientSide);
}
}

@Override
public RenderShape getRenderShape(BlockState state)
{
Expand Down Expand Up @@ -85,7 +64,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state)

public enum AnomalyType implements StringRepresentable
{
VOLATILE("volatile"), QURIRKY("quirky"), UNSTABLE("unstable"), STABLE("stable");
VOLATILE("volatile"), QUIRKY("quirky"), UNSTABLE("unstable"), STABLE("stable");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private BlockState getRenderState(RandomSource random, AnomalyBlockEntity blockE
switch (state.getValue(AnomalyBlock.ANOMALY_TYPE))
{
case VOLATILE -> index *= level.getGameTime() / 2L;
case QURIRKY -> index += level.getGameTime() / 10L;
case QUIRKY -> index += level.getGameTime() / 10L;
case UNSTABLE -> {
// Changes slowly most of the time, but has sudden bursts of rapid changes
final float slowWeight = 0.98F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
package biomesoplenty.worldgen.feature.misc;

import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.block.AnomalyBlock;
import biomesoplenty.util.SimpleBlockPredicate;
import com.mojang.serialization.Codec;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.Feature;
Expand All @@ -20,7 +23,7 @@
public class AnomalyFeature extends Feature<NoneFeatureConfiguration>
{
protected SimpleBlockPredicate placeOn = (world, pos) -> world.getBlockState(pos).getBlock() == Blocks.END_STONE;
protected SimpleBlockPredicate replace = (world, pos) -> world.getBlockState(pos).getBlock() == Blocks.END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.ALGAL_END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.NULL_END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.NULL_BLOCK;
protected SimpleBlockPredicate replace = (world, pos) -> world.getBlockState(pos).is(BlockTags.REPLACEABLE_BY_TREES) || world.getBlockState(pos).getBlock() instanceof BushBlock || world.getBlockState(pos).getBlock() == Blocks.END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.ALGAL_END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.NULL_END_STONE || world.getBlockState(pos).getBlock() == BOPBlocks.NULL_BLOCK;

public AnomalyFeature(Codec<NoneFeatureConfiguration> deserializer)
{
Expand All @@ -44,7 +47,7 @@ public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceC
}

int radius = rand.nextInt(3);
int anomalyHeight = (radius*2)+3;
int anomalyHeight = (radius*2)+4;

if (!this.checkSpace(world, startPos, radius, anomalyHeight))
{
Expand Down Expand Up @@ -92,14 +95,27 @@ else if (x == -(radius+1) || x == (radius+1) || z == -(radius+1) || z == (radius
{
for (int z = -radius; z <= radius; z++)
{
AnomalyBlock.AnomalyType type = AnomalyBlock.AnomalyType.STABLE;
if (y == -radius || y == radius || x == -radius || x == radius || z == -radius || z == radius)
{
world.setBlock(pos.offset(x,anomalyHeight+radius+y,z), BOPBlocks.ANOMALY.defaultBlockState(), 2);
}
else
{
world.setBlock(pos.offset(x,anomalyHeight+radius+y,z), Blocks.BEDROCK.defaultBlockState(), 2);
switch (rand.nextInt(6))
{
default:
case 0:
type = AnomalyBlock.AnomalyType.VOLATILE;
break;

case 1:
type = AnomalyBlock.AnomalyType.QUIRKY;
break;

case 2:
type = AnomalyBlock.AnomalyType.UNSTABLE;
break;
}
}

world.setBlock(pos.offset(x,anomalyHeight+radius+y,z), BOPBlocks.ANOMALY.defaultBlockState().setValue(AnomalyBlock.ANOMALY_TYPE, type), 2);
}
}
}
Expand Down

0 comments on commit 0fe33bd

Please sign in to comment.