Skip to content

Commit

Permalink
Some testmods
Browse files Browse the repository at this point in the history
  • Loading branch information
Oganesson897 committed Sep 4, 2024
1 parent 3e8c8e9 commit 7e13eb5
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 2 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ subprojects {
})
implementation("com.google.auto.service:auto-service-annotations:1.1.1")
annotationProcessor("com.google.auto.service:auto-service:1.1.1")

//Test mod
testImplementation(project(":base-common"))
testImplementation(project(":entrypoint-common"))
}

spotless {
Expand Down Expand Up @@ -109,4 +113,4 @@ allprojects {
}
include.extendsFrom moduleInclude
}
}
}
3 changes: 3 additions & 0 deletions command/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ base.archivesName = rootProject.name + "-command"
dependencies {
moduleImplementation(project(":base-common"))
moduleImplementation(project(":event-base-common"))

testImplementation(project(":base-common"))
testImplementation(project(":event-base-common"))
}
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;
})
);
}));
}
}
2 changes: 1 addition & 1 deletion entrypoint/common/build.gradle
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"
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);
}
}
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"
)
);
}
}
2 changes: 2 additions & 0 deletions lifecycle-events/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ base.archivesName = rootProject.name + "-lifecycle-events"
dependencies {
moduleImplementation(project(":base-common"))
moduleImplementation(project(":event-base-common"))

testImplementation(project(":event-base-common"))
}
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());
}));
}
}
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);
});
}
}
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());
}
}));
}
}
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());
}));
}
}
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);
}));
}
}
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());
}
});
}
}
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
});
}
}
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
});
}
}

0 comments on commit 7e13eb5

Please sign in to comment.