-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Add: Add custom BonemealItem interface for better compatibility and…
… qol.
- Loading branch information
Showing
14 changed files
with
333 additions
and
436 deletions.
There are no files selected for viewing
140 changes: 0 additions & 140 deletions
140
common/src/main/java/xyz/faewulf/diversity/event/useBonemealOnCoral.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +0,0 @@ | ||
package xyz.faewulf.diversity.event; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderSet; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.tags.BiomeTags; | ||
import net.minecraft.tags.BlockTags; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.minecraft.world.level.block.BaseCoralPlantTypeBlock; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.levelgen.feature.CoralClawFeature; | ||
import net.minecraft.world.level.levelgen.feature.CoralFeature; | ||
import net.minecraft.world.level.levelgen.feature.CoralMushroomFeature; | ||
import net.minecraft.world.level.levelgen.feature.CoralTreeFeature; | ||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; | ||
import net.minecraft.world.level.material.MapColor; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import xyz.faewulf.diversity.mixin.bonemealCoral.CoralFeatureInvoker; | ||
import xyz.faewulf.diversity.util.compare; | ||
import xyz.faewulf.diversity.util.config.ModConfigs; | ||
|
||
import java.util.Optional; | ||
|
||
import static net.minecraft.world.level.block.Block.UPDATE_ALL; | ||
|
||
public class useBonemealOnCoral { | ||
public static InteractionResult run(Level world, Player player, InteractionHand hand, BlockHitResult hitResult) { | ||
|
||
if (!ModConfigs.bonemeal_coral_fan) | ||
return InteractionResult.PASS; | ||
|
||
if (world.isClientSide) | ||
return InteractionResult.PASS; | ||
|
||
|
||
Item item = player.getItemInHand(hand).getItem(); | ||
|
||
if (item == Items.BONE_MEAL) { | ||
|
||
BlockState block = world.getBlockState(hitResult.getBlockPos()); | ||
BlockPos pos = hitResult.getBlockPos(); | ||
|
||
Holder<Biome> currentBiome = world.getBiome(pos); | ||
|
||
//check valid criteria | ||
if (block.is(BlockTags.CORALS) | ||
&& !compare.isHasTag(block.getBlock(), "diversity:bonemeal_blacklist") | ||
&& block.getValue(BaseCoralPlantTypeBlock.WATERLOGGED) | ||
&& world.getFluidState(pos.above()).is(FluidTags.WATER) | ||
&& currentBiome.is(BiomeTags.PRODUCES_CORALS_FROM_BONEMEAL) | ||
) { | ||
|
||
if (world.random.nextFloat() >= 0.15D) { | ||
player.swing(hand, true); | ||
|
||
if (world instanceof ServerLevel serverLevel) { | ||
serverLevel.playSound(null, pos, SoundEvents.BONE_MEAL_USE, SoundSource.PLAYERS, 1.0F, (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F); | ||
serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, // Bonemeal-like particles | ||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, // Position (above the block) | ||
7, // Number of particles | ||
0.3, 0.3, 0.3, // Particle spread on X, Y, Z axes | ||
0.1 // Particle speed | ||
); | ||
} | ||
|
||
return InteractionResult.PASS; | ||
} | ||
|
||
|
||
//perform bonmeal action | ||
|
||
CoralFeature coral = switch (world.random.nextInt(3)) { | ||
case 0 -> new CoralTreeFeature(NoneFeatureConfiguration.CODEC); | ||
case 1 -> new CoralClawFeature(NoneFeatureConfiguration.CODEC); | ||
default -> new CoralMushroomFeature(NoneFeatureConfiguration.CODEC); | ||
}; | ||
|
||
//get corresponding block based on the fan, use color map... | ||
MapColor color = block.getMapColor(world, pos); | ||
BlockState coralBlockMatchedColor = block; | ||
//get all coral blocks | ||
Optional<HolderSet.Named<Block>> coralBlocksRegistry = world.registryAccess().registryOrThrow(Registries.BLOCK).getTag(BlockTags.CORAL_BLOCKS); | ||
HolderSet.Named<Block> coralBlocks; | ||
|
||
//extra check | ||
if (coralBlocksRegistry.isPresent()) | ||
coralBlocks = coralBlocksRegistry.get(); | ||
else | ||
return InteractionResult.PASS; | ||
|
||
//then find using color | ||
for (Holder<Block> coral_block : coralBlocks) { | ||
coralBlockMatchedColor = coral_block.value().defaultBlockState(); | ||
if (coralBlockMatchedColor.getMapColor(world, pos) == color) { | ||
break; | ||
} | ||
} | ||
|
||
world.setBlock(pos, Blocks.WATER.defaultBlockState(), Block.UPDATE_NONE); | ||
|
||
if (!((CoralFeatureInvoker) coral).generateCoral(world, world.random, pos, coralBlockMatchedColor)) { | ||
world.setBlock(pos, block, UPDATE_ALL); | ||
} | ||
|
||
|
||
//handle perform action/effect | ||
player.swing(hand, true); | ||
|
||
if (world instanceof ServerLevel serverLevel) { | ||
serverLevel.playSound(null, pos, SoundEvents.BONE_MEAL_USE, SoundSource.PLAYERS, 1.0F, (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F); | ||
serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, // Bonemeal-like particles | ||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, // Position (above the block) | ||
7, // Number of particles | ||
0.3, 0.3, 0.3, // Particle spread on X, Y, Z axes | ||
0.1 // Particle speed | ||
); | ||
} | ||
|
||
player.getItemInHand(hand).consume(1, player); | ||
return InteractionResult.CONSUME; | ||
} | ||
} | ||
|
||
return InteractionResult.PASS; | ||
} | ||
} | ||
108 changes: 0 additions & 108 deletions
108
common/src/main/java/xyz/faewulf/diversity/event/useBonemealOnSmallFlower.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
common/src/main/java/xyz/faewulf/diversity/inter/ICustomBonemealable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package xyz.faewulf.diversity.inter; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.LevelReader; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface ICustomBonemealable { | ||
default boolean Diversity$isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) { | ||
return true; | ||
} | ||
|
||
boolean Diversity$isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state); | ||
|
||
void Diversity$performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state); | ||
} |
Oops, something went wrong.