Skip to content

Commit

Permalink
big mushrooms #818
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Nov 3, 2024
1 parent 5dbc62e commit 6204a3a
Show file tree
Hide file tree
Showing 49 changed files with 875 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import net.id.paradiselost.blocks.natural.plant.*;
import net.id.paradiselost.blocks.natural.tree.*;
import net.id.paradiselost.tag.ParadiseLostBlockTags;
import net.id.paradiselost.world.feature.configured_features.ParadiseLostConfiguredFeatures;
import net.id.paradiselost.world.feature.configured_features.ParadiseLostTreeConfiguredFeatures;
import net.id.paradiselost.world.feature.tree.ParadiseLostSaplingGenerators;
import net.minecraft.block.*;
import net.minecraft.block.AbstractBlock.Settings;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.registry.tag.BlockTags;
Expand Down Expand Up @@ -209,9 +212,13 @@ private static Settings crop() {
public static final TallWaterPlantBlock HONEY_NETTLE = add("honey_nettle", new TallWaterPlantBlock(shrub().sounds(BlockSoundGroup.SMALL_DRIPLEAF)), cutoutRenderLayer);

public static final WallClingingPlantBlock ROOTCAP = add("rootcap", new WallClingingPlantBlock(ParadiseLostBlockTags.FUNGI_CLINGABLES, copy(BROWN_MUSHROOM)), cutoutRenderLayer);
public static final ParadiseLostMushroomPlantBlock BROWN_SPORECAP = add("brown_sporecap", new ParadiseLostMushroomPlantBlock(BlockTags.MUSHROOM_GROW_BLOCK, copy(BROWN_MUSHROOM)), cutoutRenderLayer);
public static final ParadiseLostMushroomPlantBlock BROWN_SPORECAP = add("brown_sporecap", new ParadiseLostMushroomPlantBlock(BlockTags.MUSHROOM_GROW_BLOCK, ParadiseLostTreeConfiguredFeatures.HUGE_BROWN_SPORECAP, copy(BROWN_MUSHROOM)), cutoutRenderLayer);
public static final ParadiseLostHangingMushroomPlantBlock PINK_SPORECAP = add("pink_sporecap", new ParadiseLostHangingMushroomPlantBlock(BlockTags.MUSHROOM_GROW_BLOCK, copy(BROWN_MUSHROOM)), cutoutRenderLayer);

public static final Block ROOTCAP_BLOCK = add("rootcap_block", new MushroomBlock(copy(BROWN_MUSHROOM_BLOCK).mapColor(MapColor.TERRACOTTA_BROWN)));
public static final Block BROWN_SPORECAP_BLOCK = add("brown_sporecap_block", new MushroomBlock(copy(BROWN_MUSHROOM_BLOCK).mapColor(MapColor.BROWN)));
public static final Block PINK_SPORECAP_BLOCK = add("pink_sporecap_block", new MushroomBlock(copy(BROWN_MUSHROOM_BLOCK).mapColor(MapColor.TERRACOTTA_PINK)));

public static final AmadrysCropBlock AMADRYS = add("amadrys", new AmadrysCropBlock(crop().mapColor(MapColor.PINK)), flammablePlant, cutoutMippedRenderLayer);
public static final FlaxCropBlock FLAX = add("flax", new FlaxCropBlock(crop().mapColor(MapColor.OAK_TAN)), flammablePlant, cutoutRenderLayer);
public static final SwedrootCropBlock SWEDROOT = add("swedroot", new SwedrootCropBlock(shrub().offset(AbstractBlock.OffsetType.NONE).mapColor(MapColor.BLUE)), flammablePlant, cutoutRenderLayer);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package net.id.paradiselost.blocks.natural.plant;

import net.id.paradiselost.blocks.ParadiseLostBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.MushroomBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
import net.minecraft.world.gen.feature.ConfiguredFeature;

import java.util.Arrays;
import java.util.Optional;

public class ParadiseLostHangingMushroomPlantBlock extends ParadiseLostMushroomPlantBlock {
public ParadiseLostHangingMushroomPlantBlock(TagKey<Block> plantableOn, Settings settings) {
super(plantableOn, settings);
super(plantableOn, null, settings);
}

@Override
Expand All @@ -34,4 +47,58 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBaseLightLevel(pos, 0) < 11 && canPlantOnTop(blockState, world, blockPos);
}
}

@Override
public void grow(ServerWorld world, net.minecraft.util.math.random.Random random, BlockPos pos, BlockState state) {
int mushroomHeight = random.nextInt(4)+4;
BlockState stemState = Blocks.MUSHROOM_STEM.getDefaultState().with(MushroomBlock.DOWN, false);
BlockState capState = ParadiseLostBlocks.PINK_SPORECAP_BLOCK.getDefaultState().with(MushroomBlock.UP, false);
if (this.hasRoomToGrow(mushroomHeight+1, world, pos)) {
// stem
for (int i = 0; i < mushroomHeight; i++) {
world.setBlockState(pos.down(i), stemState);
}
// layers
for (int i = 1; i <= 2; i++) {
for (Direction d : ConnectingBlock.FACING_PROPERTIES.keySet()) {
if (!d.getAxis().isHorizontal()) continue;
BlockPos layer = pos.down(mushroomHeight - i).offset(d, 2);
BlockState insideCapState = capState.with(ConnectingBlock.FACING_PROPERTIES.get(d.getOpposite()), false);
world.setBlockState(layer, insideCapState);
world.setBlockState(layer.offset(d.rotateClockwise(Direction.Axis.Y)), insideCapState);
world.setBlockState(layer.offset(d.rotateCounterclockwise(Direction.Axis.Y)), insideCapState);
}
}
// middle level
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
world.setBlockState(pos.down(mushroomHeight).north(i).east(j), capState);
}
}
// extra detail
if (mushroomHeight >= 5 && random.nextBoolean()) {
BlockPos layer = pos.down(random.nextBetween(1, mushroomHeight-4));
Direction d = (Direction) ConnectingBlock.FACING_PROPERTIES.keySet().toArray()[random.nextBetween(2, 5)];
world.setBlockState(layer.offset(d), capState);
world.setBlockState(layer.offset(d).offset(d.rotateClockwise(Direction.Axis.Y)), capState);
world.setBlockState(layer.offset(d).offset(d.rotateClockwise(Direction.Axis.Y)).offset(d.getOpposite()), capState);
}
}
}

private boolean hasRoomToGrow(int mushroomHeight, ServerWorld world, BlockPos pos) {
for (int j = -1; j >= -mushroomHeight; j--) {
int k = 3;

for (int l = -k; l <= k; l++) {
for (int m = -k; m <= k; m++) {
BlockState blockState2 = world.getBlockState(pos.add(l, j, m));
if (!blockState2.isAir() && !blockState2.isIn(BlockTags.LEAVES)) {
return false;
}
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.*;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import net.minecraft.world.gen.feature.ConfiguredFeature;

import java.util.Iterator;
import java.util.Optional;
import java.util.Random;

public class ParadiseLostMushroomPlantBlock extends PlantBlock {
public class ParadiseLostMushroomPlantBlock extends PlantBlock implements Fertilizable {

public static final MapCodec<ParadiseLostMushroomPlantBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
TagKey.codec(RegistryKeys.BLOCK).fieldOf("plantable_on").forGetter((block) -> block.plantableOn), createSettingsCodec()
TagKey.codec(RegistryKeys.BLOCK).fieldOf("plantable_on").forGetter((block) -> block.plantableOn),
RegistryKey.createCodec(RegistryKeys.CONFIGURED_FEATURE).fieldOf("feature").forGetter(block -> block.featureKey),
createSettingsCodec()
).apply(instance, ParadiseLostMushroomPlantBlock::new));
protected final TagKey<Block> plantableOn;
private final RegistryKey<ConfiguredFeature<?, ?>> featureKey;

public ParadiseLostMushroomPlantBlock(TagKey<Block> plantableOn, Settings settings) {
public ParadiseLostMushroomPlantBlock(TagKey<Block> plantableOn, RegistryKey<ConfiguredFeature<?, ?>> featureKey, Settings settings) {
super(settings);
this.plantableOn = plantableOn;
this.featureKey = featureKey;
}

@Override
Expand Down Expand Up @@ -83,4 +92,27 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBaseLightLevel(pos, 0) < 13 && canPlantOnTop(blockState, world, blockPos);
}
}

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return true;
}

@Override
public boolean canGrow(World world, net.minecraft.util.math.random.Random random, BlockPos pos, BlockState state) {
return random.nextFloat() < 0.4;
}

@Override
public void grow(ServerWorld world, net.minecraft.util.math.random.Random random, BlockPos pos, BlockState state) {
Optional<? extends RegistryEntry<ConfiguredFeature<?, ?>>> optional = world.getRegistryManager()
.get(RegistryKeys.CONFIGURED_FEATURE)
.getEntry(this.featureKey);
if (!optional.isEmpty()) {
world.removeBlock(pos, false);
if (!((ConfiguredFeature)((RegistryEntry)optional.get()).value()).generate(world, world.getChunkManager().getChunkGenerator(), random, pos)) {
world.setBlockState(pos, state, Block.NOTIFY_ALL);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.id.paradiselost.blocks.ParadiseLostBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Fertilizable;
import net.minecraft.block.PlantBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class WallClingingPlantBlock extends PlantBlock {
public class WallClingingPlantBlock extends PlantBlock implements Fertilizable {

public static final MapCodec<WallClingingPlantBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
return instance.group(TagKey.codec(RegistryKeys.BLOCK).fieldOf("clingable_blocks").forGetter((block) -> {
Expand Down Expand Up @@ -82,4 +88,38 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
super.appendProperties(builder);
builder.add(FACING);
}

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return true;
}

@Override
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
Direction facing = state.get(FACING).getOpposite();
return random.nextFloat() < 0.4 && hasRoomToGrow(world, pos, facing);
}

@Override
public void grow(ServerWorld world, net.minecraft.util.math.random.Random random, BlockPos pos, BlockState state) {
BlockState capState = ParadiseLostBlocks.ROOTCAP_BLOCK.getDefaultState();
Direction facing = state.get(FACING).getOpposite();
for (int l = 0; l <= 1; l++) {
for (int m = -1; m <= 1; m++) {
world.setBlockState(pos.offset(facing, l).offset(facing.rotateClockwise(Direction.Axis.Y), m), capState);
}
}
}

private boolean hasRoomToGrow(World world, BlockPos pos, Direction facing) {
for (int l = 0; l <= 2; l++) {
for (int m = -1; m <= 1; m++) {
BlockState blockState2 = world.getBlockState(pos.offset(facing, l).offset(facing.rotateClockwise(Direction.Axis.Y), m));
if (!blockState2.isAir() && !blockState2.isIn(BlockTags.LEAVES) && !blockState2.isOf(this)) {
return false;
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public class ParadiseLostItemGroups {
entries.add(ROOTCAP);
entries.add(BROWN_SPORECAP);
entries.add(PINK_SPORECAP);
entries.add(ROOTCAP_BLOCK);
entries.add(BROWN_SPORECAP_BLOCK);
entries.add(PINK_SPORECAP_BLOCK);
// plants
entries.add(BLACKCURRANT);
entries.add(AMADRYS_BUSHEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ private static Settings food(FoodComponent foodComponent) {
public static final BlockItem ROOTCAP = add(ParadiseLostBlocks.ROOTCAP, compostable65);
public static final BlockItem BROWN_SPORECAP = add(ParadiseLostBlocks.BROWN_SPORECAP, compostable65);
public static final BlockItem PINK_SPORECAP = add(ParadiseLostBlocks.PINK_SPORECAP, compostable65);
public static final BlockItem ROOTCAP_BLOCK = add(ParadiseLostBlocks.ROOTCAP_BLOCK, compostable85);
public static final BlockItem BROWN_SPORECAP_BLOCK = add(ParadiseLostBlocks.BROWN_SPORECAP_BLOCK, compostable85);
public static final BlockItem PINK_SPORECAP_BLOCK = add(ParadiseLostBlocks.PINK_SPORECAP_BLOCK, compostable85);

public static final BlockItem FLAXWEAVE_CUSHION = add(ParadiseLostBlocks.FLAXWEAVE_CUSHION, fuel(300));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import net.minecraft.world.gen.feature.DeltaFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.HugeMushroomFeatureConfig;

public class ParadiseLostFeatures {
public static final ParadiseLostLakeFeature LAKE = register("lake", new ParadiseLostLakeFeature(DynamicConfiguration.CODEC));

public static final ParadiseLostDeltaFeature DELTA_FEATURE = register("delta_feature", new ParadiseLostDeltaFeature(DeltaFeatureConfig.CODEC));
public static final GroundcoverFeature GROUNDCOVER_FEATURE = register("groundcover_feature", new GroundcoverFeature(GroundcoverFeatureConfig.CODEC));
public static final ParadiseLostBoulderFeature BOULDER = register("boulder", new ParadiseLostBoulderFeature(BoulderFeatureConfig.CODEC));
public static final VitrouliteSpireFeature VITROULITE_SPIRE_FEATURE = register("vitroulite_spire", new VitrouliteSpireFeature(DefaultFeatureConfig.CODEC));

Expand All @@ -30,6 +30,9 @@ public class ParadiseLostFeatures {
public static final JaggedOreFeature JAGGED_ORE = register("jagged_ore", new JaggedOreFeature(JaggedOreConfig.CODEC));
public static final SurtrumMeteoriteFeature SURTRUM_METEORITE_FEATURE = register("surtrum_meteorite", new SurtrumMeteoriteFeature(DefaultFeatureConfig.CODEC));

public static final HugeBrownSporecapFeature BROWN_SPORECAP_FEATURE = register("huge_brown_sporecap", new HugeBrownSporecapFeature(HugeMushroomFeatureConfig.CODEC));


private static <C extends FeatureConfig, F extends Feature<C>> F register(String id, F feature) {
return Registry.register(Registries.FEATURE, ParadiseLost.locate(id), feature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ParadiseLostTreeConfiguredFeatures extends ParadiseLostConfiguredFe
public static final RegistryKey<ConfiguredFeature<?, ?>> SHIELD_STUMPS = of("shield_stumps");
public static final RegistryKey<ConfiguredFeature<?, ?>> SHIELD_HOLLOW_STUMPS = of("shield_hollow_stumps");

// Mushrooms
public static final RegistryKey<ConfiguredFeature<?, ?>> HUGE_BROWN_SPORECAP = of("huge_brown_sporecap");

// Assortments
public static final RegistryKey<ConfiguredFeature<?, ?>> SCATTERED_TREES = of("trees_scattered");
public static final RegistryKey<ConfiguredFeature<?, ?>> SHIELD_TREES = of("trees_shield");
Expand Down
Loading

0 comments on commit 6204a3a

Please sign in to comment.