Working ECS block event test
Some checks failed
Verifying Everything Compiles / build (push) Has been cancelled
Some checks failed
Verifying Everything Compiles / build (push) Has been cancelled
This commit is contained in:
@@ -1,33 +1,53 @@
|
||||
package dev.hytalemodding;
|
||||
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.util.Config;
|
||||
import dev.hytalemodding.events.RitualBreakBlockEvent;
|
||||
import dev.hytalemodding.events.RitualPlaceBlockEvent;
|
||||
import dev.hytalemodding.commands.ExampleCommand;
|
||||
import dev.hytalemodding.config.ExampleConfig;
|
||||
import dev.hytalemodding.events.ExampleEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ExamplePlugin extends JavaPlugin {
|
||||
public class RitualPlugin extends JavaPlugin {
|
||||
|
||||
public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
|
||||
|
||||
private static Config<ExampleConfig> config = null;
|
||||
|
||||
public ExamplePlugin(@Nonnull JavaPluginInit init) {
|
||||
public RitualPlugin(@Nonnull JavaPluginInit init) {
|
||||
super(init);
|
||||
config = this.withConfig("example_config", ExampleConfig.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
LOGGER.atInfo().log("ritual mod loaded");
|
||||
config.save();
|
||||
|
||||
RitualSpawner ritualSpawner = new RitualSpawner();
|
||||
this.getEntityStoreRegistry().registerSystem(new RitualPlaceBlockEvent(ritualSpawner));
|
||||
this.getEntityStoreRegistry().registerSystem(new RitualBreakBlockEvent(ritualSpawner));
|
||||
|
||||
// Example
|
||||
this.getCommandRegistry().registerCommand(new ExampleCommand("example", "An example command"));
|
||||
if (getConfig().get().isEnabledWelcomeMessage()) {
|
||||
this.getEventRegistry().registerGlobal(PlayerReadyEvent.class, ExampleEvent::onPlayerReady);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
}
|
||||
|
||||
public static Config<ExampleConfig> getConfig() {
|
||||
return config;
|
||||
}
|
||||
9
src/main/java/dev/hytalemodding/RitualSpawner.java
Normal file
9
src/main/java/dev/hytalemodding/RitualSpawner.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package dev.hytalemodding;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class RitualSpawner {
|
||||
public void blockChangeEvent(String blockId, Vector3i targetPosition) {
|
||||
RitualPlugin.LOGGER.atInfo().log("a block got placed with the id: %s", blockId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.hytalemodding.events;
|
||||
|
||||
import com.hypixel.hytale.component.Archetype;
|
||||
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.EntityEventSystem;
|
||||
import com.hypixel.hytale.server.core.event.events.ecs.BreakBlockEvent;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import dev.hytalemodding.RitualSpawner;
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class RitualBreakBlockEvent extends EntityEventSystem<EntityStore, BreakBlockEvent> {
|
||||
private final RitualSpawner ritualSpawner;
|
||||
public RitualBreakBlockEvent(RitualSpawner ritualSpawner) {
|
||||
super(BreakBlockEvent.class);
|
||||
this.ritualSpawner = ritualSpawner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(int index,
|
||||
@NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
|
||||
@NonNullDecl Store<EntityStore> store,
|
||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer,
|
||||
@NonNullDecl BreakBlockEvent breakBlockEvent) {
|
||||
String itemHolding = breakBlockEvent.getItemInHand().getItemId();
|
||||
Vector3i blockPosition = breakBlockEvent.getTargetBlock();
|
||||
ritualSpawner.blockChangeEvent(itemHolding, blockPosition);
|
||||
}
|
||||
|
||||
@NullableDecl
|
||||
@Override
|
||||
public Query<EntityStore> getQuery() {
|
||||
return Archetype.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.hytalemodding.events;
|
||||
|
||||
import com.hypixel.hytale.component.Archetype;
|
||||
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.server.core.event.events.ecs.PlaceBlockEvent;
|
||||
import dev.hytalemodding.RitualSpawner;
|
||||
import com.hypixel.hytale.component.system.EntityEventSystem;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class RitualPlaceBlockEvent extends EntityEventSystem<EntityStore, PlaceBlockEvent> {
|
||||
private final RitualSpawner ritualSpawner;
|
||||
public RitualPlaceBlockEvent(RitualSpawner ritualSpawner) {
|
||||
super(PlaceBlockEvent.class);
|
||||
this.ritualSpawner = ritualSpawner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(int index,
|
||||
@NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
|
||||
@NonNullDecl Store<EntityStore> store,
|
||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer,
|
||||
@NonNullDecl PlaceBlockEvent placeBlockEvent) {
|
||||
String blockId = placeBlockEvent.getItemInHand().getItemId();
|
||||
Vector3i targetPosition = placeBlockEvent.getTargetBlock();
|
||||
ritualSpawner.blockChangeEvent(blockId, targetPosition);
|
||||
}
|
||||
|
||||
@NullableDecl
|
||||
@Override
|
||||
public Query<EntityStore> getQuery() {
|
||||
return Archetype.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user