Improved Performance
This commit is contained in:
@@ -7,7 +7,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class EndermanTeleportComponent implements Component<EntityStore> {
|
||||
|
||||
private final float tickInterval;
|
||||
private float tickInterval;
|
||||
private float elapsedTime;
|
||||
|
||||
public EndermanTeleportComponent(float tickInterval, float elapsedTime) {
|
||||
@@ -17,6 +17,7 @@ public class EndermanTeleportComponent implements Component<EntityStore> {
|
||||
|
||||
public EndermanTeleportComponent() {
|
||||
this(10f, 0f);
|
||||
randomizeTickInterval();
|
||||
}
|
||||
|
||||
public EndermanTeleportComponent(EndermanTeleportComponent other) {
|
||||
@@ -46,4 +47,8 @@ public class EndermanTeleportComponent implements Component<EntityStore> {
|
||||
public Component<EntityStore> clone() {
|
||||
return new EndermanTeleportComponent(this);
|
||||
}
|
||||
|
||||
public void randomizeTickInterval() {
|
||||
tickInterval = (float) ((Math.random()*5)+25);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
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 {
|
||||
|
||||
@@ -9,4 +15,12 @@ public abstract class TeleportHelper {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AddEndermanTeleportComponentTickSystem extends EntityTickingSystem<EntityStore> {
|
||||
private final ComponentType<EntityStore, EndermanTeleportComponent> customComponentType;
|
||||
private final ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType;
|
||||
|
||||
public AddEndermanTeleportComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> poisonComponentType) {
|
||||
this.customComponentType = poisonComponentType;
|
||||
public AddEndermanTeleportComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType) {
|
||||
this.endermanComponentType = endermanComponentType;
|
||||
}
|
||||
@Override
|
||||
public void tick(float dt,
|
||||
@@ -25,25 +25,20 @@ public class AddEndermanTeleportComponentTickSystem extends EntityTickingSystem<
|
||||
@NonNullDecl Store<EntityStore> store,
|
||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
||||
EndermanTeleportComponent component = store.getComponent(ref, customComponentType);
|
||||
if (component != null) {
|
||||
return;
|
||||
}
|
||||
DisplayNameComponent displayNameComponent = store.getComponent(ref, DisplayNameComponent.getComponentType());
|
||||
if (displayNameComponent == null || displayNameComponent.getDisplayName() == null) {
|
||||
return;
|
||||
}
|
||||
assert displayNameComponent != null;
|
||||
assert displayNameComponent.getDisplayName() != null;
|
||||
var displayName = displayNameComponent.getDisplayName().getAnsiMessage();
|
||||
if (!"Bunny".equals(displayName)){
|
||||
return;
|
||||
}
|
||||
commandBuffer.addComponent(ref, customComponentType, new EndermanTeleportComponent());
|
||||
commandBuffer.addComponent(ref, endermanComponentType, new EndermanTeleportComponent());
|
||||
LoggerSingleton.getInstance().getHytaleLogger().at(Level.INFO).log("Added Component to ref: " + displayName);
|
||||
}
|
||||
|
||||
@NullableDecl
|
||||
@Override
|
||||
public Query<EntityStore> getQuery() {
|
||||
return Query.and(DisplayNameComponent.getComponentType());
|
||||
return Query.and(DisplayNameComponent.getComponentType(),Query.not(endermanComponentType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ 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;
|
||||
import static com.tikaiz.helpers.TeleportHelper.randomTeleport;
|
||||
|
||||
public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> {
|
||||
@@ -37,12 +38,7 @@ public class DamageEventSystem extends EntityEventSystem<EntityStore, Damage> {
|
||||
assert transformComponent != null;
|
||||
|
||||
if (Math.random() < 0.3) {
|
||||
var transform = transformComponent.getTransform();
|
||||
ParticleUtil.spawnParticleEffect("Effect_Death",transform.getPosition(),commandBuffer);
|
||||
Vector3d newPos = randomTeleport(transform.getPosition());
|
||||
ParticleUtil.spawnParticleEffect("Effect_Death",transform.getPosition(),commandBuffer);
|
||||
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
|
||||
commandBuffer.addComponent(ref, Teleport.getComponentType(), teleportForPlayer);
|
||||
EndermanTeleport(ref,transformComponent.getPosition(),commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,23 +3,19 @@ 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.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 com.tikaiz.components.EndermanTeleportComponent;
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
import static com.tikaiz.helpers.TeleportHelper.randomTeleport;
|
||||
import static com.tikaiz.helpers.TeleportHelper.EndermanTeleport;
|
||||
|
||||
public class EndermanComponentTickSystem extends EntityTickingSystem<EntityStore> {
|
||||
private final ComponentType<EntityStore, EndermanTeleportComponent> customComponentType;
|
||||
private final ComponentType<EntityStore, EndermanTeleportComponent> endermanComponentType;
|
||||
|
||||
public EndermanComponentTickSystem(ComponentType<EntityStore, EndermanTeleportComponent> poisonComponentType) {
|
||||
this.customComponentType = poisonComponentType;
|
||||
this.endermanComponentType = poisonComponentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,7 +25,7 @@ public class EndermanComponentTickSystem extends EntityTickingSystem<EntityStore
|
||||
@NonNullDecl Store<EntityStore> store,
|
||||
@NonNullDecl CommandBuffer<EntityStore> commandBuffer) {
|
||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(i);
|
||||
EndermanTeleportComponent endermanTeleportComponent = store.getComponent(ref, customComponentType);
|
||||
EndermanTeleportComponent endermanTeleportComponent = store.getComponent(ref, endermanComponentType);
|
||||
assert endermanTeleportComponent != null;
|
||||
var transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
|
||||
assert transformComponent != null;
|
||||
@@ -38,12 +34,8 @@ public class EndermanComponentTickSystem extends EntityTickingSystem<EntityStore
|
||||
endermanTeleportComponent.addElapsedTime(dt);
|
||||
if (endermanTeleportComponent.getElapsedTime() >= endermanTeleportComponent.getTickInterval()) {
|
||||
endermanTeleportComponent.resetElapsedTime();
|
||||
ParticleUtil.spawnParticleEffect("Effect_Death",transformComponent.getPosition(),commandBuffer);
|
||||
Vector3d newPos = randomTeleport(transformComponent.getPosition());
|
||||
ParticleUtil.spawnParticleEffect("Effect_Death",transformComponent.getPosition(),commandBuffer);
|
||||
|
||||
Teleport teleportForPlayer = Teleport.createForPlayer(newPos, new Vector3f());
|
||||
commandBuffer.addComponent(ref, Teleport.getComponentType(), teleportForPlayer);
|
||||
endermanTeleportComponent.randomizeTickInterval();
|
||||
EndermanTeleport(ref,transformComponent.getPosition(),commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +43,6 @@ public class EndermanComponentTickSystem extends EntityTickingSystem<EntityStore
|
||||
@NullableDecl
|
||||
@Override
|
||||
public Query<EntityStore> getQuery() {
|
||||
return Query.and(customComponentType, TransformComponent.getComponentType());
|
||||
return Query.and(endermanComponentType, TransformComponent.getComponentType());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user