Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@

public interface BasicBlockFinder extends Algorithm {

Ships5BlockFinder SHIPS_FIVE = new Ships5BlockFinder();
Ships5AsyncBlockFinder SHIPS_FIVE_ASYNC = new Ships5AsyncBlockFinder();
Ships6BlockFinder SHIPS_SIX = new Ships6BlockFinder();
Ships6MultiAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_MULTI_ASYNC = new Ships6MultiAsyncBlockFinder();
Ships6SingleAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_SINGLE_ASYNC = new Ships6SingleAsyncBlockFinder();
@Deprecated(forRemoval = true)
Ships5BlockFinder SHIPS_FIVE = BlockFinders.SHIPS_FIVE_SYNCED;

Check warning on line 16 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the missing @deprecated Javadoc tag.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6heo&open=AZ4xvECsG33uax-c6heo&pullRequest=109

Check warning on line 16 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6hen&open=AZ4xvECsG33uax-c6hen&pullRequest=109

@NotNull BasicBlockFinder init();
@Deprecated(forRemoval = true)
Ships5AsyncBlockFinder SHIPS_FIVE_ASYNC = BlockFinders.SHIPS_FIVE_ASYNCED;

Check warning on line 19 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the missing @deprecated Javadoc tag.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6heq&open=AZ4xvECsG33uax-c6heq&pullRequest=109

Check warning on line 19 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6hep&open=AZ4xvECsG33uax-c6hep&pullRequest=109

@Deprecated(forRemoval = true)
Ships6BlockFinder SHIPS_SIX = BlockFinders.SHIPS_SIX_RELEASE_TWO_SYNCED;

Check warning on line 22 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6her&open=AZ4xvECsG33uax-c6her&pullRequest=109

Check warning on line 22 in src/main/java/org/ships/algorthum/blockfinder/BasicBlockFinder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the missing @deprecated Javadoc tag.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvECsG33uax-c6hes&open=AZ4xvECsG33uax-c6hes&pullRequest=109

@Deprecated(forRemoval = true)
Ships6MultiAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_MULTI_ASYNC = BlockFinders.SHIPS_SIX_RELEASE_ONE_ASYNC_MULTI_THREADED;

@Deprecated(forRemoval = true)
Ships6SingleAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_SINGLE_ASYNC = BlockFinders.SHIPS_SIX_RELEASE_ONE_ASYNC_SINGLE_THREADED;

@NotNull
BasicBlockFinder init();

CompletableFuture<PositionableShipsStructure> getConnectedBlocksOvertime(@NotNull BlockPosition position,
@NotNull OvertimeBlockFinderUpdate runAfterFullSearch);

default CompletableFuture<PositionableShipsStructure> getConnectedBlocksOvertime(@NotNull BlockPosition position) {
return getConnectedBlocksOvertime(position,
(currentStructure, block) -> OvertimeBlockFinderUpdate.BlockFindControl.USE);
return this.getConnectedBlocksOvertime(position,
(currentStructure, block) -> OvertimeBlockFinderUpdate.BlockFindControl.USE);
}

int getBlockLimit();

@NotNull BasicBlockFinder setBlockLimit(int limit);
@NotNull
BasicBlockFinder setBlockLimit(int limit);

Optional<Vessel> getConnectedVessel();

@NotNull BasicBlockFinder setConnectedVessel(@Nullable Vessel vessel);
@NotNull
BasicBlockFinder setConnectedVessel(@Nullable Vessel vessel);

}
38 changes: 38 additions & 0 deletions src/main/java/org/ships/algorthum/blockfinder/BlockFinders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.ships.algorthum.blockfinder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.LinkedTransferQueue;

public final class BlockFinders {

private static final Collection<BasicBlockFinder> registered = new LinkedTransferQueue<>();

public static final Ships5BlockFinder SHIPS_FIVE_SYNCED = register(new Ships5BlockFinder());
public static final Ships5AsyncBlockFinder SHIPS_FIVE_ASYNCED = register(new Ships5AsyncBlockFinder());

public static final Ships6BlockFinder SHIPS_SIX_RELEASE_TWO_SYNCED = register(new Ships6BlockFinder());

public static final Ships6MultiAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_ASYNC_MULTI_THREADED = register(new Ships6MultiAsyncBlockFinder());

public static final Ships6SingleAsyncBlockFinder SHIPS_SIX_RELEASE_ONE_ASYNC_SINGLE_THREADED = register(new Ships6SingleAsyncBlockFinder());

private BlockFinders() {
throw new RuntimeException("Do not create");

Check warning on line 24 in src/main/java/org/ships/algorthum/blockfinder/BlockFinders.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=Minecraft-Ships_ShipsForCore&issues=AZ4xvD_UG33uax-c6hel&open=AZ4xvD_UG33uax-c6hel&pullRequest=109
}

public static <T extends BasicBlockFinder> T register(@NotNull T finder) {
registered.add(finder);
return finder;
}

@UnmodifiableView
public static Collection<BasicBlockFinder> getBlockFinders() {
return Collections.unmodifiableCollection(registered);
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ships.algorthum.blockfinder;

import org.core.vector.type.Vector3;
import org.core.world.position.impl.BlockPosition;
import org.jetbrains.annotations.NotNull;
import org.ships.vessel.common.types.Vessel;
Expand All @@ -16,7 +17,7 @@ public FindAirOvertimeBlockFinderUpdate(@NotNull Vessel vessel, @NotNull Overtim

@Override
public BlockFindControl onBlockFind(@NotNull PositionableShipsStructure currentStructure,
@NotNull BlockPosition block) {
@NotNull Vector3<Integer> block) {
return this.update.onBlockFind(currentStructure, block);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ships.algorthum.blockfinder;

import org.core.world.position.impl.BlockPosition;
import org.core.vector.type.Vector3;
import org.jetbrains.annotations.NotNull;
import org.ships.vessel.structure.PositionableShipsStructure;

Expand All @@ -14,6 +14,7 @@ enum BlockFindControl {

}

BlockFindControl onBlockFind(@NotNull PositionableShipsStructure currentStructure, @NotNull BlockPosition block);
BlockFindControl onBlockFind(@NotNull PositionableShipsStructure currentStructure,
@NotNull Vector3<Integer> blockPosition);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void getNextBlock(@Nullable OvertimeBlockFinderUpdate event,
OvertimeBlockFinderUpdate.BlockFindControl blockFind = null;
if (bi.getCollide() == CollideType.MATERIAL) {
if (event != null) {
blockFind = event.onBlockFind(this.shipsStructure, block);
blockFind = event.onBlockFind(this.shipsStructure, block.getPosition());
if (blockFind == OvertimeBlockFinderUpdate.BlockFindControl.IGNORE) {
this.getNextBlock(event, block, directions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void getNextBlock(OvertimeBlockFinderUpdate event, BlockPosition positio
OvertimeBlockFinderUpdate.BlockFindControl blockFind = null;
if (bi.getCollide() == CollideType.MATERIAL) {
if (event != null) {
blockFind = event.onBlockFind(this.shipsStructure, block);
blockFind = event.onBlockFind(this.shipsStructure, block.getPosition());
if (blockFind == OvertimeBlockFinderUpdate.BlockFindControl.IGNORE) {
this.getNextBlock(event, block, directions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.ships.algorthum.blockfinder;

import org.core.TranslateCore;
import org.core.config.ConfigurationNode;
import org.core.config.ConfigurationStream;
import org.core.config.parser.Parser;
import org.core.schedule.Scheduler;
import org.core.schedule.unit.TimeUnit;
import org.core.world.direction.Direction;
Expand All @@ -16,16 +13,15 @@
import org.ships.config.blocks.instruction.BlockInstruction;
import org.ships.config.blocks.instruction.CollideType;
import org.ships.config.configuration.ShipsConfig;
import org.ships.config.node.DedicatedNode;
import org.ships.config.node.ObjectDedicatedNode;
import org.ships.config.node.RawDedicatedNode;
import org.ships.plugin.ShipsPlugin;
import org.ships.vessel.common.types.Vessel;
import org.ships.vessel.structure.AbstractPositionableShipsStructure;
import org.ships.vessel.structure.PositionableShipsStructure;

import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

Expand Down Expand Up @@ -107,8 +103,8 @@ private Overtime(SyncBlockPosition position,
Scheduler scheduler = TranslateCore
.getScheduleManager()
.schedule()
.setDelay(stackDelay)
.setDelayUnit(stackDelayUnit)
.setDelay(this.stackDelay)
.setDelayUnit(this.stackDelayUnit)
.setRunner((sch1) -> {
if ((this.total.size() <= Ships6BlockFinder.this.limit) && (!this.ret.isEmpty())) {
this.process = this.ret;
Expand All @@ -117,8 +113,8 @@ private Overtime(SyncBlockPosition position,
TranslateCore
.getScheduleManager()
.schedule()
.setDelay(stackDelay)
.setDelayUnit(stackDelayUnit)
.setDelay(this.stackDelay)
.setDelayUnit(this.stackDelayUnit)
.setRunner(this.runnable)
.setDisplayName("Ships 6 ASync Block Finder")
.buildDelayed(ShipsPlugin.getPlugin())
Expand All @@ -134,14 +130,14 @@ private Overtime(SyncBlockPosition position,
scheduler = TranslateCore
.getScheduleManager()
.schedule()
.setDelay(stackDelay)
.setDelayUnit(stackDelayUnit)
.setDelay(this.stackDelay)
.setDelayUnit(this.stackDelayUnit)
.setRunner((scheduler2) -> {
OvertimeSection section = new OvertimeSection(list, this.total);
section.runnable.accept(scheduler2);
section.ret.forEach(p -> {
OvertimeBlockFinderUpdate.BlockFindControl blockFind = this.update.onBlockFind(this.pss,
p);
p.getPosition());
if (blockFind == OvertimeBlockFinderUpdate.BlockFindControl.IGNORE) {
return;
}
Expand Down Expand Up @@ -177,7 +173,7 @@ private Overtime(SyncBlockPosition position,
public CompletableFuture<PositionableShipsStructure> getConnectedBlocksOvertime(@NotNull BlockPosition position,
@NotNull OvertimeBlockFinderUpdate runAfterFullSearch) {
CompletableFuture<PositionableShipsStructure> future = new CompletableFuture<>();
var configuration = ShipsPlugin.getPlugin().getConfig();
ShipsConfig configuration = ShipsPlugin.getPlugin().getConfig();
Overtime overtime = new Overtime(position.toSyncPosition(), runAfterFullSearch, configuration, future);
TranslateCore
.getScheduleManager()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ships.algorthum.blockfinder;

import org.core.TranslateCore;
import org.core.config.ConfigurationNode;
import org.core.schedule.unit.TimeUnit;
import org.core.vector.type.Vector3;
import org.core.world.direction.Direction;
Expand All @@ -15,17 +14,19 @@
import org.ships.config.blocks.instruction.BlockInstruction;
import org.ships.config.blocks.instruction.CollideType;
import org.ships.config.configuration.ShipsConfig;
import org.ships.config.node.DedicatedNode;
import org.ships.plugin.ShipsPlugin;
import org.ships.vessel.common.types.Vessel;
import org.ships.vessel.structure.AbstractPositionableShipsStructure;
import org.ships.vessel.structure.PositionableShipsStructure;

import java.io.File;
import java.util.*;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Ships6MultiAsyncBlockFinder implements BasicBlockFinder {
Expand Down Expand Up @@ -66,14 +67,16 @@ public CompletableFuture<PositionableShipsStructure> getConnectedBlocksOvertime(
.setDelay(0)
.setRunner((scheduler) -> {
PositionableShipsStructure structure = new AbstractPositionableShipsStructure(
Position.toSync(position));
position.toSyncPosition());
LinkedTransferQueue<Map.Entry<ASyncBlockPosition, Direction>> toProcess = new LinkedTransferQueue<>();
Direction[] directions = Direction.withYDirections(FourFacingDirection.getFourFacingDirections());
toProcess.add(new AbstractMap.SimpleImmutableEntry<>(Position.toASync(position),
toProcess.add(new AbstractMap.SimpleImmutableEntry<>(position.toAsyncPosition(),
FourFacingDirection.NONE));
while (!toProcess.isEmpty() && structure.getOriginalRelativePositionsToCenter().size() < limit
&& !ShipsPlugin.getPlugin().isShuttingDown()) {
Collection<Vector3<Integer>> positions = structure.getOriginalRelativePositionsToCenter();
while (!toProcess.isEmpty() && structure.size() < limit && !ShipsPlugin
.getPlugin()
.isShuttingDown()) {
Collection<Vector3<Integer>> positions = structure.getVectorsRelativeToLicence().collect(
Collectors.toList());
LinkedTransferQueue<Map.Entry<ASyncBlockPosition, Direction>> next = new LinkedTransferQueue<>();
while (toProcess.hasWaitingConsumer()) {
continue;
Expand Down Expand Up @@ -112,11 +115,11 @@ public CompletableFuture<PositionableShipsStructure> getConnectedBlocksOvertime(
}
});
OvertimeBlockFinderUpdate.BlockFindControl blockFind = runAfterFullSearch.onBlockFind(
structure, posEntry.getKey());
structure, posEntry.getKey().getPosition());
if (blockFind == OvertimeBlockFinderUpdate.BlockFindControl.IGNORE) {
return;
}
structure.addPositionRelativeToWorld(Position.toSync(posEntry.getKey()));
structure.addPositionRelativeToWorld(posEntry.getKey().toSyncPosition());
if (blockFind == OvertimeBlockFinderUpdate.BlockFindControl.USE_AND_FINISH) {
shouldKill.set(true);
TranslateCore
Expand Down
Loading