[Feature] Renewable smaragdant

This commit is contained in:
Necrontyr 2022-10-14 22:55:12 +02:00
parent ac96841372
commit 6221600775
8 changed files with 107 additions and 3 deletions

View file

@ -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(5) == 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;
}
}

View file

@ -571,6 +571,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());

View file

@ -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(5) == 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();

View file

@ -670,6 +670,7 @@
"block.betterend.sandy_jadestone_tiles": "Sandy Jadestone Tiles",
"block.betterend.sandy_jadestone_wall": "Sandy Jadestone Wall",
"block.betterend.smaragdant_crystal": "Smaragdant Crystal",
"block.betterend.budding_smaragdant_crystal": "Budding Smaragdant Crystal",
"block.betterend.smaragdant_crystal_shard": "Smaragdant Crystal Shard",
"block.betterend.virid_jadestone": "Virid Jadestone",
"block.betterend.virid_jadestone_bricks": "Virid Jadestone Bricks",

View file

@ -0,0 +1,12 @@
{
"parent": "block/cube",
"textures": {
"down": "betterend:block/budding_smaragdant_crystal_top",
"east": "betterend:block/budding_smaragdant_crystal_side",
"north": "betterend:block/budding_smaragdant_crystal_side",
"particle": "betterend:block/budding_smaragdant_crystal_side",
"south": "betterend:block/budding_smaragdant_crystal_side",
"up": "betterend:block/budding_smaragdant_crystal_top",
"west": "betterend:block/budding_smaragdant_crystal_side"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "betterend:block/budding_smaragdant_crystal"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B