Skip to content

Commit

Permalink
1.18.2 - 3.1.1
Browse files Browse the repository at this point in the history
- rewrote the entire mod
- new world generation
- new configuration
- new registries
  • Loading branch information
wolfkidsounds committed Jan 24, 2023
1 parent 390c637 commit 2afafb8
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/wks/wolfkidsounds/wildplants/CommonSetup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package wks.wolfkidsounds.wildplants;

import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import wks.wolfkidsounds.wildplants.config.Configuration;
import wks.wolfkidsounds.wildplants.world.WildCropGeneration;

public class CommonSetup {
public static void init(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
if (Configuration.ENABLE_MINECRAFT.get()) {WildCropGeneration.registerWildMinecraftCropGeneration();}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wks.wolfkidsounds.wildplants.block;

import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FlowerBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class WildCropBlock extends FlowerBlock {
protected static final VoxelShape SHAPE = Block.box(2.0D, 0.0D, 2.0D, 14.0D, 13.0D, 14.0D);

public WildCropBlock(MobEffect suspiciousStewEffect, int effectDuration, Properties properties) {
super(suspiciousStewEffect, effectDuration, properties);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE;
}

@Override
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
return state.is(BlockTags.DIRT) || state.is(BlockTags.SAND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package wks.wolfkidsounds.wildplants.config;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class Configuration {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;

public static ForgeConfigSpec.ConfigValue<Integer> GLOBAL_FREQUENCY;
public static ForgeConfigSpec.ConfigValue<Integer> GLOBAL_SPREAD_SIZE;

public static ForgeConfigSpec.BooleanValue ENABLE_MINECRAFT;
public static ForgeConfigSpec.BooleanValue ENABLE_IMMERSIVEENGINEERING;
public static ForgeConfigSpec.BooleanValue ENABLE_VEGGIEWAY;
public static ForgeConfigSpec.BooleanValue ENABLE_HARVESTCRAFT;

static {

BUILDER.push("General");
BUILDER.push("Global_Modifier");
GLOBAL_FREQUENCY = BUILDER
.comment("How often to try to place a patch. (higher is more) [Default: 50]")
.define("Frequency", 50);
GLOBAL_SPREAD_SIZE = BUILDER
.comment("How far apart crops are planted in a patch. (higher is more) [Default: 6]")
.define("Size", 6);
BUILDER.pop();
BUILDER.push("Compat");
ENABLE_MINECRAFT = BUILDER
.define("Minecraft", true);
ENABLE_IMMERSIVEENGINEERING = BUILDER
.define("Immersive_Engineering", true);
ENABLE_VEGGIEWAY = BUILDER
.define("Veggie_Way", true);
ENABLE_HARVESTCRAFT = BUILDER
.define("Harvestcraft", true);
BUILDER.pop();
BUILDER.pop();

SPEC = BUILDER.build();
}
}
54 changes: 54 additions & 0 deletions src/main/java/wks/wolfkidsounds/wildplants/event/CommonEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package wks.wolfkidsounds.wildplants.event;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import wks.wolfkidsounds.wildplants.Wildplants;
import wks.wolfkidsounds.wildplants.config.features.MinecraftConfig;
import wks.wolfkidsounds.wildplants.world.WildCropGeneration;

@Mod.EventBusSubscriber(modid = Wildplants.MOD_ID)
public class CommonEvents {
@SubscribeEvent
public static void onBiomeLoad(BiomeLoadingEvent event) {
BiomeGenerationSettingsBuilder builder = event.getGeneration();
Biome.ClimateSettings climate = event.getClimate();

ResourceLocation biomeName = event.getName();

//Biome Name
if (biomeName != null && biomeName.getPath().equals("beach")) {
if (MinecraftConfig.GENERATE_MINECRAFT_WILD_BEETROOTS.get()) {
builder.addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, WildCropGeneration.PATCH_WILD_MINECRAFT_BEETROOTS);
}
}

//Biome Category
if (event.getCategory().equals(Biome.BiomeCategory.SWAMP) || event.getCategory().equals(Biome.BiomeCategory.JUNGLE)) {
//TEST
}

//Temperature
if (climate.temperature >= 1.0F) {
if (MinecraftConfig.GENERATE_MINECRAFT_WILD_WHEAT.get()) {
builder.addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, WildCropGeneration.PATCH_WILD_MINECRAFT_WHEAT);
}
}

if (climate.temperature > 0.3F && climate.temperature < 1.0F) {
if (MinecraftConfig.GENERATE_MINECRAFT_WILD_CARROTS.get()) {
builder.addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, WildCropGeneration.PATCH_WILD_MINECRAFT_CARROTS);
}
}

if (climate.temperature > 0.0F && climate.temperature <= 0.3F) {
if (MinecraftConfig.GENERATE_MINECRAFT_WILD_POTATOES.get()) {
builder.addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, WildCropGeneration.PATCH_WILD_MINECRAFT_POTATOES);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package wks.wolfkidsounds.wildplants.registry;

import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import wks.wolfkidsounds.wildplants.Wildplants;
import wks.wolfkidsounds.wildplants.world.settings.WildCropConfig;
import wks.wolfkidsounds.wildplants.world.settings.WildCropFeature;

public class ModBiomeFeatures {
public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, Wildplants.MOD_ID);
public static final RegistryObject<Feature<WildCropConfig>> WILD_CROP = FEATURES.register("wild_plant", () -> new WildCropFeature(WildCropConfig.CODEC));
}
27 changes: 27 additions & 0 deletions src/main/java/wks/wolfkidsounds/wildplants/registry/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package wks.wolfkidsounds.wildplants.registry;

import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import wks.wolfkidsounds.wildplants.Wildplants;
import wks.wolfkidsounds.wildplants.block.WildCropBlock;

public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Wildplants.MOD_ID);

// Minecraft
public static final RegistryObject<Block> MINECRAFT_WILD_WHEAT = BLOCKS.register("minecraft_wild_wheat",
() -> new WildCropBlock(MobEffects.GLOWING, 1, Block.Properties.copy(Blocks.TALL_GRASS)));

public static final RegistryObject<Block> MINECRAFT_WILD_CARROTS = BLOCKS.register("minecraft_wild_carrots",
() -> new WildCropBlock(MobEffects.GLOWING, 1, Block.Properties.copy(Blocks.TALL_GRASS)));

public static final RegistryObject<Block> MINECRAFT_WILD_POTATOES = BLOCKS.register("minecraft_wild_potatoes",
() -> new WildCropBlock(MobEffects.GLOWING, 1, Block.Properties.copy(Blocks.TALL_GRASS)));

public static final RegistryObject<Block> MINECRAFT_WILD_BEETROOTS = BLOCKS.register("minecraft_wild_beetroots",
() -> new WildCropBlock(MobEffects.GLOWING, 1, Block.Properties.copy(Blocks.TALL_GRASS)));
}
26 changes: 26 additions & 0 deletions src/main/java/wks/wolfkidsounds/wildplants/registry/ModItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package wks.wolfkidsounds.wildplants.registry;

import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import wks.wolfkidsounds.wildplants.Wildplants;

public class ModItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Wildplants.MOD_ID);
// Wild Crops
public static final RegistryObject<Item> MINECRAFT_WILD_WHEAT_ = ITEMS.register("minecraft_wild_wheat",
() -> new BlockItem(ModBlocks.MINECRAFT_WILD_WHEAT.get(), minecraftCrop()));
public static final RegistryObject<Item> MINECRAFT_WILD_CARROTS = ITEMS.register("minecraft_wild_carrots",
() -> new BlockItem(ModBlocks.MINECRAFT_WILD_CARROTS.get(), minecraftCrop()));
public static final RegistryObject<Item> MINECRAFT_WILD_POTATOES = ITEMS.register("minecraft_wild_potatoes",
() -> new BlockItem(ModBlocks.MINECRAFT_WILD_POTATOES.get(), minecraftCrop()));
public static final RegistryObject<Item> MINECRAFT_WILD_BEETROOTS = ITEMS.register("minecraft_wild_beetroots",
() -> new BlockItem(ModBlocks.MINECRAFT_WILD_BEETROOTS.get(), minecraftCrop()));

// Helper methods
public static Item.Properties minecraftCrop() {
return new Item.Properties().tab(ModItemGroups.MINECRAFT_TAB);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package wks.wolfkidsounds.wildplants.registry;

import com.mojang.serialization.Codec;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
import net.minecraft.world.level.levelgen.placement.PlacementModifierType;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;
import wks.wolfkidsounds.wildplants.Wildplants;
import wks.wolfkidsounds.wildplants.world.settings.BiomeTagFilter;

public class ModPlacementModifiers {
public static final DeferredRegister<PlacementModifierType<?>> PLACEMENT_MODIFIERS = DeferredRegister.create(Registry.PLACEMENT_MODIFIER_REGISTRY, Wildplants.MOD_ID);

public static final RegistryObject<PlacementModifierType<BiomeTagFilter>> BIOME_TAG = PLACEMENT_MODIFIERS.register("biome_tag", () -> typeConvert(BiomeTagFilter.CODEC));

private static <P extends PlacementModifier> PlacementModifierType<P> typeConvert(Codec<P> codec) {
return () -> codec;
}
}
18 changes: 18 additions & 0 deletions src/main/java/wks/wolfkidsounds/wildplants/world/RenderSetup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package wks.wolfkidsounds.wildplants.world;

import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import wks.wolfkidsounds.wildplants.registry.ModBlocks;

public class RenderSetup
{
public static void init(final FMLClientSetupEvent event) {

//Minecraft
ItemBlockRenderTypes.setRenderLayer(ModBlocks.MINECRAFT_WILD_WHEAT.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.MINECRAFT_WILD_CARROTS.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.MINECRAFT_WILD_POTATOES.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.MINECRAFT_WILD_BEETROOTS.get(), RenderType.cutout());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package wks.wolfkidsounds.wildplants.world;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.placement.*;
import net.minecraftforge.common.Tags;
import wks.wolfkidsounds.wildplants.config.Configuration;
import wks.wolfkidsounds.wildplants.Wildplants;
import wks.wolfkidsounds.wildplants.config.features.MinecraftConfig;
import wks.wolfkidsounds.wildplants.registry.ModBiomeFeatures;
import wks.wolfkidsounds.wildplants.registry.ModBlocks;
import wks.wolfkidsounds.wildplants.world.settings.BiomeTagFilter;
import wks.wolfkidsounds.wildplants.world.settings.WildCropConfig;

import java.util.List;

public class WildCropGeneration {
public static final BlockPos BLOCK_BELOW = new BlockPos(0, -1, 0);
public static final BiomeTagFilter TAGGED_IS_OVERWORLD = BiomeTagFilter.biomeIsInTag(Tags.Biomes.IS_OVERWORLD);
public static Holder<ConfiguredFeature<WildCropConfig, ?>> FEATURE_PATCH_WILD_MINECRAFT_WHEAT;
public static Holder<ConfiguredFeature<WildCropConfig, ?>> FEATURE_PATCH_WILD_MINECRAFT_CARROTS;
public static Holder<ConfiguredFeature<WildCropConfig, ?>> FEATURE_PATCH_WILD_MINECRAFT_POTATOES;
public static Holder<ConfiguredFeature<WildCropConfig, ?>> FEATURE_PATCH_WILD_MINECRAFT_BEETROOTS;
public static Holder<PlacedFeature> PATCH_WILD_MINECRAFT_WHEAT;
public static Holder<PlacedFeature> PATCH_WILD_MINECRAFT_CARROTS;
public static Holder<PlacedFeature> PATCH_WILD_MINECRAFT_POTATOES;
public static Holder<PlacedFeature> PATCH_WILD_MINECRAFT_BEETROOTS;

public static int TRIES = Configuration.GLOBAL_FREQUENCY.get();
public static int SPREAD = Configuration.GLOBAL_SPREAD_SIZE.get();

public static void registerWildMinecraftCropGeneration() {
FEATURE_PATCH_WILD_MINECRAFT_WHEAT = register(new ResourceLocation(Wildplants.MOD_ID, "patch_minecraft_wild_wheat"),
ModBiomeFeatures.WILD_CROP.get(), wildCropConfig(ModBlocks.MINECRAFT_WILD_WHEAT.get(), BlockPredicate.matchesTag(BlockTags.DIRT, BLOCK_BELOW)));

FEATURE_PATCH_WILD_MINECRAFT_CARROTS = register(new ResourceLocation(Wildplants.MOD_ID, "patch_minecraft_wild_carrots"),
ModBiomeFeatures.WILD_CROP.get(), wildCropConfig(ModBlocks.MINECRAFT_WILD_CARROTS.get(), BlockPredicate.matchesTag(BlockTags.DIRT, BLOCK_BELOW)));

FEATURE_PATCH_WILD_MINECRAFT_POTATOES = register(new ResourceLocation(Wildplants.MOD_ID, "patch_minecraft_wild_potatoes"),
ModBiomeFeatures.WILD_CROP.get(), wildCropConfig(ModBlocks.MINECRAFT_WILD_POTATOES.get(), BlockPredicate.matchesTag(BlockTags.DIRT, BLOCK_BELOW)));

FEATURE_PATCH_WILD_MINECRAFT_BEETROOTS = register(new ResourceLocation(Wildplants.MOD_ID, "patch_minecraft_wild_beetroots"),
ModBiomeFeatures.WILD_CROP.get(), wildCropConfig(ModBlocks.MINECRAFT_WILD_BEETROOTS.get(), BlockPredicate.matchesBlocks(List.of(Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.RED_SAND, Blocks.SAND), BLOCK_BELOW)));


PATCH_WILD_MINECRAFT_WHEAT = registerPlacement(new ResourceLocation(Wildplants.MOD_ID, "patch_minecraft_wild_wheat"),
FEATURE_PATCH_WILD_MINECRAFT_WHEAT, RarityFilter.onAverageOnceEvery(MinecraftConfig.CHANCE_MINECRAFT_WILD_WHEAT.get()), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome(), TAGGED_IS_OVERWORLD);

PATCH_WILD_MINECRAFT_CARROTS = registerPlacement(new ResourceLocation("patch_wild_onions"),
FEATURE_PATCH_WILD_MINECRAFT_CARROTS, RarityFilter.onAverageOnceEvery(MinecraftConfig.CHANCE_MINECRAFT_WILD_CARROTS.get()), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome(), TAGGED_IS_OVERWORLD);

PATCH_WILD_MINECRAFT_POTATOES = registerPlacement(new ResourceLocation("patch_wild_tomatoes"),
FEATURE_PATCH_WILD_MINECRAFT_POTATOES, RarityFilter.onAverageOnceEvery(MinecraftConfig.CHANCE_MINECRAFT_WILD_POTATOES.get()), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome(), TAGGED_IS_OVERWORLD);

PATCH_WILD_MINECRAFT_BEETROOTS = registerPlacement(new ResourceLocation("patch_wild_carrots"),
FEATURE_PATCH_WILD_MINECRAFT_BEETROOTS, RarityFilter.onAverageOnceEvery(MinecraftConfig.CHANCE_MINECRAFT_WILD_BEETROOTS.get()), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome(), TAGGED_IS_OVERWORLD);

}

public static WildCropConfig wildCropConfig(Block primaryBlock, BlockPredicate plantedOn) {
return new WildCropConfig(TRIES, SPREAD+1, SPREAD-1, plantBlockConfig(primaryBlock, plantedOn), null);
}

public static Holder<PlacedFeature> plantBlockConfig(Block block, BlockPredicate plantedOn) {
return PlacementUtils.filtered(
Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(block)),
BlockPredicate.allOf(BlockPredicate.ONLY_IN_AIR_PREDICATE, plantedOn));
}

// Registry stuff

static Holder<PlacedFeature> registerPlacement(ResourceLocation id, Holder<? extends ConfiguredFeature<?, ?>> feature, PlacementModifier... modifiers) {
return BuiltinRegistries.register(BuiltinRegistries.PLACED_FEATURE, id, new PlacedFeature(Holder.hackyErase(feature), List.of(modifiers)));
}

protected static <FC extends FeatureConfiguration, F extends Feature<FC>> Holder<ConfiguredFeature<FC, ?>> register(ResourceLocation id, F feature, FC featureConfig) {
return register(BuiltinRegistries.CONFIGURED_FEATURE, id, new ConfiguredFeature<>(feature, featureConfig));
}

private static <V extends T, T> Holder<V> register(Registry<T> registry, ResourceLocation id, V value) {
return (Holder<V>) BuiltinRegistries.register(registry, id, value);
}
}
Loading

0 comments on commit 2afafb8

Please sign in to comment.