added source code
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -4,8 +4,8 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.tikaiz</groupId>
|
<groupId>com.greiflo</groupId>
|
||||||
<artifactId>HytaleDemo</artifactId>
|
<artifactId>EndermanPlugin</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.1.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -1,29 +1,24 @@
|
|||||||
package com.tikaiz.systems;
|
package com.greiflo;
|
||||||
|
|
||||||
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.logger.HytaleLogger;
|
|
||||||
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.universe.world.storage.EntityStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||||
import com.tikaiz.components.EndermanTeleportComponent;
|
|
||||||
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;
|
public class AddComponentsEnderman extends EntityTickingSystem<EntityStore> {
|
||||||
|
|
||||||
public class AddEndermanTeleportComponentTickSystem extends EntityTickingSystem<EntityStore> {
|
|
||||||
private final ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType;
|
|
||||||
|
|
||||||
public AddEndermanTeleportComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType) {
|
private final ComponentType<EntityStore, EndermanComponent> endermanComponentType;
|
||||||
|
|
||||||
|
public AddComponentsEnderman(ComponentType<EntityStore, EndermanComponent> endermanComponentType) {
|
||||||
this.endermanComponentType = endermanComponentType;
|
this.endermanComponentType = endermanComponentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(float dt,
|
public void tick(float v, int i, @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk, @NonNullDecl Store<EntityStore> store, @NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
||||||
int i,
|
|
||||||
@NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
|
|
||||||
@NonNullDecl Store<EntityStore> store,
|
|
||||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
|
||||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
||||||
DisplayNameComponent displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType());
|
DisplayNameComponent displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType());
|
||||||
assert displayNameComponent != null;
|
assert displayNameComponent != null;
|
||||||
@@ -32,8 +27,7 @@ public class AddEndermanTeleportComponentTickSystem extends EntityTickingSystem<
|
|||||||
if (!"Enderman".equals(displayName)){
|
if (!"Enderman".equals(displayName)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commandBuffer.addComponent(ref, endermanComponentType, new EndermanTeleportComponent());
|
commandBuffer.addComponent(ref, endermanComponentType, new EndermanComponent());
|
||||||
// HytaleLogger.getLogger().atInfo().log("Added Component to ref: " + displayName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NullableDecl
|
@NullableDecl
|
||||||
@@ -1,26 +1,26 @@
|
|||||||
package com.tikaiz.components;
|
package com.greiflo;
|
||||||
|
|
||||||
import com.hypixel.hytale.component.Component;
|
import com.hypixel.hytale.component.Component;
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class EndermanTeleportComponent implements Component<EntityStore> {
|
public class EndermanComponent implements Component<EntityStore> {
|
||||||
|
|
||||||
private float tickInterval;
|
private float tickInterval;
|
||||||
private float elapsedTime;
|
private float elapsedTime;
|
||||||
|
|
||||||
public EndermanTeleportComponent(float tickInterval, float elapsedTime) {
|
public EndermanComponent(float tickInterval, float elapsedTime) {
|
||||||
this.tickInterval = tickInterval;
|
this.tickInterval = tickInterval;
|
||||||
this.elapsedTime = elapsedTime;
|
this.elapsedTime = elapsedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndermanTeleportComponent() {
|
public EndermanComponent() {
|
||||||
this(10f, 0f);
|
this(10f, 0f);
|
||||||
randomizeTickInterval();
|
randomizeTickInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndermanTeleportComponent(EndermanTeleportComponent other) {
|
public EndermanComponent(EndermanComponent other) {
|
||||||
this.tickInterval = other.tickInterval;
|
this.tickInterval = other.tickInterval;
|
||||||
this.elapsedTime = other.elapsedTime;
|
this.elapsedTime = other.elapsedTime;
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ public class EndermanTeleportComponent implements Component<EntityStore> {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Component<EntityStore> clone() {
|
public Component<EntityStore> clone() {
|
||||||
return new EndermanTeleportComponent(this);
|
return new EndermanComponent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void randomizeTickInterval() {
|
public void randomizeTickInterval() {
|
||||||
tickInterval = (float) ((Math.random()*20)+10);
|
tickInterval = (float) ((Math.random()*25)+5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
61
src/main/java/com/greiflo/EndermanDamageHandler.java
Normal file
61
src/main/java/com/greiflo/EndermanDamageHandler.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package com.greiflo;
|
||||||
|
|
||||||
|
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||||
|
import com.hypixel.hytale.component.CommandBuffer;
|
||||||
|
import com.hypixel.hytale.component.ComponentType;
|
||||||
|
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.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.universe.world.storage.EntityStore;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
import static com.greiflo.EndermanTeleportTickingSystem.EndermanTeleport;
|
||||||
|
|
||||||
|
public class EndermanDamageHandler extends EntityEventSystem<EntityStore, Damage> {
|
||||||
|
|
||||||
|
|
||||||
|
protected EndermanDamageHandler(ComponentType<EntityStore, EndermanComponent> endermanComponentType) {
|
||||||
|
super(Damage.class);
|
||||||
|
this.endermanComponentType = endermanComponentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ComponentType<EntityStore, EndermanComponent> endermanComponentType;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(int i, @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk, @NonNullDecl Store<EntityStore> store, @NonNullDecl CommandBuffer<EntityStore> commandBuffer, @NonNullDecl Damage damage) {
|
||||||
|
var ref = archetypeChunk.getReferenceTo(i);
|
||||||
|
TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
|
||||||
|
EndermanComponent endermanTeleportComponent = store.getComponent(ref, endermanComponentType);
|
||||||
|
|
||||||
|
var entityName = store.getComponent(ref, DisplayNameComponent.getComponentType());
|
||||||
|
|
||||||
|
var teleportChance = Math.random()*100;
|
||||||
|
|
||||||
|
if (endermanTeleportComponent != null) {
|
||||||
|
endermanTeleportComponent.resetElapsedTime();
|
||||||
|
}
|
||||||
|
var chance = (int)teleportChance;
|
||||||
|
if(chance > 15) return;
|
||||||
|
|
||||||
|
//if(entityName != null && entityName.getDisplayName() != null) NotificationUtil.sendNotificationToUniverse(entityName.getDisplayName());
|
||||||
|
|
||||||
|
if(entityName == null || entityName.getDisplayName() == null) return;
|
||||||
|
var raw = entityName.getDisplayName().getAnsiMessage();
|
||||||
|
//NotificationUtil.sendNotificationToUniverse(raw);
|
||||||
|
|
||||||
|
if(!"Enderman".equals(raw)) return;
|
||||||
|
|
||||||
|
EndermanTeleport(ref, transformComponent.getPosition(), commandBuffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NullableDecl
|
||||||
|
@Override
|
||||||
|
public Query<EntityStore> getQuery() {
|
||||||
|
return Query.any();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/main/java/com/greiflo/EndermanPlugin.java
Normal file
24
src/main/java/com/greiflo/EndermanPlugin.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.greiflo;
|
||||||
|
|
||||||
|
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 javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class EndermanPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
public EndermanPlugin(@Nonnull JavaPluginInit init) {
|
||||||
|
super(init);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setup() {
|
||||||
|
var type = this.getEntityStoreRegistry()
|
||||||
|
.registerComponent(EndermanComponent.class, EndermanComponent::new);
|
||||||
|
this.getEntityStoreRegistry().registerSystem(new AddComponentsEnderman(type));
|
||||||
|
this.getEntityStoreRegistry().registerSystem(new EndermanTeleportTickingSystem(type));
|
||||||
|
this.getEntityStoreRegistry().registerSystem(new EndermanDamageHandler(type));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/main/java/com/greiflo/EndermanTeleportTickingSystem.java
Normal file
58
src/main/java/com/greiflo/EndermanTeleportTickingSystem.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package com.greiflo;
|
||||||
|
|
||||||
|
import com.hypixel.hytale.component.*;
|
||||||
|
import com.hypixel.hytale.component.query.Query;
|
||||||
|
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.TransformComponent;
|
||||||
|
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.ParticleUtil;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
public class EndermanTeleportTickingSystem extends EntityTickingSystem<EntityStore> {
|
||||||
|
private final ComponentType<EntityStore, EndermanComponent> endermanComponentType;
|
||||||
|
|
||||||
|
public EndermanTeleportTickingSystem(ComponentType<EntityStore, EndermanComponent> endermanComponentType) {
|
||||||
|
this.endermanComponentType = endermanComponentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(float dt, int i, @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk, @NonNullDecl Store<EntityStore> store, @NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
||||||
|
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
||||||
|
EndermanComponent endermanTeleportComponent = store.getComponent(ref, endermanComponentType);
|
||||||
|
assert endermanTeleportComponent != null;
|
||||||
|
var transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
|
||||||
|
assert transformComponent != null;
|
||||||
|
|
||||||
|
|
||||||
|
endermanTeleportComponent.addElapsedTime(dt);
|
||||||
|
if (endermanTeleportComponent.getElapsedTime() >= endermanTeleportComponent.getTickInterval()) {
|
||||||
|
endermanTeleportComponent.resetElapsedTime();
|
||||||
|
endermanTeleportComponent.randomizeTickInterval();
|
||||||
|
EndermanTeleport(ref, transformComponent.getPosition(), commandBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3d randomTeleport(Vector3d position) {
|
||||||
|
Vector3d addPos = new Vector3d((Math.random() * 20) - 10, 3, (Math.random() * 20) - 10);
|
||||||
|
|
||||||
|
return position.add(addPos);
|
||||||
|
}
|
||||||
|
public static void EndermanTeleport(Ref<EntityStore> ref, Vector3d position, CommandBuffer<EntityStore> commandBuffer) {
|
||||||
|
ParticleUtil.spawnParticleEffect("Effect_Death",position,commandBuffer);
|
||||||
|
Vector3d newPos = randomTeleport(position);
|
||||||
|
ParticleUtil.spawnParticleEffect("Effect_Death",position,commandBuffer);
|
||||||
|
|
||||||
|
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
|
||||||
|
commandBuffer.addComponent(ref, Teleport.getComponentType(), teleportForPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NullableDecl
|
||||||
|
@Override
|
||||||
|
public Query<EntityStore> getQuery() {
|
||||||
|
return Query.and(endermanComponentType, TransformComponent.getComponentType());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.tikaiz;
|
|
||||||
|
|
||||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
|
||||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
|
||||||
import com.tikaiz.commands.ExampleCommand;
|
|
||||||
import com.tikaiz.components.EndermanTeleportComponent;
|
|
||||||
import com.tikaiz.systems.AddEndermanTeleportComponentTickSystem;
|
|
||||||
import com.tikaiz.systems.EndermanComponentTickSystem;
|
|
||||||
import com.tikaiz.systems.DamageEventSystem;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class HytaleDemo extends JavaPlugin {
|
|
||||||
|
|
||||||
public HytaleDemo(@Nonnull JavaPluginInit init) {
|
|
||||||
super(init);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setup() {
|
|
||||||
this.getCommandRegistry().registerCommand(new ExampleCommand());
|
|
||||||
var type = this.getEntityStoreRegistry()
|
|
||||||
.registerComponent(EndermanTeleportComponent.class, EndermanTeleportComponent::new);
|
|
||||||
this.getEntityStoreRegistry().registerSystem(new AddEndermanTeleportComponentTickSystem(type));
|
|
||||||
this.getEntityStoreRegistry().registerSystem(new EndermanComponentTickSystem(type));
|
|
||||||
this.getEntityStoreRegistry().registerSystem(new DamageEventSystem(type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.tikaiz.commands;
|
|
||||||
|
|
||||||
import com.hypixel.hytale.component.Ref;
|
|
||||||
import com.hypixel.hytale.component.Store;
|
|
||||||
import com.hypixel.hytale.math.vector.Vector3d;
|
|
||||||
import com.hypixel.hytale.math.vector.Vector3f;
|
|
||||||
import com.hypixel.hytale.server.core.Message;
|
|
||||||
import com.hypixel.hytale.server.core.command.system.CommandContext;
|
|
||||||
import com.hypixel.hytale.server.core.command.system.arguments.system.DefaultArg;
|
|
||||||
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
|
|
||||||
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
|
|
||||||
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.PlayerRef;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.World;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ExampleCommand extends AbstractPlayerCommand {
|
|
||||||
|
|
||||||
public ExampleCommand() {
|
|
||||||
super("tel", "Super test command!");
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultArg<List<Double>> arg = this.withListDefaultArg("Pos", "Position", ArgTypes.DOUBLE, new ArrayList<>(),"Tell the Player the Position");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(@Nonnull CommandContext commandContext,
|
|
||||||
@Nonnull Store<EntityStore> store,
|
|
||||||
@Nonnull Ref<EntityStore> ref,
|
|
||||||
@Nonnull PlayerRef playerRef,
|
|
||||||
@Nonnull World world) {
|
|
||||||
int size = arg.get(commandContext).size();
|
|
||||||
playerRef.sendMessage(Message.raw("Arg size: " + size));
|
|
||||||
if (!(size == 3 || size == 0)){
|
|
||||||
|
|
||||||
playerRef.sendMessage(Message.raw("Either specify 0 or 3 Arguments"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var transform = store.getComponent(ref, TransformComponent.getComponentType());
|
|
||||||
if (transform == null) return;
|
|
||||||
if (size == 0){
|
|
||||||
var pos = transform.getPosition();
|
|
||||||
playerRef.sendMessage(Message.raw("Player Position: " + pos));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var x = arg.get(commandContext).get(0);
|
|
||||||
var y = arg.get(commandContext).get(1);
|
|
||||||
var z = arg.get(commandContext).get(2);
|
|
||||||
|
|
||||||
var newPos = new Vector3d(x,y,z);
|
|
||||||
|
|
||||||
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
|
|
||||||
store.addComponent(ref,Teleport.getComponentType(),teleportForPlayer);
|
|
||||||
|
|
||||||
playerRef.sendMessage(Message.raw("Set Player Position to: " + newPos));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.tikaiz.helpers;
|
|
||||||
|
|
||||||
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.teleport.Teleport;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.ParticleUtil;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
|
||||||
|
|
||||||
public abstract class TeleportHelper {
|
|
||||||
|
|
||||||
public static Vector3d randomTeleport(Vector3d position) {
|
|
||||||
Vector3d addPos = new Vector3d((Math.random() * 20) - 10, 3, (Math.random() * 20) - 10);
|
|
||||||
|
|
||||||
return position.add(addPos);
|
|
||||||
}
|
|
||||||
public static void EndermanTeleport(Ref<EntityStore> ref, Vector3d position, CommandBuffer<EntityStore> commandBuffer) {
|
|
||||||
ParticleUtil.spawnParticleEffect("Effect_Death",position,commandBuffer);
|
|
||||||
Vector3d newPos = randomTeleport(position);
|
|
||||||
ParticleUtil.spawnParticleEffect("Effect_Death",position,commandBuffer);
|
|
||||||
|
|
||||||
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
|
|
||||||
commandBuffer.addComponent(ref, Teleport.getComponentType(), teleportForPlayer);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.tikaiz.systems;
|
|
||||||
|
|
||||||
import com.hypixel.hytale.component.*;
|
|
||||||
import com.hypixel.hytale.component.query.Query;
|
|
||||||
import com.hypixel.hytale.component.system.EntityEventSystem;
|
|
||||||
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.universe.world.storage.EntityStore;
|
|
||||||
import com.tikaiz.components.EndermanTeleportComponent;
|
|
||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
|
||||||
|
|
||||||
import static com.tikaiz.helpers.TeleportHelper.EndermanTeleport;
|
|
||||||
|
|
||||||
public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> {
|
|
||||||
private final ComponentType<EntityStore, EndermanTeleportComponent> endermanTeleportComponentType;
|
|
||||||
|
|
||||||
public DamageEventSystem(ComponentType<EntityStore, EndermanTeleportComponent> type) {
|
|
||||||
super(Damage.class);
|
|
||||||
this.endermanTeleportComponentType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(int i,
|
|
||||||
@NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
|
|
||||||
@NonNullDecl Store<EntityStore> store,
|
|
||||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer,
|
|
||||||
@NonNullDecl Damage damage) {
|
|
||||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
|
||||||
var transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
|
|
||||||
assert transformComponent != null;
|
|
||||||
var endermanComponent = store.getComponent(ref, endermanTeleportComponentType);
|
|
||||||
assert endermanComponent != null;
|
|
||||||
|
|
||||||
endermanComponent.resetElapsedTime();
|
|
||||||
if (Math.random() < 0.15) {
|
|
||||||
EndermanTeleport(ref,transformComponent.getPosition(),commandBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NullableDecl
|
|
||||||
@Override
|
|
||||||
public Query<EntityStore> getQuery() {
|
|
||||||
return Query.and(TransformComponent.getComponentType(), endermanTeleportComponentType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.tikaiz.systems;
|
|
||||||
|
|
||||||
import com.hypixel.hytale.component.*;
|
|
||||||
import com.hypixel.hytale.component.query.Query;
|
|
||||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
|
||||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
|
||||||
import com.tikaiz.components.EndermanTeleportComponent;
|
|
||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
|
||||||
|
|
||||||
import static com.tikaiz.helpers.TeleportHelper.EndermanTeleport;
|
|
||||||
|
|
||||||
public class EndermanComponentTickSystem extends EntityTickingSystem<EntityStore> {
|
|
||||||
private final ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType;
|
|
||||||
|
|
||||||
public EndermanComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> poisonComponentType) {
|
|
||||||
this.endermanComponentType = poisonComponentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(float dt,
|
|
||||||
int i,
|
|
||||||
@NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
|
|
||||||
@NonNullDecl Store<EntityStore> store,
|
|
||||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
|
||||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
|
||||||
EndermanTeleportComponent endermanTeleportComponent = store.getComponent(ref, endermanComponentType);
|
|
||||||
assert endermanTeleportComponent != null;
|
|
||||||
var transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
|
|
||||||
assert transformComponent != null;
|
|
||||||
|
|
||||||
|
|
||||||
endermanTeleportComponent.addElapsedTime(dt);
|
|
||||||
if (endermanTeleportComponent.getElapsedTime() >= endermanTeleportComponent.getTickInterval()) {
|
|
||||||
endermanTeleportComponent.resetElapsedTime();
|
|
||||||
endermanTeleportComponent.randomizeTickInterval();
|
|
||||||
EndermanTeleport(ref,transformComponent.getPosition(),commandBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@NullableDecl
|
|
||||||
@Override
|
|
||||||
public Query<EntityStore> getQuery() {
|
|
||||||
return Query.and(endermanComponentType, TransformComponent.getComponentType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
{
|
{
|
||||||
"Group": "com.tikaiz",
|
"Group": "com.greiflo",
|
||||||
"Name": "Hytale Plugin Demo",
|
"Name": "EndermanPlugin",
|
||||||
"Version": "${version}",
|
"Version": "${version}",
|
||||||
"Description": "Description of your plugin",
|
"Description": "Enderman Plugin",
|
||||||
"Authors": [
|
"Authors": [
|
||||||
{
|
{
|
||||||
"Name": "Tikaiz",
|
"Name": "greiflo",
|
||||||
|
"Email": "grflo7228@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "tikaiz",
|
||||||
"Email": "tikaiz@gmx.at"
|
"Email": "tikaiz@gmx.at"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"Website": "",
|
||||||
"ServerVersion": "*",
|
"ServerVersion": "*",
|
||||||
"Dependencies": {},
|
"Dependencies": {},
|
||||||
"OptionalDependencies": {},
|
"OptionalDependencies": {},
|
||||||
"DisabledByDefault": false,
|
"DisabledByDefault": false,
|
||||||
"IncludesAssetPack": false,
|
"IncludesAssetPack": false,
|
||||||
"Main": "com.tikaiz.HytaleDemo"
|
"Main": "com.greiflo.EndermanPlugin"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user