diff --git a/build.gradle b/build.gradle index 9ce4280..2ec29d4 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ base { } java { - toolchain.languageVersion = JavaLanguageVersion.of(17) + toolchain.languageVersion = JavaLanguageVersion.of(8) } minecraft { diff --git a/gradle.properties b/gradle.properties index 616e000..cf0c977 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,17 +4,17 @@ org.gradle.daemon=false mod_id=firefly_bush_backport mod_name=Firefly Bush Backport mod_license=All Rights Reserved -mod_version=1.1.0 +mod_version=1.0.0 mod_group_id=dev.micle mod_authors=Micle mod_description=Firefly bush backport from 1.21.5. -minecraft_version=1.20.1 -minecraft_version_range=[1.20.1,1.21) +minecraft_version=1.16.5 +minecraft_version_range=[1.16.5,1.17) -forge_version=47.4.0 -forge_version_range=[47,) -loader_version_range=[47,) +forge_version=36.2.42 +forge_version_range=[36,) +loader_version_range=[36,) mapping_channel=parchment -mapping_version=2023.09.03 +mapping_version=2022.03.06 diff --git a/src/generated/resources/assets/firefly_bush_backport/models/block/firefly_bush.json b/src/generated/resources/assets/firefly_bush_backport/models/block/firefly_bush.json index dd6b37f..e9afe13 100644 --- a/src/generated/resources/assets/firefly_bush_backport/models/block/firefly_bush.json +++ b/src/generated/resources/assets/firefly_bush_backport/models/block/firefly_bush.json @@ -1,6 +1,5 @@ { "parent": "firefly_bush_backport:block/cross_emissive", - "render_type": "minecraft:cutout", "textures": { "cross": "firefly_bush_backport:block/firefly_bush", "cross_emissive": "firefly_bush_backport:block/firefly_bush_emissive" diff --git a/src/generated/resources/assets/firefly_bush_backport/sounds.json b/src/generated/resources/assets/firefly_bush_backport/sounds.json index 751894d..2c1cde6 100644 --- a/src/generated/resources/assets/firefly_bush_backport/sounds.json +++ b/src/generated/resources/assets/firefly_bush_backport/sounds.json @@ -1,5 +1,6 @@ { "block.firefly_bush.idle": { + "subtitle": "sound.firefly_bush_backport.block.firefly_bush.idle", "sounds": [ { "name": "firefly_bush_backport:block/firefly_bush/firefly_bush1", @@ -49,7 +50,6 @@ "name": "firefly_bush_backport:block/firefly_bush/firefly_bush11", "volume": 4.0 } - ], - "subtitle": "sound.firefly_bush_backport.block.firefly_bush.idle" + ] } } \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json deleted file mode 100644 index 06ebf67..0000000 --- a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "forge:add_features", - "biomes": "#minecraft:is_overworld", - "features": "firefly_bush_backport:patch_firefly_bush_near_water", - "step": "vegetal_decoration" -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json deleted file mode 100644 index fe5ccb4..0000000 --- a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "forge:add_features", - "biomes": "#forge:is_swamp", - "features": "firefly_bush_backport:patch_firefly_bush_near_water_swamp", - "step": "vegetal_decoration" -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json deleted file mode 100644 index 6591b04..0000000 --- a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "forge:add_features", - "biomes": "#forge:is_swamp", - "features": "firefly_bush_backport:patch_firefly_bush_swamp", - "step": "vegetal_decoration" -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/remove_patch_firefly_bush_near_water.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/remove_patch_firefly_bush_near_water.json deleted file mode 100644 index 3969f80..0000000 --- a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/remove_patch_firefly_bush_near_water.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "forge:remove_features", - "biomes": "#forge:is_swamp", - "features": "firefly_bush_backport:patch_firefly_bush_near_water", - "steps": "vegetal_decoration" -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/loot_tables/blocks/firefly_bush.json b/src/generated/resources/data/firefly_bush_backport/loot_tables/blocks/firefly_bush.json index 1a3e099..1b7e3b2 100644 --- a/src/generated/resources/data/firefly_bush_backport/loot_tables/blocks/firefly_bush.json +++ b/src/generated/resources/data/firefly_bush_backport/loot_tables/blocks/firefly_bush.json @@ -2,20 +2,18 @@ "type": "minecraft:block", "pools": [ { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], + "rolls": 1, "entries": [ { "type": "minecraft:item", "name": "firefly_bush_backport:firefly_bush" } ], - "rolls": 1.0 + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] } - ], - "random_sequence": "firefly_bush_backport:blocks/firefly_bush" + ] } \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json b/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json deleted file mode 100644 index 38e328d..0000000 --- a/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "type": "minecraft:random_patch", - "config": { - "feature": { - "feature": { - "type": "minecraft:simple_block", - "config": { - "to_place": { - "type": "minecraft:simple_state_provider", - "state": { - "Name": "firefly_bush_backport:firefly_bush" - } - } - } - }, - "placement": [ - { - "type": "minecraft:block_predicate_filter", - "predicate": { - "type": "minecraft:matching_blocks", - "blocks": "minecraft:air" - } - } - ] - }, - "tries": 20, - "xz_spread": 4, - "y_spread": 3 - } -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json deleted file mode 100644 index abc3586..0000000 --- a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "feature": "firefly_bush_backport:patch_firefly_bush", - "placement": [ - { - "type": "minecraft:count", - "count": 2 - }, - { - "type": "minecraft:in_square" - }, - { - "type": "minecraft:heightmap", - "heightmap": "MOTION_BLOCKING_NO_LEAVES" - }, - { - "type": "minecraft:biome" - }, - { - "type": "minecraft:block_predicate_filter", - "predicate": { - "type": "minecraft:all_of", - "predicates": [ - { - "type": "minecraft:matching_blocks", - "blocks": "minecraft:air" - }, - { - "type": "minecraft:would_survive", - "state": { - "Name": "firefly_bush_backport:firefly_bush" - } - }, - { - "type": "minecraft:any_of", - "predicates": [ - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 1, - -1, - 0 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - -1, - -1, - 0 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 0, - -1, - 1 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 0, - -1, - -1 - ] - } - ] - } - ] - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json deleted file mode 100644 index 905cc61..0000000 --- a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "feature": "firefly_bush_backport:patch_firefly_bush", - "placement": [ - { - "type": "minecraft:count", - "count": 3 - }, - { - "type": "minecraft:in_square" - }, - { - "type": "minecraft:heightmap", - "heightmap": "MOTION_BLOCKING" - }, - { - "type": "minecraft:biome" - }, - { - "type": "minecraft:block_predicate_filter", - "predicate": { - "type": "minecraft:all_of", - "predicates": [ - { - "type": "minecraft:matching_blocks", - "blocks": "minecraft:air" - }, - { - "type": "minecraft:would_survive", - "state": { - "Name": "firefly_bush_backport:firefly_bush" - } - }, - { - "type": "minecraft:any_of", - "predicates": [ - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 1, - -1, - 0 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - -1, - -1, - 0 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 0, - -1, - 1 - ] - }, - { - "type": "minecraft:matching_fluids", - "fluids": [ - "minecraft:water", - "minecraft:flowing_water" - ], - "offset": [ - 0, - -1, - -1 - ] - } - ] - } - ] - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json deleted file mode 100644 index 8e849e5..0000000 --- a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "feature": "firefly_bush_backport:patch_firefly_bush", - "placement": [ - { - "type": "minecraft:rarity_filter", - "chance": 8 - }, - { - "type": "minecraft:in_square" - }, - { - "type": "minecraft:heightmap", - "heightmap": "MOTION_BLOCKING" - }, - { - "type": "minecraft:biome" - } - ] -} \ No newline at end of file diff --git a/src/main/java/dev/micle/firefly_bush_backport/FireflyBushBackport.java b/src/main/java/dev/micle/firefly_bush_backport/FireflyBushBackport.java index 2f7d666..57a2bc0 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/FireflyBushBackport.java +++ b/src/main/java/dev/micle/firefly_bush_backport/FireflyBushBackport.java @@ -1,30 +1,24 @@ package dev.micle.firefly_bush_backport; -import com.mojang.logging.LogUtils; import dev.micle.firefly_bush_backport.proxy.IProxy; import dev.micle.firefly_bush_backport.proxy.Proxy; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.slf4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; @Mod(FireflyBushBackport.MOD_ID) public class FireflyBushBackport { public static final String MOD_ID = "firefly_bush_backport"; - public static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogManager.getLogger(MOD_ID); private static FMLJavaModLoadingContext fmlJavaModLoadingContext; private static IProxy proxy; - public FireflyBushBackport(FMLJavaModLoadingContext context) { - fmlJavaModLoadingContext = context; - + public FireflyBushBackport() { proxy = DistExecutor.safeRunForDist( () -> Proxy.Client::new, () -> Proxy.Server::new ); } - - public static FMLJavaModLoadingContext getFMLJavaModLoadingContext() { - return fmlJavaModLoadingContext; - } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/block/FireflyBushBlock.java b/src/main/java/dev/micle/firefly_bush_backport/block/FireflyBushBlock.java index 4ba0ded..bc215b8 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/block/FireflyBushBlock.java +++ b/src/main/java/dev/micle/firefly_bush_backport/block/FireflyBushBlock.java @@ -3,36 +3,40 @@ package dev.micle.firefly_bush_backport.block; import dev.micle.firefly_bush_backport.config.Config; import dev.micle.firefly_bush_backport.particle.ModParticles; import dev.micle.firefly_bush_backport.sound.ModSounds; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.BonemealableBlock; -import net.minecraft.world.level.block.BushBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.Heightmap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.BushBlock; +import net.minecraft.block.IGrowable; +import net.minecraft.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.IWorldReader; +import net.minecraft.world.World; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.server.ServerWorld; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; import java.util.Optional; +import java.util.Random; +import java.util.stream.Collectors; -public class FireflyBushBlock extends BushBlock implements BonemealableBlock { +public class FireflyBushBlock extends BushBlock implements IGrowable { public FireflyBushBlock(Properties properties) { super(properties); } @Override @ParametersAreNonnullByDefault - public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource randomSource) { + public void animateTick(BlockState blockState, World level, BlockPos blockPos, Random randomSource) { if (randomSource.nextInt(Config.Client.bushFireflyAmbientSoundChanceOneIn.get()) == 0 && ( Config.Client.bushExtraAlwaysPlayAmbientSound.get() || - (isMoonVisible(level) && level.getHeight(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) <= blockPos.getY()) + (isMoonVisible(level) && level.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) <= blockPos.getY()) )) { level.playLocalSound( - blockPos, ModSounds.FIREFLY_BUSH_IDLE.get(), SoundSource.AMBIENT, 1.0F, 1.0F, false + blockPos.getX(), blockPos.getY(), blockPos.getZ(), ModSounds.FIREFLY_BUSH_IDLE.get(), SoundCategory.AMBIENT, 1.0F, 1.0F, false ); } @@ -47,7 +51,7 @@ public class FireflyBushBlock extends BushBlock implements BonemealableBlock { } } - public boolean isMoonVisible(Level level) { + public boolean isMoonVisible(World level) { if (!level.dimensionType().natural()) { return false; } else { @@ -58,37 +62,47 @@ public class FireflyBushBlock extends BushBlock implements BonemealableBlock { @Override @ParametersAreNonnullByDefault - public boolean isValidBonemealTarget(LevelReader level, BlockPos blockPos, BlockState blockState, boolean isClient) { + public boolean isValidBonemealTarget(IBlockReader level, BlockPos blockPos, BlockState blockState, boolean isClient) { return hasSpreadableNeighbourPos(level, blockPos, blockState); } @Override @ParametersAreNonnullByDefault - public boolean isBonemealSuccess(Level level, RandomSource randomSource, BlockPos blockPos, BlockState blockState) { + public boolean isBonemealSuccess(World level, Random randomSource, BlockPos blockPos, BlockState blockState) { return true; } @Override @ParametersAreNonnullByDefault - public void performBonemeal(ServerLevel level, RandomSource randomSource, BlockPos blockPos, BlockState blockState) { + public void performBonemeal(ServerWorld level, Random randomSource, BlockPos blockPos, BlockState blockState) { findSpreadableNeighbourPos(level, blockPos, blockState).ifPresent(x -> level.setBlockAndUpdate(x, this.defaultBlockState())); } - static boolean hasSpreadableNeighbourPos(LevelReader levelReader, BlockPos blockPos, BlockState blockState) { - return getSpreadableNeighbourPos(Direction.Plane.HORIZONTAL.stream().toList(), levelReader, blockPos, blockState).isPresent(); + private static boolean hasSpreadableNeighbourPos(IBlockReader levelReader, BlockPos blockPos, BlockState blockState) { + return getSpreadableNeighbourPos(Direction.Plane.HORIZONTAL.stream().collect(Collectors.toList()), levelReader, blockPos, blockState).isPresent(); } - static Optional findSpreadableNeighbourPos(Level level, BlockPos blockPos, BlockState blockState) { - return getSpreadableNeighbourPos(Direction.Plane.HORIZONTAL.shuffledCopy(level.random), level, blockPos, blockState); + private static Optional findSpreadableNeighbourPos(World level, BlockPos blockPos, BlockState blockState) { + return getSpreadableNeighbourPos(shuffledCopy(Direction.Plane.HORIZONTAL.stream().toArray(Direction[]::new), level.random), level, blockPos, blockState); } - static Optional getSpreadableNeighbourPos(List directions, LevelReader levelReader, BlockPos blockPos, BlockState blockState) { + private static Optional getSpreadableNeighbourPos(List directions, IBlockReader levelReader, BlockPos blockPos, BlockState blockState) { for (Direction direction : directions) { BlockPos blockPosDirection = blockPos.relative(direction); - if (levelReader.isEmptyBlock(blockPosDirection) && blockState.canSurvive(levelReader, blockPosDirection)) { + if (levelReader.getBlockState(blockPosDirection).is(Blocks.AIR) && blockState.canSurvive((IWorldReader) levelReader, blockPosDirection)) { return Optional.of(blockPosDirection); } } return Optional.empty(); } + + private static List shuffledCopy(T[] array, Random random) { + ObjectArrayList objectArrayList = new ObjectArrayList<>(array); + int i = objectArrayList.size(); + for (int j = i; j > 1; --j) { + int k = random.nextInt(j); + objectArrayList.set(j - 1, objectArrayList.set(k, objectArrayList.get(j - 1))); + } + return objectArrayList; + } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/block/ModBlocks.java b/src/main/java/dev/micle/firefly_bush_backport/block/ModBlocks.java index 32609e6..ab3c275 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/block/ModBlocks.java +++ b/src/main/java/dev/micle/firefly_bush_backport/block/ModBlocks.java @@ -1,28 +1,25 @@ package dev.micle.firefly_bush_backport.block; import dev.micle.firefly_bush_backport.FireflyBushBackport; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.material.MapColor; -import net.minecraft.world.level.material.PushReaction; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; public class ModBlocks { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, FireflyBushBackport.MOD_ID); public static RegistryObject FIREFLY_BUSH = BLOCKS.register("firefly_bush", - () -> new FireflyBushBlock(BlockBehaviour.Properties.of() - .mapColor(MapColor.PLANT) - .ignitedByLava() + () -> new FireflyBushBlock(AbstractBlock.Properties.of(Material.PLANT, MaterialColor.PLANT) .lightLevel(blockState -> 2) .noCollission() .instabreak() - .sound(SoundType.SWEET_BERRY_BUSH) - .pushReaction(PushReaction.DESTROY)) + .sound(SoundType.SWEET_BERRY_BUSH)) ); public static void register(IEventBus modEventBus) { diff --git a/src/main/java/dev/micle/firefly_bush_backport/config/Config.java b/src/main/java/dev/micle/firefly_bush_backport/config/Config.java index 3ec34fa..f328a23 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/config/Config.java +++ b/src/main/java/dev/micle/firefly_bush_backport/config/Config.java @@ -1,17 +1,18 @@ package dev.micle.firefly_bush_backport.config; import dev.micle.firefly_bush_backport.FireflyBushBackport; -import net.minecraft.util.random.SimpleWeightedRandomList; -import net.minecraft.world.level.Level; +import net.minecraft.util.WeightedList; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.event.config.ModConfigEvent; import org.apache.commons.lang3.tuple.Pair; import java.awt.*; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; @Mod.EventBusSubscriber(modid = FireflyBushBackport.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public final class Config { @@ -37,13 +38,11 @@ public final class Config { } public static void register() { - FireflyBushBackport.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC); - FireflyBushBackport.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.COMMON, COMMON_SPEC); - FireflyBushBackport.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.SERVER, SERVER_SPEC); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC); } @SubscribeEvent - public static void onConfigReloadEvent(ModConfigEvent event) { + public static void onConfigReloadEvent(ModConfig.ModConfigEvent event) { if (event.getConfig().getSpec() == CLIENT_SPEC) { Client.onConfigReload(); } else if (event.getConfig().getSpec() == COMMON_SPEC) { @@ -74,7 +73,7 @@ public final class Config { public static ForgeConfigSpec.DoubleValue particleExtraScale; public static ForgeConfigSpec.DoubleValue particleExtraBrightness; private static ForgeConfigSpec.ConfigValue> particleExtraColors; - public static SimpleWeightedRandomList particleExtraColorsWeightedList; + public static WeightedList particleExtraColorsWeightedList; Client(ForgeConfigSpec.Builder builder) { builder.comment("Settings for the firefly bush.").push("bush"); @@ -85,7 +84,7 @@ public final class Config { bushFireflyVerticalRange = builder .defineInRange("bushFireflyVerticalRange", 5.0, 0, Double.MAX_VALUE); bushFireflySpawnMaxBrightnessLevel = builder - .defineInRange("bushFireflySpawnMaxBrightnessLevel", 13, 0, Level.MAX_BRIGHTNESS); + .defineInRange("bushFireflySpawnMaxBrightnessLevel", 13, 0, 15); bushFireflyAmbientSoundChanceOneIn = builder .defineInRange("bushFireflyAmbientSoundChanceOneIn", 30, 0, Integer.MAX_VALUE); @@ -120,18 +119,17 @@ public final class Config { .defineInRange("particleExtraBrightness", 255.0, 0, 255); particleExtraColors = builder .comment("List of color hex values and their weight. Format: ','") - .defineList("particleExtraColors", List.of("#ffffff,1"), Client::isValidColorEntry); + .defineList("particleExtraColors", Stream.of("#ffffff,1").collect(Collectors.toList()), Client::isValidColorEntry); builder.pop(); builder.pop(); } private static void onConfigReload() { - SimpleWeightedRandomList.Builder particleExtraColorsWeightedListBuilder = SimpleWeightedRandomList.builder(); + particleExtraColorsWeightedList = new WeightedList<>(); for (String entry : particleExtraColors.get()) { String[] splitEntry = entry.split(","); - particleExtraColorsWeightedListBuilder.add(Color.decode(splitEntry[0]), Integer.parseInt(splitEntry[1])); + particleExtraColorsWeightedList.add(Color.decode(splitEntry[0]), Integer.parseInt(splitEntry[1])); } - particleExtraColorsWeightedList = particleExtraColorsWeightedListBuilder.build(); } private static boolean isValidColorEntry(Object entry) { diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java b/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java index 054df3e..070d07e 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java @@ -4,16 +4,12 @@ import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.data.client.ModBlockStateProvider; import dev.micle.firefly_bush_backport.data.client.ModItemModelProvider; import dev.micle.firefly_bush_backport.data.client.ModSoundDefinitionsProvider; -import dev.micle.firefly_bush_backport.data.server.ModLootTableProvider; -import dev.micle.firefly_bush_backport.data.server.ModWorldGenProvider; -import net.minecraft.core.HolderLookup; +import dev.micle.firefly_bush_backport.data.loot.ModLootTableProvider; import net.minecraft.data.DataGenerator; import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - -import java.util.concurrent.CompletableFuture; +import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; @Mod.EventBusSubscriber(modid = FireflyBushBackport.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @@ -21,13 +17,11 @@ public class DataGenerators { public static void gatherData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - CompletableFuture lookupProvider = event.getLookupProvider(); - generator.addProvider(event.includeClient(), new ModBlockStateProvider(generator, existingFileHelper)); - generator.addProvider(event.includeClient(), new ModItemModelProvider(generator, existingFileHelper)); - generator.addProvider(event.includeClient(), new ModSoundDefinitionsProvider(generator, existingFileHelper)); + generator.addProvider(new ModBlockStateProvider(generator, existingFileHelper)); + generator.addProvider(new ModItemModelProvider(generator, existingFileHelper)); + generator.addProvider(new ModSoundDefinitionsProvider(generator, existingFileHelper)); - generator.addProvider(event.includeServer(), new ModLootTableProvider(generator)); - generator.addProvider(event.includeServer(), new ModWorldGenProvider(generator, lookupProvider)); + generator.addProvider(new ModLootTableProvider(generator)); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModBlockStateProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModBlockStateProvider.java index d1e883c..db3880f 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModBlockStateProvider.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModBlockStateProvider.java @@ -2,18 +2,18 @@ package dev.micle.firefly_bush_backport.data.client; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; +import net.minecraft.block.Block; import net.minecraft.data.DataGenerator; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.generators.BlockStateProvider; import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.RegistryObject; +import net.minecraftforge.fml.RegistryObject; import java.util.Objects; public class ModBlockStateProvider extends BlockStateProvider { public ModBlockStateProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) { - super(generator.getPackOutput(), FireflyBushBackport.MOD_ID, existingFileHelper); + super(generator, FireflyBushBackport.MOD_ID, existingFileHelper); } @Override @@ -24,10 +24,9 @@ public class ModBlockStateProvider extends BlockStateProvider { private void crossEmissiveBlock(RegistryObject block) { String name = Objects.requireNonNull(block.getId()).getPath(); simpleBlock(block.get(), models() - .withExistingParent(name, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/cross_emissive")) + .withExistingParent(name, new ResourceLocation(FireflyBushBackport.MOD_ID, "block/cross_emissive")) .texture("cross", "block/" + name) .texture("cross_emissive", "block/" + name + "_emissive") - .renderType("cutout") ); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModItemModelProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModItemModelProvider.java index 2277e06..cbddf32 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModItemModelProvider.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModItemModelProvider.java @@ -2,21 +2,21 @@ package dev.micle.firefly_bush_backport.data.client; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; +import net.minecraft.block.Block; import net.minecraft.data.DataGenerator; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.Block; +import net.minecraft.item.Items; import net.minecraftforge.client.model.generators.ItemModelBuilder; import net.minecraftforge.client.model.generators.ItemModelProvider; import net.minecraftforge.client.model.generators.ModelFile; import net.minecraftforge.common.data.ExistingFileHelper; +import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; import java.util.Objects; public class ModItemModelProvider extends ItemModelProvider { public ModItemModelProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) { - super(generator.getPackOutput(), FireflyBushBackport.MOD_ID, existingFileHelper); + super(generator, FireflyBushBackport.MOD_ID, existingFileHelper); } @Override diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModSoundDefinitionsProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModSoundDefinitionsProvider.java index a508d28..94cc58c 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/client/ModSoundDefinitionsProvider.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/client/ModSoundDefinitionsProvider.java @@ -3,13 +3,13 @@ package dev.micle.firefly_bush_backport.data.client; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.sound.ModSounds; import net.minecraft.data.DataGenerator; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.SoundDefinitionsProvider; public class ModSoundDefinitionsProvider extends SoundDefinitionsProvider { public ModSoundDefinitionsProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) { - super(generator.getPackOutput(), FireflyBushBackport.MOD_ID, existingFileHelper); + super(generator, FireflyBushBackport.MOD_ID, existingFileHelper); } @Override @@ -17,31 +17,31 @@ public class ModSoundDefinitionsProvider extends SoundDefinitionsProvider { add(ModSounds.FIREFLY_BUSH_IDLE, definition() .subtitle("sound." + FireflyBushBackport.MOD_ID + ".block.firefly_bush.idle") .with( - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush1")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush1")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush2")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush2")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush3")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush3")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush4")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush4")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush5")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush5")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush6")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush6")) .volume(4), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush7")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush7")) .volume(4) .weight(2), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush8")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush8")) .volume(4) .weight(2), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush9")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush9")) .volume(4) .weight(2), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush10")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush10")) .volume(4) .weight(2), - sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush11")) + sound(new ResourceLocation(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush11")) .volume(4) ) ); diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModBlockLootTableProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModBlockLootTableProvider.java index 9365028..6f75cdd 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModBlockLootTableProvider.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModBlockLootTableProvider.java @@ -1,26 +1,23 @@ package dev.micle.firefly_bush_backport.data.loot; +import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; -import net.minecraft.data.loot.BlockLootSubProvider; -import net.minecraft.world.flag.FeatureFlags; -import net.minecraft.world.level.block.Block; -import net.minecraftforge.registries.RegistryObject; -import org.jetbrains.annotations.NotNull; +import net.minecraft.block.Block; +import net.minecraft.data.loot.BlockLootTables; +import net.minecraftforge.registries.ForgeRegistries; -import java.util.Set; +import java.util.stream.Collectors; -public class ModBlockLootTableProvider extends BlockLootSubProvider { - public ModBlockLootTableProvider() { - super(Set.of(), FeatureFlags.REGISTRY.allFlags()); +public class ModBlockLootTableProvider extends BlockLootTables { + @Override + protected void addTables() { + dropSelf(ModBlocks.FIREFLY_BUSH.get()); } @Override - protected void generate() { - this.dropSelf(ModBlocks.FIREFLY_BUSH.get()); - } - - @Override - protected @NotNull Iterable getKnownBlocks() { - return ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; + protected Iterable getKnownBlocks() { + return ForgeRegistries.BLOCKS.getValues().stream() + .filter(block -> FireflyBushBackport.MOD_ID.equals(block.getRegistryName().getNamespace())) + .collect(Collectors.toSet()); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModLootTableProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModLootTableProvider.java new file mode 100644 index 0000000..18dfa8c --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/data/loot/ModLootTableProvider.java @@ -0,0 +1,38 @@ +package dev.micle.firefly_bush_backport.data.loot; + +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; +import dev.micle.firefly_bush_backport.FireflyBushBackport; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.LootTableProvider; +import net.minecraft.loot.*; +import net.minecraft.util.ResourceLocation; + +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class ModLootTableProvider extends LootTableProvider { + public ModLootTableProvider(DataGenerator generator) { + super(generator); + } + + @Override + public String getName() { + return new ResourceLocation(FireflyBushBackport.MOD_ID, "loot_tables").toString(); + } + + @Override + protected List>>, LootParameterSet>> getTables() { + return ImmutableList.of( + Pair.of(ModBlockLootTableProvider::new, LootParameterSets.BLOCK) + ); + } + + @Override + protected void validate(Map map, ValidationTracker validationTracker) { + map.forEach((id, table) -> LootTableManager.validate(validationTracker, id, table)); + } +} diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/server/ModLootTableProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/server/ModLootTableProvider.java deleted file mode 100644 index 4d30a38..0000000 --- a/src/main/java/dev/micle/firefly_bush_backport/data/server/ModLootTableProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.micle.firefly_bush_backport.data.server; - -import dev.micle.firefly_bush_backport.data.loot.ModBlockLootTableProvider; -import net.minecraft.data.DataGenerator; -import net.minecraft.data.loot.LootTableProvider; -import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; - -import java.util.List; -import java.util.Set; - -public class ModLootTableProvider extends LootTableProvider { - public ModLootTableProvider(DataGenerator generator) { - super(generator.getPackOutput(), Set.of(), List.of( - new LootTableProvider.SubProviderEntry(ModBlockLootTableProvider::new, LootContextParamSets.BLOCK) - )); - } -} diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java deleted file mode 100644 index 3c9edc6..0000000 --- a/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.micle.firefly_bush_backport.data.server; - -import dev.micle.firefly_bush_backport.FireflyBushBackport; -import dev.micle.firefly_bush_backport.worldgen.ModBiomeModifiers; -import dev.micle.firefly_bush_backport.worldgen.ModConfiguredFeatures; -import dev.micle.firefly_bush_backport.worldgen.ModPlacedFeatures; -import net.minecraft.core.HolderLookup; -import net.minecraft.core.RegistrySetBuilder; -import net.minecraft.core.registries.Registries; -import net.minecraft.data.DataGenerator; -import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Set; -import java.util.concurrent.CompletableFuture; - -public class ModWorldGenProvider extends DatapackBuiltinEntriesProvider { - public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder() - .add(Registries.CONFIGURED_FEATURE, ModConfiguredFeatures::bootstrap) - .add(Registries.PLACED_FEATURE, ModPlacedFeatures::bootstrap) - .add(ForgeRegistries.Keys.BIOME_MODIFIERS, ModBiomeModifiers::bootstrap); - - public ModWorldGenProvider(DataGenerator generator, CompletableFuture registries) { - super(generator.getPackOutput(), registries, BUILDER, Set.of(FireflyBushBackport.MOD_ID)); - } -} diff --git a/src/main/java/dev/micle/firefly_bush_backport/event/OnBiomeLoadingEventHandler.java b/src/main/java/dev/micle/firefly_bush_backport/event/OnBiomeLoadingEventHandler.java new file mode 100644 index 0000000..50d9d7d --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/event/OnBiomeLoadingEventHandler.java @@ -0,0 +1,19 @@ +package dev.micle.firefly_bush_backport.event; + +import dev.micle.firefly_bush_backport.worldgen.ModConfiguredFeatures; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.GenerationStage; +import net.minecraftforge.event.world.BiomeLoadingEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class OnBiomeLoadingEventHandler { + @SubscribeEvent + public void onBiomeLoadingEvent(final BiomeLoadingEvent event) { + if (event.getCategory() == Biome.Category.SWAMP) { + event.getGeneration().addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, ModConfiguredFeatures.PLACED_PATCH_FIREFLY_BUSH_SWAMP); + event.getGeneration().addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, ModConfiguredFeatures.PLACED_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP); + } else if (event.getCategory() != Biome.Category.THEEND && event.getCategory() != Biome.Category.NETHER) { + event.getGeneration().addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, ModConfiguredFeatures.PLACED_PATCH_FIREFLY_BUSH_NEAR_WATER); + } + } +} diff --git a/src/main/java/dev/micle/firefly_bush_backport/event/OnWandererTradesEventHandler.java b/src/main/java/dev/micle/firefly_bush_backport/event/OnWandererTradesEventHandler.java index a798b75..8477ea0 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/event/OnWandererTradesEventHandler.java +++ b/src/main/java/dev/micle/firefly_bush_backport/event/OnWandererTradesEventHandler.java @@ -1,14 +1,14 @@ package dev.micle.firefly_bush_backport.event; import dev.micle.firefly_bush_backport.item.ModItems; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.BasicItemListing; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.BasicTrade; import net.minecraftforge.event.village.WandererTradesEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class OnWandererTradesEventHandler { @SubscribeEvent public void onWandererTradesEvent(WandererTradesEvent event) { - event.getGenericTrades().add(new BasicItemListing(3, new ItemStack(ModItems.FIREFLY_BUSH.get(), 1), 12, 1)); + event.getGenericTrades().add(new BasicTrade(3, new ItemStack(ModItems.FIREFLY_BUSH.get(), 1), 12, 1)); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/item/ModItems.java b/src/main/java/dev/micle/firefly_bush_backport/item/ModItems.java index 97c832d..b02b91d 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/item/ModItems.java +++ b/src/main/java/dev/micle/firefly_bush_backport/item/ModItems.java @@ -2,13 +2,14 @@ package dev.micle.firefly_bush_backport.item; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; +import dev.micle.firefly_bush_backport.tab.ModCreativeModeTabs; +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; import java.util.Objects; @@ -22,6 +23,6 @@ public class ModItems { } private static RegistryObject registerBlock(RegistryObject block) { - return ITEMS.register(Objects.requireNonNull(block.getId()).getPath(), () -> new BlockItem(block.get(), new Item.Properties())); + return ITEMS.register(Objects.requireNonNull(block.getId()).getPath(), () -> new BlockItem(block.get(), new Item.Properties().tab(ModCreativeModeTabs.MAIN_TAB))); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/particle/FireflyParticle.java b/src/main/java/dev/micle/firefly_bush_backport/particle/FireflyParticle.java index d041953..eed8dfe 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/particle/FireflyParticle.java +++ b/src/main/java/dev/micle/firefly_bush_backport/particle/FireflyParticle.java @@ -1,22 +1,32 @@ package dev.micle.firefly_bush_backport.particle; import dev.micle.firefly_bush_backport.config.Config; -import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.block.Blocks; import net.minecraft.client.particle.*; -import net.minecraft.core.BlockPos; -import net.minecraft.core.particles.SimpleParticleType; -import net.minecraft.util.Mth; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; +import net.minecraft.particles.BasicParticleType; +import net.minecraft.util.ReuseableStream; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import org.jetbrains.annotations.NotNull; import javax.annotation.ParametersAreNonnullByDefault; import java.awt.*; -import java.util.Optional; +import java.util.Random; +import java.util.stream.Stream; @OnlyIn(Dist.CLIENT) -public class FireflyParticle extends TextureSheetParticle { - protected FireflyParticle(ClientLevel clientLevel, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { +public class FireflyParticle extends SpriteTexturedParticle { + private static final double MAXIMUM_COLLISION_VELOCITY_SQUARED = MathHelper.square(100.00F); + private boolean stoppedByCollision; + private final float friction; + private final boolean speedUpWhenYMotionIsBlocked; + + protected FireflyParticle(ClientWorld clientLevel, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { super(clientLevel, x, y, z, xSpeed, ySpeed, zSpeed); this.speedUpWhenYMotionIsBlocked = true; this.friction = Config.Client.particleExtraFriction.get().floatValue(); @@ -27,8 +37,8 @@ public class FireflyParticle extends TextureSheetParticle { } @Override - public @NotNull ParticleRenderType getRenderType() { - return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; + public IParticleRenderType getRenderType() { + return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Override @@ -49,13 +59,34 @@ public class FireflyParticle extends TextureSheetParticle { } private float getLifetimeProgress(float age) { - return Mth.clamp(age / this.lifetime, 0.0F, 1.0F); + return MathHelper.clamp(age / this.lifetime, 0.0F, 1.0F); } @Override public void tick() { - super.tick(); - if (!this.level.getBlockState(BlockPos.containing(this.x, this.y, this.z)).isAir()) { + this.xo = this.x; + this.yo = this.y; + this.zo = this.z; + if (this.age++ >= this.lifetime) { + this.remove(); + } else { + this.yd -= 0.04D * (double) this.gravity; + this.move(this.xd, this.yd, this.zd); + if (this.speedUpWhenYMotionIsBlocked && this.y == this.yd) { + this.xd *= 1.1D; + this.zd *= 1.1D; + } + + this.xd *= this.friction; + this.yd *= this.friction; + this.zd *= this.friction; + if (this.onGround) { + this.xd *= 0.7F; + this.zd *= 0.7F; + } + } + + if (!this.level.getBlockState(new BlockPos(this.x, this.y, this.z)).is(Blocks.AIR)) { this.remove(); } else { this.setAlpha(getFadeAmount(this.getLifetimeProgress(this.age), @@ -68,18 +99,57 @@ public class FireflyParticle extends TextureSheetParticle { } } - @OnlyIn(Dist.CLIENT) - public static class FireflyProvider implements ParticleProvider { - private final SpriteSet sprite; + @Override + public void move(double pX, double pY, double pZ) { + if (!this.stoppedByCollision) { + double d0 = pX; + double d1 = pY; + double d2 = pZ; + if (this.hasPhysics && (pX != 0.0D || pY != 0.0D || pZ != 0.0D) && pX * pX + pY * pY + pZ * pZ < MAXIMUM_COLLISION_VELOCITY_SQUARED) { + Vector3d vec3 = Entity.collideBoundingBoxHeuristically((Entity) null, new Vector3d(pX, pY, pZ), this.getBoundingBox(), this.level, ISelectionContext.empty(), new ReuseableStream<>(Stream.empty())); + pX = vec3.x; + pY = vec3.y; + pZ = vec3.z; + } - public FireflyProvider(SpriteSet spriteSet) { + if (pX != 0.0D || pY != 0.0D || pZ != 0.0D) { + this.setBoundingBox(this.getBoundingBox().move(pX, pY, pZ)); + this.setLocationFromBoundingbox(); + } + + if (Math.abs(d1) >= (double) 1.0E-5F && Math.abs(pY) < (double) 1.0E-5F) { + this.stoppedByCollision = true; + } + + this.onGround = d1 != pY && d1 < 0.00; + if (d0 != pX) { + this.xd = 0.0D; + } + + if (d2 != pZ) { + this.zd = 0.0D; + } + } + } + + private void setParticleSpeed(double xd, double yd, double zd) { + this.xd = xd; + this.yd = yd; + this.zd = zd; + } + + @OnlyIn(Dist.CLIENT) + public static class FireflyProvider implements IParticleFactory { + private final IAnimatedSprite sprite; + + public FireflyProvider(IAnimatedSprite spriteSet) { this.sprite = spriteSet; } @ParametersAreNonnullByDefault public Particle createParticle( - SimpleParticleType simpleParticleType, - ClientLevel clientLevel, + BasicParticleType simpleParticleType, + ClientWorld clientLevel, double x, double y, double z, @@ -96,19 +166,21 @@ public class FireflyParticle extends TextureSheetParticle { clientLevel.random.nextBoolean() ? ySpeed : -ySpeed, 0.5 - clientLevel.random.nextDouble() ); - fireflyParticle.setLifetime(clientLevel.random.nextIntBetweenInclusive( - Config.Client.particleMinLifetime.get(), Config.Client.particleMaxLifetime.get() + fireflyParticle.setLifetime(nextIntBetweenInclusive( + clientLevel.random, Config.Client.particleMinLifetime.get(), Config.Client.particleMaxLifetime.get() )); fireflyParticle.scale(1.5F); fireflyParticle.pickSprite(this.sprite); fireflyParticle.setAlpha(0.0F); - Optional optionalColor = Config.Client.particleExtraColorsWeightedList.getRandomValue(clientLevel.random); - optionalColor.ifPresent(color -> - fireflyParticle.setColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F) - ); + Color color = Config.Client.particleExtraColorsWeightedList.getOne(clientLevel.random); + fireflyParticle.setColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F); return fireflyParticle; } + + private int nextIntBetweenInclusive(Random random, int low, int high) { + return random.nextInt(high - low + 1) + low; + } } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/particle/ModParticles.java b/src/main/java/dev/micle/firefly_bush_backport/particle/ModParticles.java index 7f1114e..6a3cd15 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/particle/ModParticles.java +++ b/src/main/java/dev/micle/firefly_bush_backport/particle/ModParticles.java @@ -1,18 +1,18 @@ package dev.micle.firefly_bush_backport.particle; import dev.micle.firefly_bush_backport.FireflyBushBackport; -import net.minecraft.core.particles.ParticleType; -import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.particles.BasicParticleType; +import net.minecraft.particles.ParticleType; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; public class ModParticles { public static final DeferredRegister> PARTICLE_TYPES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, FireflyBushBackport.MOD_ID); - public static final RegistryObject FIREFLY = PARTICLE_TYPES.register("firefly", - () -> new SimpleParticleType(false)); + public static final RegistryObject FIREFLY = PARTICLE_TYPES.register("firefly", + () -> new BasicParticleType(false)); public static void register(IEventBus modEventBus) { PARTICLE_TYPES.register(modEventBus); diff --git a/src/main/java/dev/micle/firefly_bush_backport/proxy/IProxy.java b/src/main/java/dev/micle/firefly_bush_backport/proxy/IProxy.java index b325ae3..56394ee 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/proxy/IProxy.java +++ b/src/main/java/dev/micle/firefly_bush_backport/proxy/IProxy.java @@ -1,11 +1,11 @@ package dev.micle.firefly_bush_backport.proxy; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; public interface IProxy { MinecraftServer getServer(); - Player getClientPlayer(); - Level getClientLevel(); + PlayerEntity getClientPlayer(); + ClientWorld getClientLevel(); } diff --git a/src/main/java/dev/micle/firefly_bush_backport/proxy/Proxy.java b/src/main/java/dev/micle/firefly_bush_backport/proxy/Proxy.java index 55c1906..c8a0504 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/proxy/Proxy.java +++ b/src/main/java/dev/micle/firefly_bush_backport/proxy/Proxy.java @@ -1,40 +1,43 @@ package dev.micle.firefly_bush_backport.proxy; -import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; import dev.micle.firefly_bush_backport.config.Config; +import dev.micle.firefly_bush_backport.event.OnBiomeLoadingEventHandler; import dev.micle.firefly_bush_backport.event.OnWandererTradesEventHandler; -import dev.micle.firefly_bush_backport.tab.ModCreativeModeTabs; import dev.micle.firefly_bush_backport.item.ModItems; import dev.micle.firefly_bush_backport.particle.FireflyParticle; import dev.micle.firefly_bush_backport.particle.ModParticles; import dev.micle.firefly_bush_backport.sound.ModSounds; +import dev.micle.firefly_bush_backport.tab.ModCreativeModeTabs; +import net.minecraft.block.ComposterBlock; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.ComposterBlock; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RegisterParticleProvidersEvent; +import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.AddReloadListenerEvent; -import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.event.lifecycle.*; +import net.minecraftforge.fml.event.server.FMLServerStartedEvent; +import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; public class Proxy implements IProxy { private static MinecraftServer server = null; // Common setup public Proxy() { - IEventBus modEventBus = FireflyBushBackport.getFMLJavaModLoadingContext().getModEventBus(); + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); Config.register(); ModBlocks.register(modEventBus); ModItems.register(modEventBus); - ModCreativeModeTabs.register(modEventBus); + ModCreativeModeTabs.register(); ModSounds.register(modEventBus); ModParticles.register(modEventBus); @@ -50,6 +53,7 @@ public class Proxy implements IProxy { // Register event handlers MinecraftForge.EVENT_BUS.register(new OnWandererTradesEventHandler()); + MinecraftForge.EVENT_BUS.register(new OnBiomeLoadingEventHandler()); } private static void setup(FMLCommonSetupEvent event) { @@ -62,11 +66,11 @@ public class Proxy implements IProxy { private static void onAddReloadListeners(AddReloadListenerEvent event) {} - private static void serverStarted(ServerStartedEvent event) { + private static void serverStarted(FMLServerStartedEvent event) { server = event.getServer(); } - private static void serverStopping(ServerStoppingEvent event) { + private static void serverStopping(FMLServerStoppingEvent event) { server = null; } @@ -76,19 +80,19 @@ public class Proxy implements IProxy { } @Override - public Player getClientPlayer() { + public PlayerEntity getClientPlayer() { return null; } @Override - public Level getClientLevel() { + public ClientWorld getClientLevel() { return null; } // Client setup public static class Client extends Proxy { public Client() { - IEventBus modEventBus = FireflyBushBackport.getFMLJavaModLoadingContext().getModEventBus(); + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); // Register mod event bus listeners modEventBus.addListener(Client::setup); @@ -96,23 +100,25 @@ public class Proxy implements IProxy { modEventBus.addListener(Client::registerParticleFactories); } - private static void setup(FMLClientSetupEvent event) {} + private static void setup(FMLClientSetupEvent event) { + RenderTypeLookup.setRenderLayer(ModBlocks.FIREFLY_BUSH.get(), RenderType.cutout()); + } private static void postSetup(FMLLoadCompleteEvent event) {} - private static void registerParticleFactories(RegisterParticleProvidersEvent event) { - event.registerSpriteSet(ModParticles.FIREFLY.get(), FireflyParticle.FireflyProvider::new); + private static void registerParticleFactories(ParticleFactoryRegisterEvent event) { + Minecraft.getInstance().particleEngine.register(ModParticles.FIREFLY.get(), FireflyParticle.FireflyProvider::new); } @Override @OnlyIn(Dist.CLIENT) - public Player getClientPlayer() { + public PlayerEntity getClientPlayer() { return Minecraft.getInstance().player; } @Override @OnlyIn(Dist.CLIENT) - public Level getClientLevel() { + public ClientWorld getClientLevel() { return Minecraft.getInstance().level; } } @@ -121,7 +127,7 @@ public class Proxy implements IProxy { public static class Server extends Proxy { public Server() { // Register mod event bus listeners - IEventBus modEventBus = FireflyBushBackport.getFMLJavaModLoadingContext().getModEventBus(); + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(Server::setup); } diff --git a/src/main/java/dev/micle/firefly_bush_backport/sound/ModSounds.java b/src/main/java/dev/micle/firefly_bush_backport/sound/ModSounds.java index a4dcb42..fed554b 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/sound/ModSounds.java +++ b/src/main/java/dev/micle/firefly_bush_backport/sound/ModSounds.java @@ -1,12 +1,12 @@ package dev.micle.firefly_bush_backport.sound; import dev.micle.firefly_bush_backport.FireflyBushBackport; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvent; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; public class ModSounds { public static final DeferredRegister SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, FireflyBushBackport.MOD_ID); @@ -18,6 +18,6 @@ public class ModSounds { } private static RegistryObject registerSoundEvent(String name) { - return SOUND_EVENTS.register(name, () -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name))); + return SOUND_EVENTS.register(name, () -> new SoundEvent(new ResourceLocation(FireflyBushBackport.MOD_ID, name))); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/tab/ModCreativeModeTabs.java b/src/main/java/dev/micle/firefly_bush_backport/tab/ModCreativeModeTabs.java index 5fdccb9..b35a1ad 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/tab/ModCreativeModeTabs.java +++ b/src/main/java/dev/micle/firefly_bush_backport/tab/ModCreativeModeTabs.java @@ -2,27 +2,24 @@ package dev.micle.firefly_bush_backport.tab; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; -import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.RegistryObject; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; public class ModCreativeModeTabs { - public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, FireflyBushBackport.MOD_ID); + public static final ItemGroup MAIN_TAB = new ItemGroup(new ResourceLocation(FireflyBushBackport.MOD_ID, "main").toString()) { + @Override + public ItemStack makeIcon() { + return ModBlocks.FIREFLY_BUSH.get().asItem().getDefaultInstance(); + } - public static final RegistryObject MAIN_TAB = CREATIVE_MODE_TABS.register( "main", - () -> CreativeModeTab.builder() - .title(Component.translatable(String.format("itemGroup.%s.main", FireflyBushBackport.MOD_ID))) - .icon(ModBlocks.FIREFLY_BUSH.get().asItem()::getDefaultInstance) - .displayItems((itemDisplayParams, output) -> { - output.accept(ModBlocks.FIREFLY_BUSH.get()); - }) - .build() - ); + @Override + public ITextComponent getDisplayName() { + return new TranslationTextComponent(String.format("itemGroup.%s.main", FireflyBushBackport.MOD_ID)); + } + }; - public static void register(IEventBus modEventBus) { - CREATIVE_MODE_TABS.register(modEventBus); - } + public static void register() {} } diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java deleted file mode 100644 index 49f640a..0000000 --- a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java +++ /dev/null @@ -1,59 +0,0 @@ -package dev.micle.firefly_bush_backport.worldgen; - -import dev.micle.firefly_bush_backport.FireflyBushBackport; -import net.minecraft.core.HolderGetter; -import net.minecraft.core.HolderSet; -import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.BiomeTags; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.GenerationStep; -import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import net.minecraftforge.common.Tags; -import net.minecraftforge.common.world.BiomeModifier; -import net.minecraftforge.common.world.ForgeBiomeModifiers; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Set; - -public class ModBiomeModifiers { - public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_SWAMP = registerKey("add_patch_firefly_bush_swamp"); - public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP = registerKey("add_patch_firefly_bush_near_water_swamp"); - public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_NEAR_WATER = registerKey("add_patch_firefly_bush_near_water"); - public static final ResourceKey REMOVE_PATCH_FIREFLY_BUSH_NEAR_WATER = registerKey("remove_patch_firefly_bush_near_water"); - - public static void bootstrap(BootstapContext context) { - HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); - HolderGetter biomes = context.lookup(Registries.BIOME); - - context.register(ADD_PATCH_FIREFLY_BUSH_SWAMP, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( - biomes.getOrThrow(Tags.Biomes.IS_SWAMP), - HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY)), - GenerationStep.Decoration.VEGETAL_DECORATION - )); - - context.register(ADD_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( - biomes.getOrThrow(Tags.Biomes.IS_SWAMP), - HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY)), - GenerationStep.Decoration.VEGETAL_DECORATION - )); - - context.register(ADD_PATCH_FIREFLY_BUSH_NEAR_WATER, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( - biomes.getOrThrow(BiomeTags.IS_OVERWORLD), - HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY)), - GenerationStep.Decoration.VEGETAL_DECORATION - )); - - context.register(REMOVE_PATCH_FIREFLY_BUSH_NEAR_WATER, new ForgeBiomeModifiers.RemoveFeaturesBiomeModifier( - biomes.getOrThrow(Tags.Biomes.IS_SWAMP), - HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY)), - Set.of(GenerationStep.Decoration.VEGETAL_DECORATION) - )); - } - - private static ResourceKey registerKey(String name) { - return ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); - } -} diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java index 66849da..ae28c93 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java +++ b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java @@ -2,43 +2,43 @@ package dev.micle.firefly_bush_backport.worldgen; import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.block.ModBlocks; -import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; -import net.minecraft.data.worldgen.placement.PlacementUtils; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -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.RandomPatchConfiguration; -import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration; -import net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.WorldGenRegistries; +import net.minecraft.world.gen.blockplacer.SimpleBlockPlacer; +import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider; +import net.minecraft.world.gen.feature.*; public class ModConfiguredFeatures { - public static final ResourceKey> PATCH_FIREFLY_BUSH_KEY = registerKey("patch_firefly_bush"); + private static final BlockClusterFeatureConfig.Builder CONFIG_PATCH_FIREFLY_BUSH = new BlockClusterFeatureConfig.Builder( + new SimpleBlockStateProvider(ModBlocks.FIREFLY_BUSH.get().defaultBlockState()), new SimpleBlockPlacer() + ).tries(20).xspread(4).yspread(3).zspread(4); - public static void bootstrap(BootstapContext> context) { - register(context, PATCH_FIREFLY_BUSH_KEY, Feature.RANDOM_PATCH, new RandomPatchConfiguration( - 20, - 4, - 3, - PlacementUtils.onlyWhenEmpty( - Feature.SIMPLE_BLOCK, - new SimpleBlockConfiguration( - SimpleStateProvider.simple(ModBlocks.FIREFLY_BUSH.get()) - ) - ) - )); - } + public static final ConfiguredFeature CONFIGURED_PATCH_FIREFLY_BUSH = create("patch_firefly_bush", Feature.RANDOM_PATCH.configured( + CONFIG_PATCH_FIREFLY_BUSH.build() + )); - public static ResourceKey> registerKey(String name) { - return ResourceKey.create(Registries.CONFIGURED_FEATURE, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); - } + public static final ConfiguredFeature CONFIGURED_PATCH_FIREFLY_BUSH_NEAR_WATER = create("patch_firefly_bush", Feature.RANDOM_PATCH.configured( + CONFIG_PATCH_FIREFLY_BUSH.needWater().build() + )); - private static > void register( - BootstapContext> context, - ResourceKey> key, F feature, FC configuration - ) { - context.register(key, new ConfiguredFeature<>(feature, configuration)); + public static final ConfiguredFeature PLACED_PATCH_FIREFLY_BUSH_SWAMP = create("patch_firefly_bush_swamp", CONFIGURED_PATCH_FIREFLY_BUSH + .chance(8) + .decorated(Features.Placements.HEIGHTMAP_SQUARE) + ); + + public static final ConfiguredFeature PLACED_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP = create("patch_firefly_bush_near_water_swamp", CONFIGURED_PATCH_FIREFLY_BUSH_NEAR_WATER + .count(3) + .decorated(Features.Placements.HEIGHTMAP_SQUARE) + ); + + public static final ConfiguredFeature PLACED_PATCH_FIREFLY_BUSH_NEAR_WATER = create("patch_firefly_bush_near_water", CONFIGURED_PATCH_FIREFLY_BUSH_NEAR_WATER + .count(2) + .decorated(Features.Placements.TOP_SOLID_HEIGHTMAP_SQUARE) + ); + + private static , CF extends ConfiguredFeature> CF create(String id, CF configuredFeature) { + Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, new ResourceLocation(FireflyBushBackport.MOD_ID, id), configuredFeature); + return configuredFeature; } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java deleted file mode 100644 index c7a3094..0000000 --- a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java +++ /dev/null @@ -1,79 +0,0 @@ -package dev.micle.firefly_bush_backport.worldgen; - -import dev.micle.firefly_bush_backport.FireflyBushBackport; -import dev.micle.firefly_bush_backport.block.ModBlocks; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderGetter; -import net.minecraft.core.Vec3i; -import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; -import net.minecraft.data.worldgen.placement.PlacementUtils; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.placement.*; -import net.minecraft.world.level.material.Fluids; - -import java.util.List; - -public class ModPlacedFeatures { - public static final ResourceKey PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY = registerKey("patch_firefly_bush_swamp"); - public static final ResourceKey PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY = registerKey("patch_firefly_bush_near_water_swamp"); - public static final ResourceKey PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY = registerKey("patch_firefly_bush_near_water"); - - public static void bootstrap(BootstapContext context) { - HolderGetter> configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE); - - register(context, PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( - RarityFilter.onAverageOnceEvery(8), - InSquarePlacement.spread(), - PlacementUtils.HEIGHTMAP, - BiomeFilter.biome() - )); - - register(context, PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( - CountPlacement.of(3), - InSquarePlacement.spread(), - PlacementUtils.HEIGHTMAP, - BiomeFilter.biome(), - BlockPredicateFilter.forPredicate(BlockPredicate.allOf( - BlockPredicate.matchesBlocks(Blocks.AIR), - BlockPredicate.wouldSurvive(ModBlocks.FIREFLY_BUSH.get().defaultBlockState(), Vec3i.ZERO), - BlockPredicate.anyOf( - BlockPredicate.matchesFluids(new Vec3i(1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(-1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(0, -1, 1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(0, -1, -1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)) - ) - )) - )); - - register(context, PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( - CountPlacement.of(2), - InSquarePlacement.spread(), - HeightmapPlacement.onHeightmap(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES), - BiomeFilter.biome(), - BlockPredicateFilter.forPredicate(BlockPredicate.allOf( - BlockPredicate.matchesBlocks(Blocks.AIR), - BlockPredicate.wouldSurvive(ModBlocks.FIREFLY_BUSH.get().defaultBlockState(), Vec3i.ZERO), - BlockPredicate.anyOf( - BlockPredicate.matchesFluids(new Vec3i(1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(-1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(0, -1, 1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), - BlockPredicate.matchesFluids(new Vec3i(0, -1, -1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)) - ) - )) - )); - } - - private static ResourceKey registerKey(String name) { - return ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); - } - - private static void register(BootstapContext context, ResourceKey key, Holder> configuration, List modifiers) { - context.register(key, new PlacedFeature(configuration, List.copyOf(modifiers))); - } -}