Skip to content

Commit

Permalink
Fix moss and finally planks
Browse files Browse the repository at this point in the history
  • Loading branch information
Onako2 committed Sep 29, 2024
1 parent 6da8987 commit 9a8bd3f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/rs/onako2/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rs.onako2.block.PaleMossBlock;
import rs.onako2.block.PaleRootsBlock;
import rs.onako2.block.PaleRootsPlantBlock;
import rs.onako2.feature.pale_moss_ceiling_feature.PaleMossPatchCeilingConfig;
import rs.onako2.feature.pale_moss_ceiling_feature.PaleMossPatchCeilingFeature;
import rs.onako2.feature.pale_moss_feature.PaleMossPatchConfig;
import rs.onako2.feature.pale_moss_feature.PaleMossPatchFeature;
import rs.onako2.feature.pale_moss_patch_bonemeal.PaleMossPatchBonemealConfig;
import rs.onako2.feature.pale_moss_patch_bonemeal.PaleMossPatchBonemealFeature;
import rs.onako2.feature.pale_short_grass_feature.PaleShortGrassFeature;
import rs.onako2.feature.pale_short_grass_feature.PaleShortGrassPatchConfig;
import rs.onako2.feature.paletree.PaleFeatureConfig;
Expand All @@ -38,7 +41,7 @@ public class Init implements ModInitializer {

public static final Block PALE_SHORT_GRASS = new ShortPlantBlock(AbstractBlock.Settings.create().mapColor(MapColor.PALE_YELLOW).replaceable().noCollision().breakInstantly().sounds(BlockSoundGroup.GRASS).offset(AbstractBlock.OffsetType.XYZ).burnable().pistonBehavior(PistonBehavior.DESTROY));

public static final Block PALE_MOSS_BLOCK = new MossBlock(AbstractBlock.Settings.create().mapColor(MapColor.PALE_YELLOW).strength(0.1F).sounds(BlockSoundGroup.MOSS_BLOCK).pistonBehavior(PistonBehavior.DESTROY));
public static final Block PALE_MOSS_BLOCK = new PaleMossBlock(AbstractBlock.Settings.create().mapColor(MapColor.PALE_YELLOW).strength(0.1F).sounds(BlockSoundGroup.MOSS_BLOCK).pistonBehavior(PistonBehavior.DESTROY));

public static final Block PALE_MOSS_CARPET = new CarpetBlock(AbstractBlock.Settings.create().mapColor(MapColor.PALE_YELLOW).strength(0.1F).sounds(BlockSoundGroup.MOSS_BLOCK).pistonBehavior(PistonBehavior.DESTROY));

Expand Down Expand Up @@ -78,6 +81,10 @@ public class Init implements ModInitializer {

public static final PaleShortGrassFeature PALE_SHORT_GRASS_FEATURE = new PaleShortGrassFeature(PaleShortGrassPatchConfig.CODEC);

public static final Identifier PALE_MOSS_PATCH_BONEMEAL_FEATURE_ID = Identifier.of("iwie", "pale_moss_patch_bonemeal");

public static final PaleMossPatchBonemealFeature PALE_MOSS_PATCH_BONEMEAL_FEATURE = new PaleMossPatchBonemealFeature(PaleMossPatchBonemealConfig.CODEC);

private static final ItemGroup IWIE = FabricItemGroup.builder()
.icon(() -> new ItemStack(TEST))
.displayName(Text.translatable("itemGroup.iwie.main"))
Expand Down Expand Up @@ -115,6 +122,8 @@ public void onInitialize() {

Registry.register(Registries.FEATURE, PALE_SHORT_GRASS_PATCH_FEATURE_ID, PALE_SHORT_GRASS_FEATURE);

Registry.register(Registries.FEATURE, PALE_MOSS_PATCH_BONEMEAL_FEATURE_ID, PALE_MOSS_PATCH_BONEMEAL_FEATURE);

ModRegistry.registerBlocks();
ModRegistry.registerItems();
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/rs/onako2/block/PaleMossBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package rs.onako2.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.MossBlock;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import rs.onako2.Init;

public class PaleMossBlock extends MossBlock {
public PaleMossBlock(Settings settings) {
super(settings);
}

@Override
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
world.getRegistryManager().getOptional(RegistryKeys.CONFIGURED_FEATURE).flatMap((key) -> {
return key.getEntry(Init.PALE_MOSS_PATCH_BONEMEAL_FEATURE_ID);
}).ifPresent((entry) -> {
((ConfiguredFeature)entry.value()).generate(world, world.getChunkManager().getChunkGenerator(), random, pos.up());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package rs.onako2.feature.pale_moss_patch_bonemeal;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.world.gen.feature.FeatureConfig;

public record PaleMossPatchBonemealConfig(int number, Identifier blockId) implements FeatureConfig {
public static final Codec<PaleMossPatchBonemealConfig> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
// you can add as many of these as you want, one for each parameter
Codecs.POSITIVE_INT.fieldOf("number").forGetter(PaleMossPatchBonemealConfig::number),
Identifier.CODEC.fieldOf("blockID").forGetter(PaleMossPatchBonemealConfig::blockId))
.apply(instance, PaleMossPatchBonemealConfig::new));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package rs.onako2.feature.pale_moss_patch_bonemeal;

import com.mojang.serialization.Codec;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.util.FeatureContext;

public class PaleMossPatchBonemealFeature extends Feature<PaleMossPatchBonemealConfig> {
public PaleMossPatchBonemealFeature(Codec<PaleMossPatchBonemealConfig> configCodec) {
super(configCodec);
}

@Override
public boolean generate(FeatureContext<PaleMossPatchBonemealConfig> context) {
StructureWorldAccess world = context.getWorld();
// the origin is the place where the game starts trying to place the feature
BlockPos origin = context.getOrigin();
// we won't use the random here, but we could if we wanted to
Random random = context.getRandom();
PaleMossPatchBonemealConfig config = context.getConfig();

// don't worry about where these come from-- we'll implement these methods soon
int number = config.number();
Identifier blockId = config.blockId();

BlockState blockState = Registries.BLOCK.get(blockId).getDefaultState();
// ensure the ID is okay
if (blockState == null)
throw new IllegalStateException(blockId + " could not be parsed to a valid block identifier!");

// find the surface of the world
BlockPos testPos = new BlockPos(origin);
for (int y = 0; y < world.getHeight(); y++) {
testPos = testPos.up();
// the tag name is dirt, but includes grass, mud, podzol, etc.
if (world.getBlockState(testPos).isIn(BlockTags.DIRT)) {
if (world.getBlockState(testPos.up()).isOf(Blocks.AIR)) {
for (int i = 0; i < number; i++) {
// create a simple pillar of blocks
world.setBlockState(testPos, blockState, 0x10);
testPos = testPos.up();

// ensure we don't try to place blocks outside the world
if (testPos.getY() >= world.getTopY()) break;
}
return true;
}
}
}
// the game couldn't find a place to put the pillar
return false;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/data/iwie/tags/item/pale_oak_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"iwie:pale_oak_log"
]
}

0 comments on commit 9a8bd3f

Please sign in to comment.