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