Added EndermanTeleportComponent

This commit is contained in:
2026-01-19 09:32:31 +01:00
parent a02ba8eb7b
commit b42b9b013b
7 changed files with 121 additions and 100 deletions

View File

@@ -11,9 +11,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.util.logging.Level; import java.util.logging.Level;
public class AddDefaultComponentTickSystem extends EntityTickingSystem<EntityStore> { public class AddDefaultComponentTickSystem extends EntityTickingSystem<EntityStore> {
private final ComponentType<EntityStore, CustomComponent> customComponentType; private final ComponentType<EntityStore, EndermanTeleportComponent> customComponentType;
public AddDefaultComponentTickSystem(ComponentType<EntityStore, CustomComponent> poisonComponentType) { public AddDefaultComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> poisonComponentType) {
this.customComponentType = poisonComponentType; this.customComponentType = poisonComponentType;
} }
@Override @Override
@@ -23,7 +23,7 @@ public class AddDefaultComponentTickSystem extends EntityTickingSystem<EntitySto
@NonNullDecl Store<EntityStore> store, @NonNullDecl Store<EntityStore> store,
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) { @NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i); Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
CustomComponent component = store.getComponent(ref, customComponentType); EndermanTeleportComponent component = store.getComponent(ref, customComponentType);
if (component != null) { if (component != null) {
return; return;
} }
@@ -36,13 +36,13 @@ public class AddDefaultComponentTickSystem extends EntityTickingSystem<EntitySto
if (!"Bunny".equals(displayName)){ if (!"Bunny".equals(displayName)){
return; return;
} }
commandBuffer.addComponent(ref, customComponentType, new CustomComponent()); commandBuffer.addComponent(ref, customComponentType, new EndermanTeleportComponent());
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("Added Component to ref: " + displayName); LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("Added Component to ref: " + displayName);
} }
@NullableDecl @NullableDecl
@Override @Override
public Query<EntityStore> getQuery() { public Query<EntityStore> getQuery() {
return Query.any(); return Query.and(DisplayNameComponent.getComponentType());
} }
} }

View File

@@ -1,14 +0,0 @@
package com.tikaiz;
import com.hypixel.hytale.component.Component;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import javax.annotation.Nullable;
public class CustomComponent implements Component<EntityStore> {
@Nullable
@Override
public Component<EntityStore> clone() {
return new CustomComponent();
}
}

View File

@@ -3,19 +3,26 @@ package com.tikaiz;
import com.hypixel.hytale.component.*; import com.hypixel.hytale.component.*;
import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent; import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import org.checkerframework.checker.nullness.compatqual.NonNullDecl; import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.util.logging.Level; import java.util.logging.Level;
public class CustomComponentTickSystem extends EntityTickingSystem<EntityStore> { import static com.tikaiz.TeleportHelper.randomTeleport;
private final ComponentType<EntityStore, CustomComponent> customComponentType;
public CustomComponentTickSystem(ComponentType<EntityStore, CustomComponent> poisonComponentType) { public class CustomComponentTickSystem extends EntityTickingSystem<EntityStore> {
private final ComponentType<EntityStore, EndermanTeleportComponent> customComponentType;
public CustomComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> poisonComponentType) {
this.customComponentType = poisonComponentType; this.customComponentType = poisonComponentType;
} }
@Override @Override
public void tick(float dt, public void tick(float dt,
int i, int i,
@@ -23,24 +30,24 @@ public class CustomComponentTickSystem extends EntityTickingSystem<EntityStore>
@NonNullDecl Store<EntityStore> store, @NonNullDecl Store<EntityStore> store,
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) { @NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i); Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
CustomComponent component = store.getComponent(ref, customComponentType); EndermanTeleportComponent endermanTeleportComponent = store.getComponent(ref, customComponentType);
if (component == null) { assert endermanTeleportComponent != null;
LoggerSingleton.getInstance().getHytaleLogger().at(Level.SEVERE).log("This should never happen! "); var transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
return; assert transformComponent != null;
}
DisplayNameComponent displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType());
if (displayNameComponent == null || displayNameComponent.getDisplayName() == null) {
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("new Event Ticking system called on : " + ref);
return;
}
var displayName = displayNameComponent.getDisplayName().getAnsiMessage();
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("new Event Ticking system called on : " + displayName);
endermanTeleportComponent.addElapsedTime(dt);
if (endermanTeleportComponent.getElapsedTime() >= endermanTeleportComponent.getTickInterval()) {
endermanTeleportComponent.resetElapsedTime();
randomTeleport(commandBuffer, ref, transformComponent.getPosition());
} }
}
@NullableDecl @NullableDecl
@Override @Override
public Query<EntityStore> getQuery() { public Query<EntityStore> getQuery() {
return Query.and(customComponentType); return Query.and(customComponentType, TransformComponent.getComponentType());
} }
} }

View File

@@ -1,28 +1,25 @@
package com.tikaiz; package com.tikaiz;
import com.hypixel.hytale.component.ArchetypeChunk; import com.hypixel.hytale.component.*;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.EntityEventSystem; import com.hypixel.hytale.component.system.EntityEventSystem;
import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent; import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.damage.Damage; import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.core.util.NotificationUtil; import com.hypixel.hytale.server.core.util.NotificationUtil;
import org.checkerframework.checker.nullness.compatqual.NonNullDecl; import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.util.logging.Level; import static com.tikaiz.TeleportHelper.randomTeleport;
public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> { public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> {
protected DamageEventSystem() { private final ComponentType<EntityStore, EndermanTeleportComponent> endermanTeleportComponentType;
protected DamageEventSystem(ComponentType<EntityStore, EndermanTeleportComponent> type) {
super(Damage.class); super(Damage.class);
this.endermanTeleportComponentType = type;
} }
@Override @Override
@@ -32,42 +29,23 @@ public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> {
@NonNullDecl CommandBuffer<EntityStore> commandBuffer, @NonNullDecl CommandBuffer<EntityStore> commandBuffer,
@NonNullDecl Damage damage) { @NonNullDecl Damage damage) {
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i); Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
TransformComponent component = store.getComponent(ref, TransformComponent.getComponentType()); TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
if (component == null) { assert transformComponent != null;
LoggerSingleton.getInstance().getHytaleLogger().at(Level.SEVERE).log("Transform was Null");
return;
}
var displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType()); var displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType());
if (displayNameComponent == null) { assert displayNameComponent != null;
LoggerSingleton.getInstance().getHytaleLogger().at(Level.SEVERE).log("Display name was Null"); assert displayNameComponent.getDisplayName() != null;
return; var name = displayNameComponent.getDisplayName().getAnsiMessage();
NotificationUtil.sendNotificationToUniverse(name);
if (Math.random() < 0.3) {
var transform = transformComponent.getTransform();
randomTeleport(commandBuffer, ref, transform.getPosition());
} }
NotificationUtil.sendNotificationToUniverse(displayNameComponent.getDisplayName());
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("Display name: " + displayNameComponent.getDisplayName());
var uuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
if (uuidComponent == null) {
LoggerSingleton.getInstance().getHytaleLogger().at(Level.SEVERE).log("UUID was Null");
return;
}
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("UUID: " + uuidComponent.getUuid());
var transform = component.getTransform();
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("Transform: "+transform);
Vector3d addPos = new Vector3d((Math.random()*20)-10, 3, (Math.random()*20)-10);
var newPos = transform.getPosition().add(addPos);
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
new Thread(()->{
store.addComponent(ref,Teleport.getComponentType(),teleportForPlayer);
}).start();
} }
@NullableDecl @NullableDecl
@Override @Override
public Query<EntityStore> getQuery() { public Query<EntityStore> getQuery() {
return Query.any(); return Query.and(TransformComponent.getComponentType(), DisplayNameComponent.getComponentType(), endermanTeleportComponentType);
} }
} }

View File

@@ -0,0 +1,48 @@
package com.tikaiz;
import com.hypixel.hytale.component.Component;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import javax.annotation.Nullable;
public class EndermanTeleportComponent implements Component<EntityStore> {
private float tickInterval = 5f;
private float elapsedTime = 0f;
public EndermanTeleportComponent(float tickInterval, float elapsedTime) {
this.tickInterval = tickInterval;
this.elapsedTime = elapsedTime;
}
public EndermanTeleportComponent() {
this(10f, 0f);
}
public EndermanTeleportComponent(EndermanTeleportComponent other) {
this.tickInterval = other.tickInterval;
this.elapsedTime = other.elapsedTime;
}
public float getTickInterval() {
return tickInterval;
}
public float getElapsedTime() {
return elapsedTime;
}
public void addElapsedTime(float dt) {
this.elapsedTime += dt;
}
public void resetElapsedTime() {
this.elapsedTime = 0f;
}
@Nullable
@Override
public Component<EntityStore> clone() {
return new EndermanTeleportComponent(this);
}
}

View File

@@ -1,31 +1,11 @@
package com.tikaiz; package com.tikaiz;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.SystemType;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.CancellableEcsEvent;
import com.hypixel.hytale.component.system.EcsEvent;
import com.hypixel.hytale.server.core.event.events.BootEvent;
import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit; import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.universe.Universe;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.events.AllWorldsLoadedEvent; import com.hypixel.hytale.server.core.universe.world.events.AllWorldsLoadedEvent;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.core.util.NotificationUtil;
import com.hypixel.hytale.server.npc.AllNPCsLoadedEvent;
import com.hypixel.hytale.server.spawning.LoadedNPCEvent;
import com.hypixel.hytale.server.spawning.assets.spawns.config.NPCSpawn;
import com.tikaiz.commands.ExampleCommand; import com.tikaiz.commands.ExampleCommand;
import jdk.jfr.EventType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.logging.Level; import java.util.logging.Level;
public class HytaleDemo extends JavaPlugin { public class HytaleDemo extends JavaPlugin {
@@ -38,15 +18,15 @@ public class HytaleDemo extends JavaPlugin {
@Override @Override
protected void setup() { protected void setup() {
this.getCommandRegistry().registerCommand(new ExampleCommand()); this.getCommandRegistry().registerCommand(new ExampleCommand());
this.getEntityStoreRegistry().registerSystem(new DamageEventSystem());
var type = this.getEntityStoreRegistry() var type = this.getEntityStoreRegistry()
.registerComponent(CustomComponent.class, CustomComponent::new); .registerComponent(EndermanTeleportComponent.class, EndermanTeleportComponent::new);
this.getEntityStoreRegistry().registerSystem(new AddDefaultComponentTickSystem(type)); this.getEntityStoreRegistry().registerSystem(new AddDefaultComponentTickSystem(type));
this.getEntityStoreRegistry().registerSystem(new CustomComponentTickSystem(type)); this.getEntityStoreRegistry().registerSystem(new CustomComponentTickSystem(type));
this.getEntityStoreRegistry().registerSystem(new DamageEventSystem(type));
// var list = new ArrayList<EntityStore>(); // var list = new ArrayList<EntityStore>();
this.getEventRegistry().registerGlobal(AllWorldsLoadedEvent.class, (x)->{ // this.getEventRegistry().registerGlobal(AllWorldsLoadedEvent.class, (x)->{
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("World has loaded!"); // LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("World has loaded!");
}); // });
// Universe.get().getDefaultWorld().getEntityStore().getStore().fetch(new SystemType<>(), Query.any(),list); // Universe.get().getDefaultWorld().getEntityStore().getStore().fetch(new SystemType<>(), Query.any(),list);
// EntityStore.REGISTRY.assertInStoreThread(); // EntityStore.REGISTRY.assertInStoreThread();
// this.getEventRegistry().registerGlobal(LoadedNPCEvent.class, (x)->{ // this.getEventRegistry().registerGlobal(LoadedNPCEvent.class, (x)->{

View File

@@ -0,0 +1,22 @@
package com.tikaiz;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
abstract class TeleportHelper {
static void randomTeleport(@NonNullDecl CommandBuffer<EntityStore> commandBuffer, Ref<EntityStore> ref, Vector3d position) {
Vector3d addPos = new Vector3d((Math.random() * 20) - 10, 3, (Math.random() * 20) - 10);
var newPos = position.add(addPos);
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
commandBuffer.addComponent(ref, Teleport.getComponentType(), teleportForPlayer);
}
}