-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fixed loading into saves and added a note about ModernFix compatibility to the readme.
- Loading branch information
1 parent
f69f5b3
commit 58b2bbe
Showing
10 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ub/steveplays28/noisiumchunkmanager/server/event/world/ticket/ServerWorldTicketEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.steveplays28.noisiumchunkmanager.server.event.world.ticket; | ||
|
||
import dev.architectury.event.Event; | ||
import dev.architectury.event.EventFactory; | ||
import net.minecraft.server.world.ChunkTicketType; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.ChunkPos; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface ServerWorldTicketEvent { | ||
/** | ||
* @see TicketCreated | ||
*/ | ||
Event<TicketCreated> TICKET_CREATED = EventFactory.createLoop(); | ||
/** | ||
* @see TicketCreated | ||
*/ | ||
Event<TicketRemoved> TICKET_REMOVED = EventFactory.createLoop(); | ||
|
||
@FunctionalInterface | ||
interface TicketCreated { | ||
/** | ||
* Invoked after a chunk ticket has been created. | ||
* | ||
* @param serverWorld The {@link ServerWorld}. | ||
* @param ticketType The {@link ChunkTicketType}. | ||
* @param chunkPosition The {@link ChunkPos}. | ||
* @param radius The radius, in chunks. | ||
*/ | ||
void onTicketCreated(@NotNull ServerWorld serverWorld, @NotNull ChunkTicketType<?> ticketType, @NotNull ChunkPos chunkPosition, int radius); | ||
} | ||
|
||
@FunctionalInterface | ||
interface TicketRemoved { | ||
/** | ||
* Invoked after a chunk ticket has been removed. | ||
* | ||
* @param serverWorld The {@link ServerWorld}. | ||
* @param chunkPosition The {@link ChunkPos}. | ||
*/ | ||
void onTicketRemoved(@NotNull ServerWorld serverWorld, @NotNull ChunkPos chunkPosition); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ava/io/github/steveplays28/noisiumchunkmanager/server/world/ticket/ServerWorldTicket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.steveplays28.noisiumchunkmanager.server.world.ticket; | ||
|
||
/** | ||
* Stores specific data of a {@link net.minecraft.server.world.ChunkTicketType}. | ||
* | ||
* @param startTick The start tick. | ||
* @param duration The duration, in ticks. | ||
*/ | ||
public record ServerWorldTicket(long startTick, long duration) { | ||
// NO-OP | ||
} |
82 changes: 82 additions & 0 deletions
82
...github/steveplays28/noisiumchunkmanager/server/world/ticket/ServerWorldTicketTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package io.github.steveplays28.noisiumchunkmanager.server.world.ticket; | ||
|
||
import dev.architectury.event.events.common.TickEvent; | ||
import io.github.steveplays28.noisiumchunkmanager.server.event.world.ticket.ServerWorldTicketEvent; | ||
import net.minecraft.server.world.ChunkTicketType; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.ChunkPos; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
|
||
public class ServerWorldTicketTracker { | ||
private final @NotNull ServerWorld serverWorld; | ||
private final @NotNull BiConsumer<ChunkPos, Integer> loadChunksInRadiusBiConsumer; | ||
private final @NotNull Consumer<ChunkPos> unloadChunkConsumer; | ||
private final @NotNull Map<ChunkPos, ServerWorldTicket> tickets; | ||
|
||
public ServerWorldTicketTracker(@NotNull ServerWorld serverWorld, @NotNull BiConsumer<ChunkPos, Integer> loadChunksInRadiusBiConsumer, @NotNull Consumer<ChunkPos> unloadChunkConsumer) { | ||
this.serverWorld = serverWorld; | ||
this.loadChunksInRadiusBiConsumer = loadChunksInRadiusBiConsumer; | ||
this.unloadChunkConsumer = unloadChunkConsumer; | ||
|
||
this.tickets = new HashMap<>(); | ||
|
||
ServerWorldTicketEvent.TICKET_CREATED.register((ticketServerWorld, ticketType, chunkPosition, radius) -> { | ||
if (ticketServerWorld != serverWorld) { | ||
return; | ||
} | ||
|
||
onTicketCreated(ticketServerWorld, ticketType, chunkPosition, radius); | ||
}); | ||
ServerWorldTicketEvent.TICKET_REMOVED.register((ticketServerWorld, chunkPosition) -> { | ||
if (ticketServerWorld != serverWorld) { | ||
return; | ||
} | ||
|
||
onTicketRemoved(chunkPosition); | ||
}); | ||
TickEvent.SERVER_LEVEL_POST.register(instance -> { | ||
if (instance != serverWorld) { | ||
return; | ||
} | ||
|
||
tick(); | ||
}); | ||
} | ||
|
||
private void onTicketCreated(@NotNull ServerWorld serverWorld, @NotNull ChunkTicketType<?> ticketType, @NotNull ChunkPos chunkPosition, int radius) { | ||
if (tickets.containsKey(chunkPosition)) { | ||
return; | ||
} | ||
|
||
loadChunksInRadiusBiConsumer.accept(chunkPosition, radius); | ||
tickets.put(chunkPosition, new ServerWorldTicket(serverWorld.getTime(), ticketType.getExpiryTicks())); | ||
} | ||
|
||
private void onTicketRemoved(@NotNull ChunkPos chunkPosition) { | ||
if (!tickets.containsKey(chunkPosition)) { | ||
return; | ||
} | ||
|
||
unloadChunkConsumer.accept(chunkPosition); | ||
tickets.remove(chunkPosition); | ||
} | ||
|
||
private void tick() { | ||
for (@NotNull var ticketEntry : tickets.entrySet()) { | ||
@NotNull var ticket = ticketEntry.getValue(); | ||
// TODO: Store endTick in the ServerWorldTicket instead of the startTick and duration | ||
if (ticket.startTick() + ticket.duration() > this.serverWorld.getTime()) { | ||
return; | ||
} | ||
|
||
@NotNull var ticketChunkPosition = ticketEntry.getKey(); | ||
unloadChunkConsumer.accept(ticketChunkPosition); | ||
tickets.remove(ticketChunkPosition); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
common/src/main/resources/assets/noisiumchunkmanager/lang/en_us.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ | |
"breaks": { | ||
"c2me": "*", | ||
"vmp": "*", | ||
"leavesbegone": "*" | ||
"leavesbegone": "*", | ||
"ksyxis": "*" | ||
} | ||
} |