forked from ethanicusss/AstralAdditions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuneShroomBlock.java
More file actions
102 lines (89 loc) · 4.03 KB
/
LuneShroomBlock.java
File metadata and controls
102 lines (89 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.github.ethanicuss.astraladditions.blocks;
import com.github.ethanicuss.astraladditions.registry.ModBlocks;
import com.github.ethanicuss.astraladditions.registry.ModData;
import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import java.util.Random;
public class LuneShroomBlock extends Block {
protected static final VoxelShape OUTLINE_SHAPE = Block.createCuboidShape(4.0, 0.0, 4.0, 12.0, 4.0, 12.0);
protected static final VoxelShape NO_SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
public LuneShroomBlock(Settings settings) {
super(settings);
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int count = 1;
for(int i = 0; i < 7; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 7; k++){
BlockPos checkPos = new BlockPos(pos.getX() - 3 + i, pos.getY() - 1 + j, pos.getZ() - 3 + k);
if (world.getBlockState(checkPos).isOf(ModBlocks.LUNE_SHROOM_BLOCK)) {
count++;
}
}
}
}
if (count <= 4) {
BlockPos blockPos = new BlockPos(pos.getX() - 3 + (int)(random.nextFloat()*7), pos.getY(), pos.getZ() - 3 + (int)(random.nextFloat()*7));
if (canPlaceAt(this.getDefaultState(), world, blockPos)) {
world.setBlockState(blockPos, this.getDefaultState());
}
// Prioritizes spreading up over down when both are available. Uncomment the random check below to change to random chance
else if(/*random.nextFloat() >= 0.5 &&*/ canPlaceAt(this.getDefaultState(), world, blockPos.up())) {
world.setBlockState(blockPos.up(), this.getDefaultState());
}
else if(canPlaceAt(this.getDefaultState(), world, blockPos.down())) {
world.setBlockState(blockPos.down(), this.getDefaultState());
}
}
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
world.createAndScheduleBlockTick(pos, this, 1);
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
if (!world.getBlockState(pos).isAir() && !world.getBlockState(pos).isOf(ModBlocks.LUNE_SHROOM_BLOCK)){
return false;
}
BlockState blockState2 = world.getBlockState(pos.down());
return (blockState2.isIn(ModData.LUNE_SHROOM_GROWABLE));
}
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return NO_SHAPE;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return OUTLINE_SHAPE;
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.XYZ;
}
@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
}