2
2
3
3
import ace .actually .pirates .util .PatternProcessor ;
4
4
import ace .actually .pirates .Pirates ;
5
+ import net .minecraft .block .Block ;
5
6
import net .minecraft .block .BlockState ;
6
7
import net .minecraft .block .Blocks ;
7
8
import net .minecraft .block .entity .BlockEntity ;
8
9
import net .minecraft .nbt .NbtCompound ;
9
10
import net .minecraft .nbt .NbtList ;
10
- import net .minecraft .registry .tag .BlockTags ;
11
11
import net .minecraft .server .world .ServerWorld ;
12
12
import net .minecraft .util .math .BlockPos ;
13
13
import net .minecraft .util .math .ChunkPos ;
14
14
import net .minecraft .world .World ;
15
15
import org .valkyrienskies .core .api .ships .LoadedServerShip ;
16
+ import org .valkyrienskies .core .util .datastructures .DenseBlockPosSet ;
16
17
import org .valkyrienskies .eureka .block .ShipHelmBlock ;
17
- import org .valkyrienskies .eureka .util .ShipAssembler ;
18
18
import org .valkyrienskies .mod .api .SeatedControllingPlayer ;
19
19
import org .valkyrienskies .mod .common .VSGameUtilsKt ;
20
20
import org .valkyrienskies .mod .common .ValkyrienSkiesMod ;
21
+ import org .valkyrienskies .mod .common .assembly .ShipAssemblyKt ;
21
22
import org .valkyrienskies .mod .common .util .DimensionIdProvider ;
22
23
24
+ import java .util .List ;
25
+
23
26
import static net .minecraft .state .property .Properties .HORIZONTAL_FACING ;
24
27
25
28
public class MotionInvokingBlockEntity extends BlockEntity {
@@ -38,7 +41,16 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
38
41
}
39
42
40
43
if (be .instructions .isEmpty () && world .getGameRules ().getBoolean (Pirates .PIRATES_IS_LIVE_WORLD )) {
41
- be .getPattern ("circle.pattern" );
44
+
45
+ if (world .random .nextBoolean ())
46
+ {
47
+ be .setPattern ("circle.pattern" );
48
+ }
49
+ else
50
+ {
51
+ be .setPattern ("rcircle.pattern" );
52
+ }
53
+
42
54
}
43
55
if (!world .isClient && world .getGameRules ().getBoolean (Pirates .PIRATES_IS_LIVE_WORLD ) && world .getTime () >= be .nextInstruction ) {
44
56
DimensionIdProvider provider = (DimensionIdProvider ) world ;
@@ -76,7 +88,8 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
76
88
}
77
89
78
90
private void buildShipRec (ServerWorld world , BlockPos pos ) {
79
- ShipAssembler .INSTANCE .collectBlocks (world , pos , a -> !a .isAir () && !a .isOf (Blocks .WATER ) && !a .isOf (Blocks .KELP ) && !a .isOf (Blocks .KELP_PLANT ) && !a .isOf (Blocks .SAND ) && !a .isIn (BlockTags .ICE ) && !a .isOf (Blocks .STONE ));
91
+ //ShipAssembler.INSTANCE.collectBlocks(world, pos, a -> !a.isAir() && !a.isOf(Blocks.WATER) && !a.isOf(Blocks.KELP) && !a.isOf(Blocks.KELP_PLANT) && !a.isOf(Blocks.SAND) && !a.isIn(BlockTags.ICE) && !a.isOf(Blocks.STONE));
92
+ collectBlocks (world ,pos );
80
93
}
81
94
82
95
@ Override
@@ -94,7 +107,7 @@ public void readNbt(NbtCompound nbt) {
94
107
}
95
108
96
109
97
- public void getPattern (String loc ) {
110
+ public void setPattern (String loc ) {
98
111
instructions = PatternProcessor .loadPattern (loc );
99
112
nextInstruction = world .getTime () + 10 ;
100
113
markDirty ();
@@ -115,4 +128,44 @@ private void utiliseInternalPattern(SeatedControllingPlayer seatedControllingPla
115
128
be .instructions .add (be .instructions .remove (0 ));
116
129
be .markDirty ();
117
130
}
131
+
132
+ public void collectBlocks (ServerWorld world , BlockPos center )
133
+ {
134
+ sortDense (world ,center );
135
+ if (SET .size ()<5000 )
136
+ {
137
+ ShipAssemblyKt .createNewShipWithBlocks (center , SET , world );
138
+ }
139
+ }
140
+
141
+ private static final List <Block > a = List .of (Blocks .SAND ,Blocks .STONE ,Blocks .ICE ,Blocks .PACKED_ICE ,Blocks .BLUE_ICE ,Blocks .KELP ,Blocks .KELP_PLANT ,Blocks .AIR ,Blocks .WATER );
142
+ private static final DenseBlockPosSet SET = new DenseBlockPosSet ();
143
+
144
+ public void sortDense (ServerWorld world , BlockPos here )
145
+ {
146
+ for (int i = -2 ; i < 3 ; i ++) {
147
+ for (int j = -2 ; j < 3 ; j ++) {
148
+ for (int k = -2 ; k < 3 ; k ++) {
149
+ //this means that we could hit 5000 in this loop, this is considered a false-start
150
+ if (SET .getSize ()<5000 )
151
+ {
152
+ BlockPos o = here .add (i ,j ,k );
153
+ if (!SET .contains (o .getX (),o .getY (),o .getZ ()))
154
+ {
155
+ if (!a .contains (world .getBlockState (o ).getBlock ()))
156
+ {
157
+ SET .add (o .getX (),o .getY (),o .getZ ());
158
+ //System.out.println(SET.size());
159
+ sortDense (world ,o );
160
+ }
161
+
162
+ }
163
+ }
164
+
165
+ }
166
+ }
167
+ }
168
+
169
+ }
170
+
118
171
}
0 commit comments