Hydralux blocks
This commit is contained in:
parent
fa3f8afed4
commit
2a0c3ee1e0
17 changed files with 668 additions and 0 deletions
41
src/main/java/ru/betterend/blocks/BlockHydralux.java
Normal file
41
src/main/java/ru/betterend/blocks/BlockHydralux.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.blocks.BlockProperties.HydraluxShape;
|
||||
import ru.betterend.blocks.basis.BlockUnderwaterPlant;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class BlockHydralux extends BlockUnderwaterPlant {
|
||||
public static final EnumProperty<HydraluxShape> SHAPE = BlockProperties.HYDRALUX_SHAPE;
|
||||
|
||||
public BlockHydralux() {
|
||||
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.WET_GRASS)
|
||||
.breakByHand(true)
|
||||
.luminance((state) -> { return state.get(SHAPE).hasGlow() ? 15 : 0; })
|
||||
.noCollision());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.down());
|
||||
HydraluxShape shape = state.get(SHAPE);
|
||||
if (shape == HydraluxShape.FLOWER_BIG_TOP || shape == HydraluxShape.FLOWER_SMALL_TOP) {
|
||||
return down.isOf(this);
|
||||
}
|
||||
else if (shape == HydraluxShape.ROOTS) {
|
||||
return down.isOf(EndBlocks.SULPHURIC_ROCK.stone) && world.getBlockState(pos.up()).isOf(this);
|
||||
}
|
||||
else {
|
||||
return down.isOf(this) && world.getBlockState(pos.up()).isOf(this);
|
||||
}
|
||||
}
|
||||
}
|
44
src/main/java/ru/betterend/blocks/BlockHydraluxSpore.java
Normal file
44
src/main/java/ru/betterend/blocks/BlockHydraluxSpore.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.HydraluxShape;
|
||||
import ru.betterend.blocks.basis.BlockUnderwaterPlantWithAge;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockHydraluxSpore extends BlockUnderwaterPlantWithAge {
|
||||
@Override
|
||||
public void grow(StructureWorldAccess world, Random random, BlockPos pos) {
|
||||
int h = MHelper.randRange(4, 8, random);
|
||||
Mutable mut = new Mutable().set(pos);
|
||||
|
||||
for (int i = 1; i < h; i++) {
|
||||
mut.setY(pos.getY() + i);
|
||||
if (!world.getBlockState(mut).isOf(Blocks.WATER)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mut.setY(pos.getY());
|
||||
BlockState state = EndBlocks.HYDRALUX.getDefaultState();
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state.with(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.ROOTS));
|
||||
for (int i = 1; i < h - 2; i++) {
|
||||
mut.setY(pos.getY() + i);
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state.with(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.VINE));
|
||||
}
|
||||
|
||||
mut.setY(mut.getY() + 1);
|
||||
boolean big = random.nextBoolean();
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state.with(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_BOTTOM : HydraluxShape.FLOWER_SMALL_BOTTOM));
|
||||
|
||||
mut.setY(mut.getY() + 1);
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state.with(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_TOP : HydraluxShape.FLOWER_SMALL_TOP));
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import net.minecraft.util.StringIdentifiable;
|
|||
public class BlockProperties {
|
||||
public static final EnumProperty<TripleShape> TRIPLE_SHAPE = EnumProperty.of("shape", TripleShape.class);
|
||||
public final static EnumProperty<PedestalState> PEDESTAL_STATE = EnumProperty.of("state", PedestalState.class);
|
||||
public static final EnumProperty<HydraluxShape> HYDRALUX_SHAPE = EnumProperty.of("shape", HydraluxShape.class);
|
||||
public static final BooleanProperty HAS_ITEM = BooleanProperty.of("has_item");
|
||||
public static final BooleanProperty HAS_LIGHT = BooleanProperty.of("has_light");
|
||||
public static final BooleanProperty ACTIVATED = BooleanProperty.of("active");
|
||||
|
@ -57,4 +58,35 @@ public class BlockProperties {
|
|||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum HydraluxShape implements StringIdentifiable {
|
||||
FLOWER_BIG_BOTTOM("flower_big_bottom", true),
|
||||
FLOWER_BIG_TOP("flower_big_top", true),
|
||||
FLOWER_SMALL_BOTTOM("flower_small_bottom", true),
|
||||
FLOWER_SMALL_TOP("flower_small_top", true),
|
||||
VINE("vine", false),
|
||||
ROOTS("roots", false);
|
||||
|
||||
private final String name;
|
||||
private final boolean glow;
|
||||
|
||||
HydraluxShape(String name, boolean glow) {
|
||||
this.name = name;
|
||||
this.glow = glow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean hasGlow() {
|
||||
return glow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue