EntityRefCollisionProvider class

Пакет: com.hypixel.hytale.server.core.modules.collision

Файл: com/hypixel/hytale/server/core/modules/collision/EntityRefCollisionProvider.java

Поля (7)

МодификаторыТипИмя
final int ALLOC_SIZE
Archetype var2
Entity var3
BoundingBox var4
TransformComponent var5
Box var6
SpatialResource var8

Методы (16)

МодификаторыВозвратСигнатура
protected void acceptNearestIgnorevoid acceptNearestIgnore(@Nonnull Ref<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2)
public void clearvoid clear()
protected void clearRefsvoid clearRefs()
public double computeNearestdouble computeNearest(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Box var2, @Nonnull Vector3d var3, @Nonnull Vector3d var4, @Nullable Ref<EntityStore> var5, @Nullable Ref<EntityStore> var6)
public double computeNearestdouble computeNearest(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Vector3d var2, @Nonnull Vector3d var3, @Nonnull Box var4, double var5, @Nonnull BiPredicate<Ref<EntityStore>, CommandBuffer<EntityStore>> var7, @Nullable Ref<EntityStore> var8, @Nullable Ref<EntityStore> var9)
static boolean defaultEntityFilterboolean defaultEntityFilter(@Nonnull Ref<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1)
for for(int var1 = 0; var1 < this.contacts.length; var1++)
for for(int var1 = 0; var1 < this.count; var1++)
for for(Ref var10 : this.tmpResults)
public int getCountint getCount()
if if(this.count == 0)
if if(var4 == null)
if if(var5 == null)
protected boolean isCollidingboolean isColliding(@Nonnull Ref<EntityStore> var1, @Nonnull Vector2d var2, @Nonnull CommandBuffer<EntityStore> var3)
protected void iterateEntitiesInSpherevoid iterateEntitiesInSphere(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Vector3d var2, @Nonnull Vector3d var3, @Nonnull Box var4, double var5, @Nonnull TriConsumer<EntityRefCollisionProvider, Ref<EntityStore>, CommandBuffer<EntityStore>> var7)
protected void setContactvoid setContact(@Nonnull Ref<EntityStore> var1, @Nonnull String var2)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.collision;

class="kw">import com.hypixel.hytale.component.Archetype;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.spatial.SpatialResource;
class="kw">import com.hypixel.hytale.function.consumer.TriConsumer;
class="kw">import com.hypixel.hytale.math.shape.Box;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.DetailBox;
class="kw">import com.hypixel.hytale.server.core.entity.Entity;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
class="kw">import com.hypixel.hytale.server.core.modules.projectile.component.Projectile;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
class="kw">import java.util.List;
class="kw">import java.util.Map.Entry;
class="kw">import java.util.function.BiPredicate;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector2d;
class="kw">import org.joml.Vector3d;

class="kw">public class EntityRefCollisionProvider {
   class="kw">protected class="kw">static class="kw">final int ALLOC_SIZE = 4;
   class="kw">protected class="kw">static class="kw">final double EXTRA_DISTANCE = 8.0;
   class="kw">protected EntityContactData[] contacts;
   class="kw">protected EntityContactData[] sortBuffer;
   class="kw">protected int count;
   class="kw">protected class="kw">final Vector2d minMax = new Vector2d();
   class="kw">protected class="kw">final Vector3d collisionPosition = new Vector3d();
   class="kw">protected class="kw">final Box tempBox = new Box();
   class="kw">protected double nearestCollisionStart;
   @Nullable
   class="kw">protected Vector3d position;
   @Nullable
   class="kw">protected Vector3d direction;
   @Nullable
   class="kw">protected Box boundingBox;
   @Nullable
   class="kw">protected BiPredicate<Ref<EntityStore>, CommandBuffer<EntityStore>> entityFilter;
   @Nullable
   class="kw">protected Ref<EntityStore> ignoreSelf;
   @Nullable
   class="kw">protected Ref<EntityStore> ignoreOther;
   @Nonnull
   class="kw">protected List<Ref<EntityStore>> tmpResults = new ReferenceArrayList();
   @Nonnull
   class="kw">protected Vector3d tmpVector = new Vector3d();
   @Nullable
   class="kw">protected String hitDetail;

   class="kw">public EntityRefCollisionProvider() {
      this.contacts = new EntityContactData[4];
      this.sortBuffer = new EntityContactData[4];

      for (int var1 = 0; var1 < this.contacts.length; var1++) {
         this.contacts[var1] = new EntityContactData();
      }
   }

   class="kw">public int getCount() {
      class="kw">return this.count;
   }

   @Nonnull
   class="kw">public EntityContactData getContact(int var1) {
      class="kw">return this.contacts[var1];
   }

   class="kw">public void clear() {
      for (int var1 = 0; var1 < this.count; var1++) {
         this.contacts[var1].clear();
      }

      this.count = 0;
   }

   class="kw">public double computeNearest(
      @Nonnull CommandBuffer<EntityStore> var1,
      @Nonnull Box var2,
      @Nonnull Vector3d var3,
      @Nonnull Vector3d var4,
      @Nullable Ref<EntityStore> var5,
      @Nullable Ref<EntityStore> var6
   ) {
      class="kw">return this.computeNearest(var1, var3, var4, var2, var4.length() + 8.0, EntityRefCollisionProvider::defaultEntityFilter, var5, var6);
   }

   class="kw">public double computeNearest(
      @Nonnull CommandBuffer<EntityStore> var1,
      @Nonnull Vector3d var2,
      @Nonnull Vector3d var3,
      @Nonnull Box var4,
      double var5,
      @Nonnull BiPredicate<Ref<EntityStore>, CommandBuffer<EntityStore>> var7,
      @Nullable Ref<EntityStore> var8,
      @Nullable Ref<EntityStore> var9
   ) {
      this.ignoreSelf = var8;
      this.ignoreOther = var9;
      this.nearestCollisionStart = Double.MAX_VALUE;
      this.entityFilter = var7;
      this.iterateEntitiesInSphere(var1, var2, var3, var4, var5, EntityRefCollisionProvider::acceptNearestIgnore);
      if (this.count == 0) {
         this.nearestCollisionStart = -Double.MAX_VALUE;
      }

      this.clearRefs();
      this.ignoreSelf = null;
      this.ignoreOther = null;
      class="kw">return this.nearestCollisionStart;
   }

   class="kw">protected void iterateEntitiesInSphere(
      @Nonnull CommandBuffer<EntityStore> var1,
      @Nonnull Vector3d var2,
      @Nonnull Vector3d var3,
      @Nonnull Box var4,
      double var5,
      @Nonnull TriConsumer<EntityRefCollisionProvider, Ref<EntityStore>, CommandBuffer<EntityStore>> var7
   ) {
      this.position = var2;
      this.direction = var3;
      this.boundingBox = var4;
      SpatialResource var8 = var1.getResource(CollisionModule.get().getTangibleEntitySpatialResourceType());
      this.tmpResults.clear();
      var8.getSpatialStructure().collect(var2, var5, this.tmpResults);

      for (Ref var10 : this.tmpResults) {
         var7.accept(this, var10, var1);
      }
   }

   class="kw">protected void setContact(@Nonnull Ref<EntityStore> var1, @Nonnull String var2) {
      this.collisionPosition.set(this.position).fma(this.minMax.x, this.direction);
      this.contacts[0].assign(this.collisionPosition, this.minMax.x, this.minMax.y, var1, var2);
      this.count = 1;
   }

   class="kw">protected boolean isColliding(@Nonnull Ref<EntityStore> var1, @Nonnull Vector2d var2, @Nonnull CommandBuffer<EntityStore> var3) {
      BoundingBox var4 = var3.getComponent(var1, BoundingBox.getComponentType());
      if (var4 == null) {
         class="kw">return false;
      }

      TransformComponent var5 = var3.getComponent(var1, TransformComponent.getComponentType());
      if (var5 == null) {
         class="kw">return false;
      }

      Box var6 = var4.getBoundingBox();
      if (var4.getDetailBoxes() != null && !var4.getDetailBoxes().isEmpty()) {
         for (Entry var8 : var4.getDetailBoxes().entrySet()) {
            for (DetailBox var12 : var8.getValue()) {
               this.tmpVector.set(var12.getOffset());
               this.tmpVector.rotateY(var5.getRotation().yaw());
               this.tmpVector.add(var5.getPosition());
               if (CollisionMath.intersectSweptAABBs(this.position, this.direction, this.boundingBox, this.tmpVector, var12.getBox(), var2, this.tempBox)
                  && var2.x <= 1.0) {
                  this.hitDetail = var8.getKey();
                  class="kw">return true;
               }
            }
         }

         this.hitDetail = null;
         class="kw">return false;
      } else {
         this.hitDetail = null;
         class="kw">return CollisionMath.intersectSweptAABBs(this.position, this.direction, this.boundingBox, var5.getPosition(), var6, var2, this.tempBox)
            && var2.x <= 1.0;
      }
   }

   class="kw">protected void clearRefs() {
      this.position = null;
      this.direction = null;
      this.boundingBox = null;
      this.entityFilter = null;
   }

   class="kw">public class="kw">static boolean defaultEntityFilter(@Nonnull Ref<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1) {
      if (!var0.isValid()) {
         class="kw">return false;
      }

      Archetype var2 = var1.getArchetype(var0);
      if (var2.contains(Projectile.getComponentType())) {
         class="kw">return false;
      }

      if (var2.contains(DeathComponent.getComponentType())) {
         class="kw">return false;
      }

      Entity var3 = EntityUtils.getEntity(var0, var1);
      class="kw">return var3 == null || var3.isCollidable();
   }

   class="kw">protected void acceptNearestIgnore(@Nonnull Ref<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2) {
      if (this.entityFilter.test(var1, var2)
         && !var1.equals(this.ignoreSelf)
         && !var1.equals(this.ignoreOther)
         && this.isColliding(var1, this.minMax, var2)
         && this.minMax.x < this.nearestCollisionStart) {
         this.nearestCollisionStart = this.minMax.x;
         this.setContact(var1, this.hitDetail);
      }
   }
}