3 files changed
+100
-156
No files matched your search
@@ -0,0 +1,88 @@
|
|||||||
|
package carpet.helpers;
|
||||||
|
|
||||||
|
import carpet.fakes.CoralFeatureInterface;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.HolderSet;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.tags.BlockTags;
|
||||||
|
import net.minecraft.tags.FluidTags;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
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.BonemealableBlock;
|
||||||
|
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.MaterialColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deduplicates logic for the different behaviors of the {@code renewableCoral} rule
|
||||||
|
*/
|
||||||
|
public interface FertilizableCoral extends BonemealableBlock {
|
||||||
|
/**
|
||||||
|
* @return Whether the rule for this behavior is enabled
|
||||||
|
*/
|
||||||
|
boolean isEnabled();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public default boolean isValidBonemealTarget(LevelReader world, BlockPos pos, BlockState state, boolean var4)
|
||||||
|
{
|
||||||
|
return isEnabled()
|
||||||
|
&& state.getValue(BaseCoralPlantTypeBlock.WATERLOGGED)
|
||||||
|
&& world.getFluidState(pos.above()).is(FluidTags.WATER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public default boolean isBonemealSuccess(Level world, RandomSource random, BlockPos pos, BlockState state)
|
||||||
|
{
|
||||||
|
return random.nextFloat() < 0.15D;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public default void performBonemeal(ServerLevel worldIn, RandomSource random, BlockPos pos, BlockState blockUnder)
|
||||||
|
{
|
||||||
|
int variant = random.nextInt(3);
|
||||||
|
CoralFeature coral = switch (variant) {
|
||||||
|
case 0 -> new CoralClawFeature(NoneFeatureConfiguration.CODEC);
|
||||||
|
case 1 -> new CoralTreeFeature(NoneFeatureConfiguration.CODEC);
|
||||||
|
default -> new CoralMushroomFeature(NoneFeatureConfiguration.CODEC);
|
||||||
|
};
|
||||||
|
|
||||||
|
MaterialColor color = blockUnder.getMapColor(worldIn, pos);
|
||||||
|
BlockState properBlock = blockUnder;
|
||||||
|
HolderSet.Named<Block> coralBlocks = worldIn.registryAccess().registryOrThrow(Registries.BLOCK).getTag(BlockTags.CORAL_BLOCKS).orElseThrow();
|
||||||
|
for (Holder<Block> block: coralBlocks)
|
||||||
|
{
|
||||||
|
properBlock = block.value().defaultBlockState();
|
||||||
|
if (properBlock.getMapColor(worldIn, pos) == color)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
worldIn.setBlock(pos, Blocks.WATER.defaultBlockState(), Block.UPDATE_NONE);
|
||||||
|
|
||||||
|
if (!((CoralFeatureInterface)coral).growSpecific(worldIn, random, pos, properBlock))
|
||||||
|
{
|
||||||
|
worldIn.setBlock(pos, blockUnder, 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (worldIn.random.nextInt(10) == 0)
|
||||||
|
{
|
||||||
|
BlockPos randomPos = pos.offset(worldIn.random.nextInt(16) - 8, worldIn.random.nextInt(8), worldIn.random.nextInt(16) - 8);
|
||||||
|
if (coralBlocks.contains(worldIn.getBlockState(randomPos).getBlockHolder()))
|
||||||
|
{
|
||||||
|
worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), Block.UPDATE_ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,88 +1,16 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.fakes.CoralFeatureInterface;
|
import carpet.helpers.FertilizableCoral;
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Holder;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.tags.BlockTags;
|
|
||||||
import net.minecraft.tags.FluidTags;
|
|
||||||
import net.minecraft.util.RandomSource;
|
|
||||||
import net.minecraft.world.level.BlockGetter;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
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.BonemealableBlock;
|
|
||||||
import net.minecraft.world.level.block.CoralFanBlock;
|
import net.minecraft.world.level.block.CoralFanBlock;
|
||||||
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.MaterialColor;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Mixin(CoralFanBlock.class)
|
@Mixin(CoralFanBlock.class)
|
||||||
public abstract class CoralFanBlock_renewableCoralMixin implements BonemealableBlock
|
public class CoralFanBlock_renewableCoralMixin implements FertilizableCoral
|
||||||
{
|
{
|
||||||
public boolean isValidBonemealTarget(BlockGetter var1, BlockPos var2, BlockState var3, boolean var4)
|
@Override
|
||||||
{
|
public boolean isEnabled() {
|
||||||
return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED
|
return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED;
|
||||||
&& var3.getValue(BaseCoralPlantTypeBlock.WATERLOGGED)
|
|
||||||
&& var1.getFluidState(var2.above()).is(FluidTags.WATER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBonemealSuccess(Level var1, RandomSource var2, BlockPos var3, BlockState var4)
|
|
||||||
{
|
|
||||||
return (double)var1.random.nextFloat() < 0.15D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void performBonemeal(ServerLevel worldIn, RandomSource random, BlockPos pos, BlockState blockUnder)
|
|
||||||
{
|
|
||||||
|
|
||||||
CoralFeature coral;
|
|
||||||
int variant = random.nextInt(3);
|
|
||||||
if (variant == 0)
|
|
||||||
coral = new CoralClawFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
else if (variant == 1)
|
|
||||||
coral = new CoralTreeFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
else
|
|
||||||
coral = new CoralMushroomFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
|
|
||||||
MaterialColor color = blockUnder.getMapColor(worldIn, pos);
|
|
||||||
BlockState proper_block = blockUnder;
|
|
||||||
Set<Block> coralBlockSet = worldIn.registryAccess().registryOrThrow(Registries.BLOCK).getTag(BlockTags.CORAL_BLOCKS).orElseThrow().stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
|
|
||||||
for (Block block: coralBlockSet)
|
|
||||||
{
|
|
||||||
proper_block = block.defaultBlockState();
|
|
||||||
if (proper_block.getMapColor(worldIn,pos) == color)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
worldIn.setBlock(pos, Blocks.WATER.defaultBlockState(), 4);
|
|
||||||
|
|
||||||
if (!((CoralFeatureInterface)coral).growSpecific(worldIn, random, pos, proper_block))
|
|
||||||
{
|
|
||||||
worldIn.setBlock(pos, blockUnder, 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (worldIn.random.nextInt(10)==0)
|
|
||||||
{
|
|
||||||
BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 );
|
|
||||||
if (coralBlockSet.contains(worldIn.getBlockState(randomPos).getBlock()))
|
|
||||||
{
|
|
||||||
worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Logic in FertilizableCoral
|
||||||
}
|
}
|
||||||
@@ -1,90 +1,18 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.fakes.CoralFeatureInterface;
|
import carpet.helpers.FertilizableCoral;
|
||||||
import net.minecraft.core.Holder;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
|
||||||
import net.minecraft.util.RandomSource;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.tags.BlockTags;
|
|
||||||
import net.minecraft.tags.FluidTags;
|
|
||||||
import net.minecraft.world.level.BlockGetter;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
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.BonemealableBlock;
|
|
||||||
import net.minecraft.world.level.block.CoralPlantBlock;
|
import net.minecraft.world.level.block.CoralPlantBlock;
|
||||||
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.MaterialColor;
|
|
||||||
|
|
||||||
@Mixin(CoralPlantBlock.class)
|
@Mixin(CoralPlantBlock.class)
|
||||||
public abstract class CoralPlantBlock_renewableCoralMixin implements BonemealableBlock
|
public class CoralPlantBlock_renewableCoralMixin implements FertilizableCoral
|
||||||
{
|
{
|
||||||
public boolean isValidBonemealTarget(BlockGetter var1, BlockPos var2, BlockState var3, boolean var4)
|
@Override
|
||||||
{
|
public boolean isEnabled() {
|
||||||
return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED
|
return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED
|
||||||
|| CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.TRUE
|
|| CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.TRUE;
|
||||||
&& var3.getValue(BaseCoralPlantTypeBlock.WATERLOGGED)
|
|
||||||
&& var1.getFluidState(var2.above()).is(FluidTags.WATER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBonemealSuccess(Level var1, RandomSource var2, BlockPos var3, BlockState var4)
|
|
||||||
{
|
|
||||||
return (double)var1.random.nextFloat() < 0.15D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void performBonemeal(ServerLevel worldIn, RandomSource random, BlockPos pos, BlockState blockUnder)
|
|
||||||
{
|
|
||||||
|
|
||||||
CoralFeature coral;
|
|
||||||
int variant = random.nextInt(3);
|
|
||||||
if (variant == 0)
|
|
||||||
coral = new CoralClawFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
else if (variant == 1)
|
|
||||||
coral = new CoralTreeFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
else
|
|
||||||
coral = new CoralMushroomFeature(NoneFeatureConfiguration.CODEC);
|
|
||||||
|
|
||||||
MaterialColor color = blockUnder.getMapColor(worldIn, pos);
|
|
||||||
BlockState proper_block = blockUnder;
|
|
||||||
Set<Block> coralBlockSet = worldIn.registryAccess().registryOrThrow(Registries.BLOCK).getTag(BlockTags.CORAL_BLOCKS).orElseThrow().stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
|
|
||||||
for (Block block: coralBlockSet)
|
|
||||||
{
|
|
||||||
proper_block = block.defaultBlockState();
|
|
||||||
if (proper_block.getMapColor(worldIn,pos) == color)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
worldIn.setBlock(pos, Blocks.WATER.defaultBlockState(), 4);
|
|
||||||
|
|
||||||
if (!((CoralFeatureInterface)coral).growSpecific(worldIn, random, pos, proper_block))
|
|
||||||
{
|
|
||||||
worldIn.setBlock(pos, blockUnder, 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (worldIn.random.nextInt(10)==0)
|
|
||||||
{
|
|
||||||
BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 );
|
|
||||||
if (coralBlockSet.contains(worldIn.getBlockState(randomPos).getBlock()))
|
|
||||||
{
|
|
||||||
worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Logic in FertilizableCoral
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user