-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e8c8e9
commit 7e13eb5
Showing
15 changed files
with
287 additions
and
2 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
21 changes: 21 additions & 0 deletions
21
command/common/src/test/java/kessoku/testmod/command/KessokuTestCommand.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,21 @@ | ||
package kessoku.testmod.command; | ||
|
||
import band.kessoku.lib.command.api.events.CommandRegistryEvent; | ||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.text.Text; | ||
|
||
public class KessokuTestCommand implements KessokuModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
CommandRegistryEvent.EVENT.register(((dispatcher, registryAccess, environment) -> { | ||
dispatcher.register( | ||
CommandManager.literal("test") | ||
.executes(context -> { | ||
context.getSource().sendMessage(Text.literal("Hello world!")); | ||
return 0; | ||
}) | ||
); | ||
})); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apply from: rootProject.file("gradle/scripts/klib-common.gradle") | ||
|
||
group = "band.kessoku.lib.entrypoint" | ||
base.archivesName = rootProject.name + "-entrypoint" | ||
base.archivesName = rootProject.name + "-entrypoint" |
22 changes: 22 additions & 0 deletions
22
event-base/common/src/test/java/kessoku/testmod/event/KessokuTestEvent.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,22 @@ | ||
package kessoku.testmod.event; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.event.api.Event; | ||
|
||
public class KessokuTestEvent implements KessokuModInitializer { | ||
|
||
public static final Event<TestEvent> EVENT = Event.of(testEvents -> (name) -> { | ||
for (TestEvent event : testEvents) { | ||
event.test(name); | ||
} | ||
}); | ||
|
||
@Override | ||
public void onInitialize() { | ||
EVENT.invoker().test("Hello, world!"); | ||
} | ||
|
||
public interface TestEvent { | ||
void test(String name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
keybind/common/src/test/java/kessoku/testmod/keybind/KessokuTestKeybind.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,18 @@ | ||
package kessoku.testmod.keybind; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.keybind.api.KeyBindRegister; | ||
import net.minecraft.client.option.KeyBinding; | ||
|
||
public class KessokuTestKeybind implements KessokuModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
KeyBindRegister.getInstance().register( | ||
new KeyBinding( | ||
"Test Name", | ||
0, | ||
"Test Category" | ||
) | ||
); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/CommonLifecycleTest.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,13 @@ | ||
package kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.LifecycleEvent; | ||
|
||
public class CommonLifecycleTest implements KessokuModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
LifecycleEvent.TAG_LOADED.register(((registries, client) -> { | ||
KessokuTestLifecycle.LOGGER.info("Tags (re)loaded on {} {}", client ? "client" : "server", Thread.currentThread()); | ||
})); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/KessokuTestLifecycle.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,44 @@ | ||
package kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class KessokuTestLifecycle implements KessokuModInitializer { | ||
public static final Logger LOGGER = LoggerFactory.getLogger("LifecycleEventsTest"); | ||
|
||
@Override | ||
public void onInitialize() { | ||
//Server Chunk | ||
ServerChunkEvent.LOADED.register(((serverWorld, world) -> { | ||
//Do something | ||
})); | ||
ServerChunkEvent.UNLOADED.register(((serverWorld, world) -> { | ||
//Do something | ||
})); | ||
|
||
//Server Lifecycle | ||
ServerLifecycleEvent.STARTED.register(((minecraftServer) -> { | ||
LOGGER.info("Started Server!"); | ||
})); | ||
ServerLifecycleEvent.STARTING.register(((minecraftServer) -> { | ||
LOGGER.info("Starting Server!"); | ||
})); | ||
ServerLifecycleEvent.STOPPED.register(((minecraftServer) -> { | ||
LOGGER.info("Stopping Server!"); | ||
})); | ||
ServerLifecycleEvent.STOPPING.register(((minecraftServer) -> { | ||
LOGGER.info("Stopped Server!"); | ||
})); | ||
ServerLifecycleEvent.SYNC_DATA_PACK_CONTENTS.register(((player, joined) -> { | ||
LOGGER.info("SyncDataPackContents received for {}", joined ? "join" : "reload"); | ||
})); | ||
ServerLifecycleEvent.BEFORE_SAVE.register((server, flush, force) -> { | ||
LOGGER.info("Starting Save with settings: Flush:{} Force:{}", flush, force); | ||
}); | ||
ServerLifecycleEvent.AFTER_SAVE.register((server, flush, force) -> { | ||
LOGGER.info("Save Finished with settings: Flush:{} Force:{}", flush, force); | ||
}); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ResourceReloadTests.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,22 @@ | ||
package kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.ServerLifecycleEvent; | ||
|
||
public class ResourceReloadTests implements KessokuModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
ServerLifecycleEvent.START_DATA_PACK_RELOAD.register(((server, serverResourceManager) -> { | ||
KessokuTestLifecycle.LOGGER.info("PREPARING FOR RELOAD"); | ||
})); | ||
|
||
ServerLifecycleEvent.END_DATA_PACK_RELOAD.register(((server, serverResourceManager, success) -> { | ||
if (success) { | ||
KessokuTestLifecycle.LOGGER.info("FINISHED RELOAD on {}", Thread.currentThread()); | ||
} else { | ||
// Failure can be tested by trying to disable the vanilla datapack | ||
KessokuTestLifecycle.LOGGER.error("FAILED TO RELOAD on {}", Thread.currentThread()); | ||
} | ||
})); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerBlockEntityTests.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,28 @@ | ||
package kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.ServerBlockEntityEvent; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.registry.Registries; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ServerBlockEntityTests implements KessokuModInitializer { | ||
private final List<BlockEntity> serverBlockEntities = new ArrayList<>(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
ServerBlockEntityEvent.LOADED.register(((blockEntity, world) -> { | ||
this.serverBlockEntities.add(blockEntity); | ||
|
||
KessokuTestLifecycle.LOGGER.info("[SERVER] LOADED {} - BlockEntities: {}", Registries.BLOCK_ENTITY_TYPE.getId(blockEntity.getType()).toString(), this.serverBlockEntities.size()); | ||
})); | ||
|
||
ServerBlockEntityEvent.UNLOADED.register(((blockEntity, world) -> { | ||
this.serverBlockEntities.remove(blockEntity); | ||
|
||
KessokuTestLifecycle.LOGGER.info("[SERVER] UNLOADED {} - BlockEntities: {}", Registries.BLOCK_ENTITY_TYPE.getId(blockEntity.getType()).toString(), this.serverBlockEntities.size()); | ||
})); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerEntityTests.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,31 @@ | ||
package kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.ServerEntityEvent; | ||
import net.minecraft.entity.Entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ServerEntityTests implements KessokuModInitializer { | ||
private final List<Entity> serverEntities = new ArrayList<>(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
ServerEntityEvent.LOADED.register(((entity, world) -> { | ||
this.serverEntities.add(entity); | ||
|
||
KessokuTestLifecycle.LOGGER.info("[SERVER] LOADED {} - Entities: {}", entity.toString(), this.serverEntities.size()); | ||
})); | ||
|
||
ServerEntityEvent.UNLOADED.register(((entity, world) -> { | ||
this.serverEntities.remove(entity); | ||
|
||
KessokuTestLifecycle.LOGGER.info("[SERVER] UNLOADED {} - Entities: {}", entity.toString(), this.serverEntities.size()); | ||
})); | ||
|
||
ServerEntityEvent.EQUIPMENT_CHANGED.register(((livingEntity, equipmentSlot, previous, next) -> { | ||
KessokuTestLifecycle.LOGGER.info("[SERVER] Entity equipment change: Entity: {}, Slot {}, Previous: {}, Current {} ", livingEntity, equipmentSlot.name(), previous, next); | ||
})); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerTickTests.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 kessoku.testmod.lifecycle; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.ServerTickEvent; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ServerTickTests implements KessokuModInitializer { | ||
private final Map<RegistryKey<World>, Integer> tickTracker = new HashMap<>(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
ServerTickEvent.START_WORLD_TICK.register(world -> { | ||
// Verify we are inside the tick | ||
if (!world.isInBlockTick()) { | ||
throw new AssertionError("Start tick event should be fired while ServerWorld is inside of block tick"); | ||
} | ||
}); | ||
|
||
ServerTickEvent.END_WORLD_TICK.register(world -> { | ||
final int worldTicks = tickTracker.computeIfAbsent(world.getRegistryKey(), k -> 0); | ||
|
||
if (worldTicks % 200 == 0) { // Log every 200 ticks to verify the tick callback works on the server world | ||
KessokuTestLifecycle.LOGGER.info("Ticked Server World - {} ticks:{}", worldTicks, world.getRegistryKey().getValue()); | ||
} | ||
|
||
this.tickTracker.put(world.getRegistryKey(), worldTicks + 1); | ||
}); | ||
|
||
ServerTickEvent.START_SERVER_TICK.register(server -> { | ||
KessokuTestLifecycle.LOGGER.info("Server tick started"); | ||
}); | ||
|
||
ServerTickEvent.END_SERVER_TICK.register(server -> { | ||
if (server.getTicks() % 200 == 0) { // Log every 200 ticks to verify the tick callback works on the server | ||
KessokuTestLifecycle.LOGGER.info("Ticked Server at {} ticks.", server.getTicks()); | ||
} | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientBlockEntityTests.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,17 @@ | ||
package kessoku.testmod.lifecycle.client; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.client.ClientBlockEntityEvent; | ||
|
||
public class ClientBlockEntityTests implements KessokuClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
ClientBlockEntityEvent.LOADED.register((blockEntity, world) -> { | ||
//Do something in client | ||
}); | ||
|
||
ClientBlockEntityEvent.UNLOADED.register((blockEntity, world) -> { | ||
//Do something in client | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientChunkTests.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,17 @@ | ||
package kessoku.testmod.lifecycle.client; | ||
|
||
import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; | ||
import band.kessoku.lib.events.lifecycle.api.client.ClientChunkEvent; | ||
|
||
public class ClientChunkTests implements KessokuClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
ClientChunkEvent.LOADED.register((world, chunk) -> { | ||
//Do something in client | ||
}); | ||
|
||
ClientChunkEvent.UNLOADED.register((world, chunk) -> { | ||
//Do something in client | ||
}); | ||
} | ||
} |