Skip to content

Commit 12f25ab

Browse files
committed
Reverse circles and a more "dynamic" ship builder
1 parent 7062580 commit 12f25ab

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
lines changed

src/main/java/ace/actually/pirates/blocks/MotionInvokingBlock.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ private static void stopMotion(World world, BlockPos pos)
7272
DimensionIdProvider provider = (DimensionIdProvider) world;
7373
ChunkPos chunkPos = world.getChunk(pos).getPos();
7474
LoadedServerShip ship = (LoadedServerShip) ValkyrienSkiesMod.getVsCore().getHooks().getCurrentShipServerWorld().getLoadedShips().getByChunkPos(chunkPos.x, chunkPos.z, provider.getDimensionId());
75-
SeatedControllingPlayer seatedControllingPlayer = ship.getAttachment(SeatedControllingPlayer.class);
76-
seatedControllingPlayer.setLeftImpulse(0);
77-
seatedControllingPlayer.setForwardImpulse(0);
78-
seatedControllingPlayer.setCruise(false);
79-
seatedControllingPlayer.setUpImpulse(0);
80-
ship.setAttachment(SeatedControllingPlayer.class, seatedControllingPlayer);
75+
if(ship!=null)
76+
{
77+
SeatedControllingPlayer seatedControllingPlayer = ship.getAttachment(SeatedControllingPlayer.class);
78+
seatedControllingPlayer.setLeftImpulse(0);
79+
seatedControllingPlayer.setForwardImpulse(0);
80+
seatedControllingPlayer.setCruise(false);
81+
seatedControllingPlayer.setUpImpulse(0);
82+
ship.setAttachment(SeatedControllingPlayer.class, seatedControllingPlayer);
83+
}
84+
8185
}
8286
}

src/main/java/ace/actually/pirates/blocks/entity/MotionInvokingBlockEntity.java

+58-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22

33
import ace.actually.pirates.util.PatternProcessor;
44
import ace.actually.pirates.Pirates;
5+
import net.minecraft.block.Block;
56
import net.minecraft.block.BlockState;
67
import net.minecraft.block.Blocks;
78
import net.minecraft.block.entity.BlockEntity;
89
import net.minecraft.nbt.NbtCompound;
910
import net.minecraft.nbt.NbtList;
10-
import net.minecraft.registry.tag.BlockTags;
1111
import net.minecraft.server.world.ServerWorld;
1212
import net.minecraft.util.math.BlockPos;
1313
import net.minecraft.util.math.ChunkPos;
1414
import net.minecraft.world.World;
1515
import org.valkyrienskies.core.api.ships.LoadedServerShip;
16+
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet;
1617
import org.valkyrienskies.eureka.block.ShipHelmBlock;
17-
import org.valkyrienskies.eureka.util.ShipAssembler;
1818
import org.valkyrienskies.mod.api.SeatedControllingPlayer;
1919
import org.valkyrienskies.mod.common.VSGameUtilsKt;
2020
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;
21+
import org.valkyrienskies.mod.common.assembly.ShipAssemblyKt;
2122
import org.valkyrienskies.mod.common.util.DimensionIdProvider;
2223

24+
import java.util.List;
25+
2326
import static net.minecraft.state.property.Properties.HORIZONTAL_FACING;
2427

2528
public class MotionInvokingBlockEntity extends BlockEntity {
@@ -38,7 +41,16 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
3841
}
3942

4043
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+
4254
}
4355
if (!world.isClient && world.getGameRules().getBoolean(Pirates.PIRATES_IS_LIVE_WORLD) && world.getTime() >= be.nextInstruction) {
4456
DimensionIdProvider provider = (DimensionIdProvider) world;
@@ -76,7 +88,8 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
7688
}
7789

7890
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);
8093
}
8194

8295
@Override
@@ -94,7 +107,7 @@ public void readNbt(NbtCompound nbt) {
94107
}
95108

96109

97-
public void getPattern(String loc) {
110+
public void setPattern(String loc) {
98111
instructions = PatternProcessor.loadPattern(loc);
99112
nextInstruction = world.getTime() + 10;
100113
markDirty();
@@ -115,4 +128,44 @@ private void utiliseInternalPattern(SeatedControllingPlayer seatedControllingPla
115128
be.instructions.add(be.instructions.remove(0));
116129
be.markDirty();
117130
}
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+
118171
}

src/main/java/ace/actually/pirates/util/PatternProcessor.java

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public static void setupBasicPatterns()
4848
throw new RuntimeException(e);
4949
}
5050
}
51+
file = new File(FabricLoader.getInstance().getConfigDirectory().getPath() + "/pirates/patterns/rcircle.pattern");
52+
if(!file.exists())
53+
{
54+
try {
55+
FileUtils.writeLines(file, Arrays.asList("forward 1 1","left 0.05 10"));
56+
} catch (IOException e) {
57+
throw new RuntimeException(e);
58+
}
59+
}
5160
}
5261

5362
}

0 commit comments

Comments
 (0)