[Feature] Renewable smaragdant
Merge pull request #97 from Necrontyrr/budding-smaragdant
This commit is contained in:
commit
503c55549d
10 changed files with 115 additions and 4 deletions
|
@ -0,0 +1,66 @@
|
|||
package org.betterx.betterend.blocks;
|
||||
|
||||
import org.betterx.bclib.interfaces.tools.AddMineablePickaxe;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
import org.betterx.betterend.blocks.basis.LitPillarBlock;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BuddingSmaragdantCrystalBlock extends LitPillarBlock implements AddMineablePickaxe {
|
||||
public BuddingSmaragdantCrystalBlock() {
|
||||
super(FabricBlockSettings.of(Material.GLASS)
|
||||
.luminance(15)
|
||||
.hardness(1F)
|
||||
.resistance(1F)
|
||||
.noOcclusion()
|
||||
.sound(SoundType.AMETHYST)
|
||||
.randomTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushReaction getPistonPushReaction(BlockState blockState) {
|
||||
return PushReaction.DESTROY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void randomTick(BlockState blockState, ServerLevel world, BlockPos pos, RandomSource random) {
|
||||
Direction dir = BlocksHelper.randomDirection(random);
|
||||
BlockPos side = pos.relative(dir);
|
||||
BlockState sideState = world.getBlockState(side);
|
||||
if (random.nextInt(20) == 0) {
|
||||
if (canShardGrowAtState(sideState)) {
|
||||
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.defaultBlockState()
|
||||
.setValue(SmaragdantCrystalShardBlock.WATERLOGGED, sideState.getFluidState().getType() == Fluids.WATER)
|
||||
.setValue(SmaragdantCrystalShardBlock.FACING, dir);
|
||||
world.setBlockAndUpdate(side, shard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canShardGrowAtState(BlockState blockState) {
|
||||
return blockState.isAir() || blockState.is(Blocks.WATER) && blockState.getFluidState().getAmount() == 8;
|
||||
}
|
||||
}
|
|
@ -489,6 +489,12 @@ public class CraftingRecipes {
|
|||
.setOutputCount(4)
|
||||
.addMaterial('#', EndBlocks.DRAGON_BONE_BLOCK)
|
||||
.build();
|
||||
|
||||
BCLRecipeBuilder.crafting(BetterEnd.makeID("smaragdant_crystal"), EndBlocks.SMARAGDANT_CRYSTAL)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.setShape("##", "##")
|
||||
.addMaterial('#', EndBlocks.SMARAGDANT_CRYSTAL_SHARD)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void registerLantern(String name, Block lantern, Block slab) {
|
||||
|
|
|
@ -638,6 +638,7 @@ public class EndBlocks {
|
|||
"smaragdant_crystal",
|
||||
SMARAGDANT_CRYSTAL
|
||||
);
|
||||
public static final Block BUDDING_SMARAGDANT_CRYSTAL = registerBlock("budding_smaragdant_crystal", new BuddingSmaragdantCrystalBlock());
|
||||
|
||||
public static final Block RESPAWN_OBELISK = registerBlock("respawn_obelisk", new RespawnObeliskBlock());
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.betterx.betterend.world.features.terrain;
|
|||
import org.betterx.bclib.api.v2.levelgen.features.features.DefaultFeature;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
import org.betterx.bclib.util.MHelper;
|
||||
import org.betterx.betterend.blocks.BuddingSmaragdantCrystalBlock;
|
||||
import org.betterx.betterend.blocks.SmaragdantCrystalShardBlock;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
import org.betterx.worlds.together.tag.v3.CommonBlockTags;
|
||||
|
||||
|
@ -14,6 +16,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
|
||||
public class SmaragdantCrystalFeature extends DefaultFeature {
|
||||
@Override
|
||||
|
@ -29,6 +33,7 @@ public class SmaragdantCrystalFeature extends DefaultFeature {
|
|||
int count = MHelper.randRange(15, 30, random);
|
||||
BlockState crystal = EndBlocks.SMARAGDANT_CRYSTAL.defaultBlockState();
|
||||
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.defaultBlockState();
|
||||
BlockState buddingCrystal = EndBlocks.BUDDING_SMARAGDANT_CRYSTAL.defaultBlockState();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mut.set(pos)
|
||||
.move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, MHelper.floor(random.nextGaussian() * 2 + 0.5));
|
||||
|
@ -42,10 +47,26 @@ public class SmaragdantCrystalFeature extends DefaultFeature {
|
|||
mut.setY(mut.getY() - 1);
|
||||
state = world.getBlockState(mut);
|
||||
}
|
||||
if (state.is(CommonBlockTags.GEN_END_STONES) && !world.getBlockState(mut.above())
|
||||
.is(crystal.getBlock())) {
|
||||
if (state.is(CommonBlockTags.GEN_END_STONES) && world.getBlockState(mut.above()).isAir()) {
|
||||
for (int j = 0; j <= dist; j++) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, crystal);
|
||||
if (random.nextInt(8) == 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, buddingCrystal);
|
||||
for (Direction k : BlocksHelper.HORIZONTAL) {
|
||||
BlockPos sidePos = mut.relative(k);
|
||||
BlockState sideState = world.getBlockState(sidePos);
|
||||
if (BuddingSmaragdantCrystalBlock.canShardGrowAtState(sideState)) {
|
||||
if (random.nextBoolean()) {
|
||||
BlockState attachedShard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.defaultBlockState()
|
||||
.setValue(SmaragdantCrystalShardBlock.WATERLOGGED,
|
||||
sideState.getFluidState().getType() == Fluids.WATER)
|
||||
.setValue(SmaragdantCrystalShardBlock.FACING, k);
|
||||
BlocksHelper.setWithoutUpdate(world, sidePos, attachedShard);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, crystal);
|
||||
}
|
||||
mut.setY(mut.getY() + 1);
|
||||
}
|
||||
boolean waterlogged = !world.getFluidState(mut).isEmpty();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue