Skip to content

Commit

Permalink
Move more Bonemeal handing into Common Code
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph T. McQuigg <J.T.McQuigg12@gmail.com>
  • Loading branch information
JT122406 committed Jan 7, 2025
1 parent 9956f8a commit f515ff1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.placement.VegetationPlacements;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
Expand All @@ -13,12 +14,25 @@
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.levelgen.biome.BWGBiomes;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldVegationPlacedFeatures;

import java.util.List;
import java.util.Optional;

public final class BoneMealHandler {
public static boolean grassBoneMealHandler(ServerLevel level, BlockPos blockPos, Block grass, ResourceKey<PlacedFeature> placedFeatureResourceKey, boolean randomizeFlower) {

public static boolean bwgBoneMealHandler(ServerLevel level, BlockPos blockPos, BlockState grass) {
if (grass.is(Blocks.GRASS_BLOCK))
if (level.getBiome(blockPos).is(BWGBiomes.PRAIRIE))
return grassBoneMealHandler(level, blockPos.above(), BWGBlocks.PRAIRIE_GRASS.get(), BWGOverworldVegationPlacedFeatures.PRAIRIE_GRASS_BONEMEAL, false);
else if (level.getBiome(blockPos).is(BWGBiomes.ALLIUM_SHRUBLAND))
return grassBoneMealHandler(level, blockPos.above(), Blocks.SHORT_GRASS, VegetationPlacements.GRASS_BONEMEAL, true);
return false;
}

private static boolean grassBoneMealHandler(ServerLevel level, BlockPos blockPos, Block grass, ResourceKey<PlacedFeature> placedFeatureResourceKey, boolean randomizeFlower) {
BlockState blockState = grass.defaultBlockState();
Optional<Holder.Reference<PlacedFeature>> optional = level.registryAccess()
.registryOrThrow(Registries.PLACED_FEATURE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package net.potionstudios.biomeswevegone.fabric.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.data.worldgen.placement.VegetationPlacements;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.GrassBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.potionstudios.biomeswevegone.util.BoneMealHandler;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.levelgen.biome.BWGBiomes;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldVegationPlacedFeatures;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -25,13 +20,7 @@ public abstract class PrairieGrassMixin {
*/
@Inject(method = "performBonemeal", at = @At("HEAD"), cancellable = true)
private void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state, CallbackInfo ci) {
boolean cancel = false;
if (state.is(Blocks.GRASS_BLOCK))
if (level.getBiome(pos).is(BWGBiomes.PRAIRIE))
cancel = BoneMealHandler.grassBoneMealHandler(level, pos.above(), BWGBlocks.PRAIRIE_GRASS.get(), BWGOverworldVegationPlacedFeatures.PRAIRIE_GRASS_BONEMEAL, false);
else if (level.getBiome(pos).is(BWGBiomes.ALLIUM_SHRUBLAND))
cancel = BoneMealHandler.grassBoneMealHandler(level, pos.above(), Blocks.GRASS, VegetationPlacements.GRASS_BONEMEAL, true);
if (cancel)
if (BoneMealHandler.bwgBoneMealHandler(level, pos, state))
ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.potionstudios.biomeswevegone.forge;

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.core.BlockPos;
import net.minecraft.data.worldgen.placement.VegetationPlacements;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.AxeItem;
Expand All @@ -24,8 +22,6 @@
import net.potionstudios.biomeswevegone.world.item.tools.ToolInteractions;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.block.BlockFeatures;
import net.potionstudios.biomeswevegone.world.level.levelgen.biome.BWGBiomes;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldVegationPlacedFeatures;

import java.util.HashMap;
import java.util.List;
Expand All @@ -45,7 +41,7 @@ public static void init() {
ToolInteractions.registerFlattenables(ShovelItem.FLATTENABLES::put);
}

public static void registerVanillaCompatEvents(IEventBus bus) {
public static void registerVanillaCompatEvents(final IEventBus bus) {
bus.addListener(VanillaCompatForge::registerTillables);
bus.addListener(VanillaCompatForge::registerFuels);
if (!BWGTradesConfig.INSTANCE.trades.disableTrades.value()) {
Expand Down Expand Up @@ -111,16 +107,7 @@ private static void onWanderingTrade(final WandererTradesEvent event) {
* @see BonemealEvent
*/
private static void onBoneMealUse(final BonemealEvent event) {
if (event.getLevel().isClientSide()) return;
ServerLevel level = (ServerLevel) event.getLevel();
BlockPos pos = event.getPos();
if (event.getBlock().is(Blocks.GRASS_BLOCK))
if (level.getBiome(pos).is(BWGBiomes.PRAIRIE)) {
BoneMealHandler.grassBoneMealHandler(level, pos.above(), BWGBlocks.PRAIRIE_GRASS.get(), BWGOverworldVegationPlacedFeatures.PRAIRIE_GRASS_BONEMEAL, false);
event.setResult(Event.Result.ALLOW);
} else if (level.getBiome(pos).is(BWGBiomes.ALLIUM_SHRUBLAND)) {
BoneMealHandler.grassBoneMealHandler(level, pos.above(), Blocks.GRASS, VegetationPlacements.GRASS_BONEMEAL, true);
event.setResult(Event.Result.ALLOW);
}
if (!event.getLevel().isClientSide() && BoneMealHandler.bwgBoneMealHandler((ServerLevel) event.getLevel(), event.getPos(), event.getBlock()))
event.setResult(Event.Result.ALLOW);
}
}

0 comments on commit f515ff1

Please sign in to comment.