Skip to content

Commit 9be3a75

Browse files
committed
ported to vs 2.4
1 parent 31e8437 commit 9be3a75

File tree

22 files changed

+167
-421
lines changed

22 files changed

+167
-421
lines changed

buildSrc/src/main/groovy/multiloader-common.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ repositories {
146146
includeGroup('com.jamieswhiteshirt')
147147
}
148148
}
149+
149150
exclusiveContent {
150151
forRepository {
151152
maven {

common/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ dependencies {
2525
annotationProcessor "com.google.auto.service:auto-service:1.1.1"
2626

2727
modApi "org.valkyrienskies:valkyrienskies-120-common:${vs2_version}"
28-
2928
implementation "org.valkyrienskies.core:api:${vs_core_version}"
30-
implementation "org.valkyrienskies.core:api-game:${vs_core_version}"
31-
implementation "org.valkyrienskies.core:util:${vs_core_version}"
3229
implementation "org.valkyrienskies.core:impl:${vs_core_version}"
30+
implementation "org.valkyrienskies.core:internal:${vs_core_version}"
31+
implementation "org.valkyrienskies.core:util:${vs_core_version}"
32+
3333
modImplementation "com.github.litermc.vtil:vtil-common-${minecraft_version}:${vtil_version}"
3434

3535
compileOnly "cc.tweaked:cc-tweaked-${minecraft_version}-common:${cct_version}"

common/src/main/java/com/github/litermc/vschunkloader/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public final class Constants {
77
public static final String MOD_ID = "vschunkloader";
88
public static final String MOD_NAME = "VSChunkLoader";
9-
public static final String MOD_VERSION = "1.5.0";
9+
public static final String MOD_VERSION = "2.0.0";
1010
public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);
1111

1212
private Constants() {}

common/src/main/java/com/github/litermc/vschunkloader/VSCApi.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ public static boolean isForceLoadedBy(final MinecraftServer server, final long i
121121
return ForceLoadAttachment.get(ship).isForceLoadedBy(token);
122122
}
123123

124-
public static boolean canFreezeShipForChunkLoad(final ServerShip ship) {
125-
return switch (Config.shipFreezing) {
126-
case ALL -> true;
127-
case NONE -> false;
128-
case AMMO -> ship.getAttachment(AmmoShipAttachment.class) != null;
129-
};
130-
}
131-
132124
private static ServerShip getShip(final MinecraftServer server, final long id) {
133125
final ServerShipWorld shipWorld = VSGameUtilsKt.getShipObjectWorld(server);
134126
final ServerShip ship = shipWorld.getLoadedShips().getById(id);

common/src/main/java/com/github/litermc/vschunkloader/VSCListeners.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.litermc.vschunkloader;
22

3-
import com.github.litermc.vschunkloader.attachment.ChunkSensorAttachment;
3+
import com.github.litermc.vschunkloader.attachment.AmmoShipAttachment;
4+
import com.github.litermc.vschunkloader.attachment.ForceLoadAttachment;
45
import com.github.litermc.vschunkloader.config.Config;
56
import com.github.litermc.vschunkloader.util.ChunkLoaderManager;
67
import com.github.litermc.vschunkloader.util.ChunkSensor;
@@ -17,10 +18,21 @@
1718
import org.valkyrienskies.core.api.ships.ServerShip;
1819
import org.valkyrienskies.core.api.world.ServerShipWorld;
1920
import org.valkyrienskies.mod.common.VSGameUtilsKt;
21+
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;
2022

2123
public final class VSCListeners {
2224
private VSCListeners() {}
2325

26+
public static void onModInit() {
27+
VSCRegistry.register();
28+
registerAttachments();
29+
}
30+
31+
private static void registerAttachments() {
32+
ValkyrienSkiesMod.getApi().registerAttachment(AmmoShipAttachment.class);
33+
ValkyrienSkiesMod.getApi().registerAttachment(ForceLoadAttachment.class);
34+
}
35+
2436
public static void onServerLevelLoad(final ServerLevel level) {
2537
ChunkLoaderManager.get(level);
2638
}
@@ -46,10 +58,6 @@ public static void preServerTick(final MinecraftServer server) {
4658
}
4759
ChunkLoaderManager.get(level).refreshForcedShip(ship);
4860
}
49-
50-
for (final LoadedServerShip ship : shipWorld.getLoadedShips()) {
51-
ChunkSensorAttachment.get(ship).serverTick(ship);
52-
}
5361
}
5462

5563
public static void postServerTick(final MinecraftServer server) {

common/src/main/java/com/github/litermc/vschunkloader/attachment/AmmoShipAttachment.java

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,51 @@
33
import com.github.litermc.vschunkloader.Constants;
44
import com.github.litermc.vschunkloader.VSCApi;
55
import com.github.litermc.vschunkloader.config.Config;
6-
import com.github.litermc.vschunkloader.platform.PlatformHelper;
76
import com.github.litermc.vschunkloader.util.TaskUtil;
87
import com.github.litermc.vtil.api.assemble.ShipAllocator;
9-
import com.github.litermc.vtil.util.LevelUtil;
8+
import com.github.litermc.vtil.api.attachment.IServerTickListener;
109

1110
import net.minecraft.resources.ResourceLocation;
12-
import net.minecraft.server.MinecraftServer;
1311
import net.minecraft.server.level.ServerLevel;
1412

1513
import com.fasterxml.jackson.annotation.JsonAutoDetect;
1614
import com.fasterxml.jackson.annotation.JsonGetter;
1715
import com.fasterxml.jackson.annotation.JsonSetter;
1816
import org.valkyrienskies.core.api.ships.LoadedServerShip;
1917
import org.valkyrienskies.core.api.ships.ServerShip;
20-
import org.valkyrienskies.core.api.ships.ServerTickListener;
21-
import org.valkyrienskies.core.apigame.world.ServerShipWorldCore;
22-
import org.valkyrienskies.mod.common.VSGameUtilsKt;
23-
24-
import java.util.Collection;
25-
import java.util.Collections;
26-
import java.util.HashSet;
27-
import java.util.Set;
18+
import org.valkyrienskies.core.impl.game.ships.ShipData;
2819

2920
@JsonAutoDetect(
3021
fieldVisibility = JsonAutoDetect.Visibility.NONE,
3122
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
3223
getterVisibility = JsonAutoDetect.Visibility.NONE,
3324
setterVisibility = JsonAutoDetect.Visibility.NONE
3425
)
35-
public final class AmmoShipAttachment implements ServerTickListener {
26+
public final class AmmoShipAttachment implements IServerTickListener {
3627
private static final ResourceLocation AMMO_SHIP_TICKET = new ResourceLocation(Constants.MOD_ID, "ammo_ship");
3728

38-
private final MinecraftServer server;
39-
private final ServerShipWorldCore world;
40-
private long shipId;
4129
private int activatedTick;
4230
private boolean unmanaged = false;
4331
private boolean deactivated = false;
4432

45-
public AmmoShipAttachment() {
46-
this(-1);
47-
}
48-
49-
private AmmoShipAttachment(final long shipId) {
50-
this.server = PlatformHelper.get().getCurrentServer();
51-
this.world = VSGameUtilsKt.getShipObjectWorld(this.server);
52-
this.shipId = shipId;
53-
}
33+
public AmmoShipAttachment() {}
5434

5535
public static AmmoShipAttachment create(final ServerShip ship) {
56-
final AmmoShipAttachment attachment = new AmmoShipAttachment(ship.getId());
57-
ship.saveAttachment(AmmoShipAttachment.class, attachment);
36+
final AmmoShipAttachment attachment = new AmmoShipAttachment();
37+
if (ship instanceof final LoadedServerShip loadedShip) {
38+
loadedShip.setAttachment(attachment);
39+
return attachment;
40+
} else if (ship instanceof final ShipData shipData) {
41+
final var attachmentHolder = shipData.getAttachmentHolder();
42+
attachmentHolder.setAttachment(attachment);
43+
} else {
44+
throw new IllegalArgumentException("ship is neither LoadedServerShip nor ShipData");
45+
}
5846
return attachment;
5947
}
6048

61-
@JsonGetter("shipId")
62-
private long getShipId() {
63-
return this.shipId;
64-
}
65-
66-
@JsonSetter("shipId")
67-
private void setShipId(final long shipId) {
68-
this.shipId = shipId;
69-
}
70-
7149
@JsonGetter("activatedTick")
72-
private long getActivatedTick() {
50+
private int getActivatedTick() {
7351
return this.activatedTick;
7452
}
7553

@@ -79,15 +57,15 @@ private void setActivatedTick(final int activatedTick) {
7957
}
8058

8159
@Override
82-
public void onServerTick() {
60+
public void onServerTick(final ServerLevel level, final LoadedServerShip ship) {
8361
if (this.activatedTick == 0) {
84-
this.checkActivate();
62+
this.checkActivate(level, ship);
8563
return;
8664
}
8765
if (this.activatedTick > Config.ammoMaxActivateSeconds * 20) {
8866
if (!this.deactivated) {
8967
this.deactivated = true;
90-
this.deactivate();
68+
this.deactivate(level, ship);
9169
}
9270
return;
9371
}
@@ -98,41 +76,24 @@ public void managerTick() {
9876
this.unmanaged = false;
9977
}
10078

101-
private ServerShip getShip() {
102-
final ServerShip ship = this.world.getLoadedShips().getById(this.shipId);
103-
if (ship != null) {
104-
return ship;
105-
}
106-
return this.world.getAllShips().getById(this.shipId);
107-
}
108-
109-
private void checkActivate() {
79+
private void checkActivate(final ServerLevel level, final LoadedServerShip ship) {
11080
if (this.unmanaged) {
111-
this.activate();
81+
this.activate(level, ship);
11282
return;
11383
}
11484
this.unmanaged = true;
11585
}
11686

117-
private void activate() {
87+
private void activate(final ServerLevel level, final LoadedServerShip ship) {
11888
this.activatedTick = 1;
119-
VSCApi.forceLoad(this.server, this.shipId, AMMO_SHIP_TICKET, true);
89+
VSCApi.forceLoad(level.getServer(), ship.getId(), AMMO_SHIP_TICKET, true);
12090
}
12191

122-
private void deactivate() {
123-
VSCApi.forceLoad(this.server, this.shipId, AMMO_SHIP_TICKET, false);
92+
private void deactivate(final ServerLevel level, final LoadedServerShip ship) {
93+
VSCApi.forceLoad(level.getServer(), ship.getId(), AMMO_SHIP_TICKET, false);
12494
if (!Config.removeAmmoAfterExpired) {
12595
return;
12696
}
127-
final ServerShip ship = this.getShip();
128-
if (ship == null) {
129-
return;
130-
}
131-
final ServerLevel level = LevelUtil.getLevel(ship.getChunkClaimDimension());
132-
if (level == null) {
133-
this.world.deleteShip(ship);
134-
return;
135-
}
13697
TaskUtil.queueTickStart(() -> ShipAllocator.get(level.getServer()).putShip(ship));
13798
}
13899
}

0 commit comments

Comments
 (0)