Skip to content

Commit

Permalink
blooming stem now has unique functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Oct 31, 2023
1 parent a0a352a commit 202cccd
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 1.20.1 2023-10-29T14:19:37.0146147 Block States: deeperdarker
// 1.20.1 2023-10-29T21:56:08.2776156 Block States: deeperdarker
4394f02c270408be611b2f3ba7abfbfd658cb0ff assets/deeperdarker/blockstates/ancient_vase.json
6a6092533dcd9d5b6932f99f5be6dc85b429f41b assets/deeperdarker/blockstates/blooming_flowers.json
165980177c5adcf470b9a08fe401e3bb1a4966f0 assets/deeperdarker/blockstates/blooming_moss_block.json
498227afd0f8c9b0fa72dfef97bf22b886a9069f assets/deeperdarker/blockstates/blooming_sculk.json
57383ac6efb1e22c062918a53dec426e8966f718 assets/deeperdarker/blockstates/blooming_stem.json
a9636c05e9a8e2c7566c106f3dbbbd86c8097a4e assets/deeperdarker/blockstates/blooming_stem.json
b618639a1bd650f5bbceed1f24a777ca15ae37fe assets/deeperdarker/blockstates/chiseled_gloomslate.json
389153807c5651eba34cf020ac7d3b675b0418a2 assets/deeperdarker/blockstates/chiseled_sculk_stone.json
68002cff985c9e3e803a31cbe314c4e4d6ac9e36 assets/deeperdarker/blockstates/cobbled_gloomslate.json
Expand Down Expand Up @@ -122,6 +122,8 @@ b3e7881ec9d01d89952b70be65946eea0305c45f assets/deeperdarker/models/block/bloomi
5f6d78b44fd7067c2670c9e989ce03e4e9aac70f assets/deeperdarker/models/block/blooming_moss_block.json
446377a22c7cd0fa8486a0da7afe4adf393c90e2 assets/deeperdarker/models/block/blooming_sculk.json
0c90c3f2270980d69f3a46e4826ab53ce84ec3f4 assets/deeperdarker/models/block/blooming_stem.json
6fae9a607b167f9c128d9fe1584b440069918f0e assets/deeperdarker/models/block/blooming_stem_horizontal.json
44cf74d85128376b4eac3aa6d1e8511756ab23f3 assets/deeperdarker/models/block/blooming_stem_vertical.json
b00bfe63a4595969e6f0a510761702536bf5c367 assets/deeperdarker/models/block/chiseled_gloomslate.json
72cffa498213da488cf3a2f3f60488de0a5fab6a assets/deeperdarker/models/block/chiseled_sculk_stone.json
95d18c450b387ca11be36213e2be0e675b3a7440 assets/deeperdarker/models/block/cobbled_gloomslate.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,67 @@
{
"variants": {
"axis=x": {
"model": "deeperdarker:block/blooming_stem",
"x": 90,
"y": 90
"multipart": [
{
"apply": {
"model": "deeperdarker:block/blooming_stem"
}
},
"axis=y": {
"model": "deeperdarker:block/blooming_stem"
{
"apply": {
"model": "deeperdarker:block/blooming_stem_vertical",
"uvlock": true,
"x": 180
},
"when": {
"down": "true"
}
},
"axis=z": {
"model": "deeperdarker:block/blooming_stem",
"x": 90
{
"apply": {
"model": "deeperdarker:block/blooming_stem_vertical",
"uvlock": true
},
"when": {
"up": "true"
}
},
{
"apply": {
"model": "deeperdarker:block/blooming_stem_horizontal",
"uvlock": true,
"y": 90
},
"when": {
"north": "true"
}
},
{
"apply": {
"model": "deeperdarker:block/blooming_stem_horizontal",
"uvlock": true,
"y": 270
},
"when": {
"south": "true"
}
},
{
"apply": {
"model": "deeperdarker:block/blooming_stem_horizontal",
"uvlock": true
},
"when": {
"west": "true"
}
},
{
"apply": {
"model": "deeperdarker:block/blooming_stem_horizontal",
"uvlock": true,
"y": 180
},
"when": {
"east": "true"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "deeperdarker:block/stem_horizontal",
"textures": {
"stem": "deeperdarker:block/blooming_stem"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "deeperdarker:block/stem_vertical",
"textures": {
"stem": "deeperdarker:block/blooming_stem"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
});
public static final RegistryObject<Block> POTTED_ECHO_SAPLING = BLOCKS.register("potted_echo_sapling", () -> new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, ECHO_SAPLING, BlockBehaviour.Properties.copy(Blocks.POTTED_OAK_SAPLING)));

public static final RegistryObject<RotatedPillarBlock> BLOOMING_STEM = register("blooming_stem", () -> new BloomingStemBlock(BlockBehaviour.Properties.copy(Blocks.OAK_LOG).noOcclusion(), 2, 4));
public static final RegistryObject<Block> BLOOMING_STEM = register("blooming_stem", () -> new BloomingStemBlock(BlockBehaviour.Properties.of().strength(1f).sound(SoundType.WOOD).ignitedByLava().noOcclusion()));

public static final RegistryObject<Block> SCULK_STONE = register("sculk_stone", () -> new Block(BlockBehaviour.Properties.copy(Blocks.STONE).mapColor(MapColor.COLOR_CYAN).sound(DDSounds.SCULK_STONE).requiresCorrectToolForDrops()));
public static final RegistryObject<StairBlock> SCULK_STONE_STAIRS = register("sculk_stone_stairs", () -> new StairBlock(() -> SCULK_STONE.get().defaultBlockState(), BlockBehaviour.Properties.copy(SCULK_STONE.get())));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.kyanite.deeperdarker.content.blocks;

import com.kyanite.deeperdarker.content.DDBlocks;
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.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PipeBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

@SuppressWarnings("deprecation, NullableProblems")
public class BloomingStemBlock extends Block {
public static final BooleanProperty UP = BlockStateProperties.UP;
public static final BooleanProperty DOWN = BlockStateProperties.DOWN;
public static final BooleanProperty NORTH = BlockStateProperties.NORTH;
public static final BooleanProperty EAST = BlockStateProperties.EAST;
public static final BooleanProperty SOUTH = BlockStateProperties.SOUTH;
public static final BooleanProperty WEST = BlockStateProperties.WEST;
private static final VoxelShape[] shapes = {
Block.box(5, 5, 5, 11, 11, 11), // CUBE
Block.box(5, 11, 5, 11, 16, 11), // UP
Block.box(5, 0, 5, 11, 5, 11), // DOWN
Block.box(5, 5, 0, 11, 11, 5), // NORTH
Block.box(11, 5, 5, 16, 11, 11), // EAST
Block.box(5, 5, 11, 11, 11, 16), // SOUTH
Block.box(0, 5, 5, 5, 11, 11) // WEST
};

public BloomingStemBlock(Properties pProperties) {
super(pProperties);
this.registerDefaultState(this.stateDefinition.any().setValue(UP, false).setValue(DOWN, true).setValue(NORTH, false).setValue(EAST, false).setValue(SOUTH, false).setValue(WEST, false));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
BlockPos pos = pContext.getClickedPos();
BlockGetter level = pContext.getLevel();

BlockState aboveState = level.getBlockState(pos.above());
BlockState belowState = level.getBlockState(pos.below());
BlockState northState = level.getBlockState(pos.north());
BlockState eastState = level.getBlockState(pos.east());
BlockState southState = level.getBlockState(pos.south());
BlockState westState = level.getBlockState(pos.west());

if(belowState.is(this) || belowState.is(DDBlocks.BLOOMING_SCULK.get())) return this.defaultBlockState();
return this.defaultBlockState().setValue(UP, aboveState.is(this)).setValue(DOWN, belowState.is(this) || belowState.is(DDBlocks.BLOOMING_SCULK.get())).setValue(NORTH, northState.is(this)).setValue(EAST, eastState.is(this)).setValue(SOUTH, southState.is(this)).setValue(WEST, westState.is(this));
}

@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
VoxelShape shape = shapes[0];

if(pState.getValue(UP)) shape = Shapes.join(shape, shapes[1], BooleanOp.OR);
if(pState.getValue(DOWN)) shape = Shapes.join(shape, shapes[2], BooleanOp.OR);
if(pState.getValue(NORTH)) shape = Shapes.join(shape, shapes[3], BooleanOp.OR);
if(pState.getValue(EAST)) shape = Shapes.join(shape, shapes[4], BooleanOp.OR);
if(pState.getValue(SOUTH)) shape = Shapes.join(shape, shapes[5], BooleanOp.OR);
if(pState.getValue(WEST)) shape = Shapes.join(shape, shapes[6], BooleanOp.OR);

return shape;
}

@Override
public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState, LevelAccessor pLevel, BlockPos pPos, BlockPos pNeighborPos) {
if(!pState.canSurvive(pLevel, pPos)) {
pLevel.scheduleTick(pPos, this, 1);
return super.updateShape(pState, pDirection, pNeighborState, pLevel, pPos, pNeighborPos);
}

if(pDirection == Direction.DOWN && pNeighborState.is(DDBlocks.BLOOMING_SCULK.get())) return pState.setValue(DOWN, true);
if(pDirection.getAxis().isHorizontal() && !pLevel.getBlockState(pNeighborPos.below()).isAir()) return pState;
return pState.setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(pDirection), pNeighborState.is(this));
}

@Override
public void tick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) {
if(!pState.canSurvive(pLevel, pPos)) {
pLevel.destroyBlock(pPos, true);
}
}

@Override
public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos) {
BlockState below = pLevel.getBlockState(pPos.below());

if(below.is(this) || below.is(DDBlocks.BLOOMING_SCULK.get())) return true;


if(canSurvive(below)) return true;

for(Direction direction : Direction.Plane.HORIZONTAL) {
BlockPos pos = pPos.relative(direction);
BlockState state = pLevel.getBlockState(pos);
if(state.is(this) && canSurvive(pLevel.getBlockState(pos.below()))) return true;
}

return false;
}

private boolean canSurvive(BlockState state) {
return state.is(this) || state.is(DDBlocks.BLOOMING_SCULK.get());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.kyanite.deeperdarker.DeeperDarker;
import com.kyanite.deeperdarker.content.DDBlocks;
import com.kyanite.deeperdarker.content.blocks.SculkJawBlock;
import net.minecraft.core.Direction;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.*;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.RegistryObject;

Expand Down Expand Up @@ -38,7 +40,16 @@ protected void registerStatesAndModels() {
simpleBlock(DDBlocks.ECHO_WALL_HANGING_SIGN.get(), models().sign(DDBlocks.ECHO_HANGING_SIGN.getId().getPath(), blockLoc(DDBlocks.STRIPPED_ECHO_LOG)));
simpleBlock(DDBlocks.POTTED_ECHO_SAPLING.get(), models().withExistingParent(DDBlocks.POTTED_ECHO_SAPLING.getId().getPath(), mcLoc("flower_pot_cross")).texture("plant", blockLoc(DDBlocks.ECHO_SAPLING)).renderType("cutout"));

axisBlock(DDBlocks.BLOOMING_STEM.get(), models().withExistingParent(DDBlocks.BLOOMING_STEM.getId().getPath(), modLoc("stem")).texture("stem", blockLoc(DDBlocks.BLOOMING_STEM)), models().withExistingParent(DDBlocks.BLOOMING_STEM.getId().getPath(), modLoc("stem")).texture("stem", blockLoc(DDBlocks.BLOOMING_STEM)));
RegistryObject<Block> block = DDBlocks.BLOOMING_STEM;
ModelFile stem = models().withExistingParent(block.getId().getPath(), modLoc("stem")).texture("stem", blockLoc(block));
ModelFile horizontal = models().withExistingParent(block.getId().getPath() + "_horizontal", modLoc("stem_horizontal")).texture("stem", blockLoc(block));
ModelFile vertical = models().withExistingParent(block.getId().getPath() + "_vertical", modLoc("stem_vertical")).texture("stem", blockLoc(block));
MultiPartBlockStateBuilder builder = getMultipartBuilder(block.get()).part().modelFile(stem).addModel().end();
PipeBlock.PROPERTY_BY_DIRECTION.forEach((direction, value) -> {
if(direction.getAxis().isHorizontal()) builder.part().modelFile(horizontal).rotationY((((int) direction.toYRot()) + 270) % 360).uvLock(true).addModel().condition(value, true);
if(direction == Direction.UP) builder.part().modelFile(vertical).rotationX(0).uvLock(true).addModel().condition(value, true);
if(direction == Direction.DOWN) builder.part().modelFile(vertical).rotationX(180).uvLock(true).addModel().condition(value, true);
});

simpleBlock(DDBlocks.SCULK_STONE.get());
stairsBlock(DDBlocks.SCULK_STONE_STAIRS.get(), blockLoc(DDBlocks.SCULK_STONE));
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/assets/deeperdarker/models/block/stem.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
},
"elements": [
{
"from": [5, 0, 5],
"to": [11, 16, 11],
"from": [5, 5, 5],
"to": [11, 11, 11],
"faces": {
"north": {"uv": [0, 0, 6, 16], "texture": "#stem"},
"east": {"uv": [0, 0, 6, 16], "texture": "#stem"},
"south": {"uv": [0, 0, 6, 16], "texture": "#stem"},
"west": {"uv": [0, 0, 6, 16], "texture": "#stem"},
"up": {"uv": [6, 0, 12, 6], "texture": "#stem"},
"down": {"uv": [6, 6, 12, 12], "texture": "#stem"}
"north": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"east": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"south": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"west": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"up": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"down": {"uv": [5, 5, 11, 11], "texture": "#stem"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"textures": {
"particle": "#stem"
},
"elements": [
{
"from": [0, 5, 5],
"to": [5, 11, 11],
"faces": {
"north": {"uv": [11, 5, 16, 11], "texture": "#stem"},
"east": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"south": {"uv": [0, 5, 5, 11], "texture": "#stem"},
"west": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"up": {"uv": [0, 5, 5, 11], "texture": "#stem"},
"down": {"uv": [0, 5, 5, 11], "texture": "#stem"}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"textures": {
"particle": "#stem"
},
"elements": [
{
"from": [5, 11, 5],
"to": [11, 16, 11],
"faces": {
"north": {"uv": [5, 0, 11, 5], "texture": "#stem"},
"east": {"uv": [5, 0, 11, 5], "texture": "#stem"},
"south": {"uv": [5, 0, 11, 5], "texture": "#stem"},
"west": {"uv": [5, 0, 11, 5], "texture": "#stem"},
"up": {"uv": [5, 5, 11, 11], "texture": "#stem"},
"down": {"uv": [5, 5, 11, 11], "texture": "#stem"}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 202cccd

Please sign in to comment.