BreakShape class

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

Файл: com/hypixel/hytale/server/core/modules/interaction/breakshape/BreakShape.java

implements: NetworkSerializable<com.hypixel.hytale.protocol.BreakShape>

Поля (30)

МодификаторыТипИмя
final int MAX_DIMENSION
long var1
int var10
int var10
double var10
int var11
int var11
double var11
int var12
int var12
double var12
int var13
double var13
double var14
Vector3d var16
double var17
double var19
double var21
Vector3d var4
Vector3i var5
Vector3i var6
int var6
HeadRotation var6
Vector3i var7
TransformComponent var7
int var8
float var8
int var9
double var9
Vector3d var9

Методы (24)

МодификаторыВозвратСигнатура
static void computeSurfaceBasisvoid computeSurfaceBasis(@Nonnull CommandBuffer<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull Vector3i var2, @Nonnull Vector3i var3, @Nonnull Vector3i var4, @Nonnull Vector3i var5)
abstract computeSurfaceBasis computeSurfaceBasis(var1, var2, var3, var5, var6, var7)
static void computeViewBasisvoid computeViewBasis(@Nullable HeadRotation var0, @Nonnull Vector3i var1, @Nonnull Vector3i var2, @Nonnull Vector3i var3)
static void computeViewBasisvoid computeViewBasis(double var0, double var2, double var4, @Nonnull Vector3i var6, @Nonnull Vector3i var7, @Nonnull Vector3i var8)
abstract computeViewBasis computeViewBasis(0.0, -1.0, 0.0, var1, var2, var3)
abstract computeViewBasis computeViewBasis(var6, var3, var4, var5)
static double entryDistancedouble entryDistance(double var0, double var2, int var4)
abstract abstract void forEachLocalOffsetvoid forEachLocalOffset(@Nonnull TriIntConsumer var1)
public int getDepthint getDepth()
public int getHeightint getHeight()
public int getWidthint getWidth()
if if(var3 != null)
if if(this.orientation == BreakShapeOrientation.Surface)
if if(var1 > 1024L)
if if(var0 != null)
if if(var11 >= var9 && var11 >= var13)
if if(var6 != null && var7 != null)
if if(var19 >= var17 && var19 >= var21)
if if(var2 > 0.0)
public boolean isCenteredboolean isCentered()
static int lowBoundint lowBound(int var0, boolean var1)
public void selectBlocksvoid selectBlocks(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Ref<EntityStore> var2, @Nullable Vector3i var3, @Nonnull TriIntConsumer var4)
protected void validateShapevoid validateShape()
static void verticalUpvoid verticalUp(double var0, double var2, int var4, @Nonnull Vector3i var5)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.codec.lookup.CodecMapCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.function.consumer.TriIntConsumer;
class="kw">import com.hypixel.hytale.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.protocol.BreakShapeOrientation;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3f;
class="kw">import org.joml.Vector3i;

class="kw">public class="kw">abstract class BreakShape class="kw">implements NetworkSerializable<com.hypixel.hytale.protocol.BreakShape> {
   class="kw">public class="kw">static class="kw">final int MAX_DIMENSION = 32;
   class="kw">public class="kw">static class="kw">final int MAX_TOTAL_CELLS = 1024;
   class="kw">public class="kw">static class="kw">final int MAX_OFFSET = 32;
   @Nonnull
   class="kw">public class="kw">static class="kw">final CodecMapCodec<BreakShape> CODEC = new CodecMapCodec<>();
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<BreakShape> BASE_CODEC = BuilderCodec.abstractBuilder(BreakShape.class)
      .append(new KeyedCodec<>("Width", Codec.INTEGER, true), (var0, var1) -> var0.width = var1, var0 -> var0.width)
      .addValidator(Validators.range(1, 32))
      .documentation("The size of the shape along the user's horizontal view axis (right).")
      .add()
      .<Integer>append(new KeyedCodec<>("Height", Codec.INTEGER, true), (var0, var1) -> var0.height = var1, var0 -> var0.height)
      .addValidator(Validators.range(1, 32))
      .documentation("The size of the shape along the user's vertical view axis (up).")
      .add()
      .<Integer>append(new KeyedCodec<>("Depth", Codec.INTEGER), (var0, var1) -> var0.depth = var1, var0 -> var0.depth)
      .addValidator(Validators.range(1, 32))
      .documentation("How many blocks deep the shape class="kw">extends into the targeted surface. Defaults to 1.")
      .add()
      .<Boolean>append(new KeyedCodec<>("Centered", Codec.BOOLEAN), (var0, var1) -> var0.centered = var1, var0 -> var0.centered)
      .documentation("Whether the shape's width/height are centered on the targeted block. Defaults to true.")
      .add()
      .<Vector3d>append(new KeyedCodec<>("Offset", Vector3dUtil.CODEC), (var0, var1) -> var0.offset.set(var1), var0 -> var0.offset)
      .addValidator(Validators.nonNull())
      .documentation("Shifts the shape's center off the targeted block, in the view basis (x = right, y = up, z = into the surface). Rounded to whole blocks.")
      .add()
      .<BreakShapeOrientation>append(
         new KeyedCodec<>("Orientation", new EnumCodec<>(BreakShapeOrientation.class)), (var0, var1) -> var0.orientation = var1, var0 -> var0.orientation
      )
      .addValidator(Validators.nonNull())
      .documentation(
         "How the shape is oriented: 'View' (the dominant axis of the look direction, the class="kw">default) or 'Surface' (into the targeted block face that the look ray hits)."
      )
      .add()
      .build();
   class="kw">protected int width = 1;
   class="kw">protected int height = 1;
   class="kw">protected int depth = 1;
   class="kw">protected boolean centered = true;
   @Nonnull
   class="kw">protected class="kw">final Vector3d offset = new Vector3d();
   @Nonnull
   class="kw">protected BreakShapeOrientation orientation = BreakShapeOrientation.View;

   class="kw">public BreakShape() {
   }

   class="kw">public int getWidth() {
      class="kw">return this.width;
   }

   class="kw">public int getHeight() {
      class="kw">return this.height;
   }

   class="kw">public int getDepth() {
      class="kw">return this.depth;
   }

   class="kw">public boolean isCentered() {
      class="kw">return this.centered;
   }

   @Nonnull
   class="kw">public Vector3f getOffset() {
      class="kw">return new Vector3f((float)this.offset.x, (float)this.offset.y, (float)this.offset.z);
   }

   @Nonnull
   class="kw">public BreakShapeOrientation getOrientation() {
      class="kw">return this.orientation;
   }

   class="kw">public class="kw">abstract void forEachLocalOffset(@Nonnull TriIntConsumer var1);

   class="kw">public void selectBlocks(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Ref<EntityStore> var2, @Nullable Vector3i var3, @Nonnull TriIntConsumer var4) {
      if (var3 != null) {
         Vector3i var5 = new Vector3i();
         Vector3i var6 = new Vector3i();
         Vector3i var7 = new Vector3i();
         if (this.orientation == BreakShapeOrientation.Surface) {
            computeSurfaceBasis(var1, var2, var3, var5, var6, var7);
         } else {
            computeViewBasis(var1.getComponent(var2, HeadRotation.getComponentType()), var5, var6, var7);
         }

         int var8 = (int)Math.round(this.offset.x);
         int var9 = (int)Math.round(this.offset.y);
         int var10 = (int)Math.round(this.offset.z);
         int var11 = var3.x() + var7.x() * var8 + var6.x() * var9 + var5.x() * var10;
         int var12 = var3.y() + var7.y() * var8 + var6.y() * var9 + var5.y() * var10;
         int var13 = var3.z() + var7.z() * var8 + var6.z() * var9 + var5.z() * var10;
         this.forEachLocalOffset((var7x, var8x, var9x) -> {
            int var10 = var11 + var7.x() * var7x + var6.x() * var8x + var5.x() * var9x;
            int var11 = var12 + var7.y() * var7x + var6.y() * var8x + var5.y() * var9x;
            int var12 = var13 + var7.z() * var7x + var6.z() * var8x + var5.z() * var9x;
            var4.accept(var10, var11, var12);
         });
      }
   }

   class="kw">protected void validateShape() {
      long var1 = (long)this.width * this.height * this.depth;
      if (var1 > 1024L) {
         throw new IllegalArgumentException(
            "Break shape volume " + var1 + " (" + this.width + "x" + this.height + "x" + this.depth + ") exceeds the maximum of 1024"
         );
      } else if (Math.abs(this.offset.x) > 32.0 || Math.abs(this.offset.y) > 32.0 || Math.abs(this.offset.z) > 32.0) {
         throw new IllegalArgumentException(
            "Break shape offset (" + this.offset.x + ", " + this.offset.y + ", " + this.offset.z + ") exceeds the maximum magnitude of 32 per axis"
         );
      }
   }

   class="kw">protected class="kw">static int lowBound(int var0, boolean var1) {
      class="kw">return var1 ? -((var0 - 1) / 2) : 0;
   }

   class="kw">private class="kw">static void computeViewBasis(@Nullable HeadRotation var0, @Nonnull Vector3i var1, @Nonnull Vector3i var2, @Nonnull Vector3i var3) {
      if (var0 != null) {
         Vector3d var4 = var0.getDirection();
         computeViewBasis(var4.x(), var4.y(), var4.z(), var1, var2, var3);
      } else {
         computeViewBasis(0.0, -1.0, 0.0, var1, var2, var3);
      }
   }

   class="kw">static void computeViewBasis(double var0, double var2, double var4, @Nonnull Vector3i var6, @Nonnull Vector3i var7, @Nonnull Vector3i var8) {
      double var9 = Math.abs(var0);
      double var11 = Math.abs(var2);
      double var13 = Math.abs(var4);
      if (var11 >= var9 && var11 >= var13) {
         var6.set(0, var2 >= 0.0 ? 1 : -1, 0);
         verticalUp(var0, var4, var6.y(), var7);
      } else if (var9 >= var13) {
         var6.set(var0 >= 0.0 ? 1 : -1, 0, 0);
         var7.set(0, 1, 0);
      } else {
         var6.set(0, 0, var4 >= 0.0 ? 1 : -1);
         var7.set(0, 1, 0);
      }

      var8.set(var7.y() * var6.z() - var7.z() * var6.y(), var7.z() * var6.x() - var7.x() * var6.z(), var7.x() * var6.y() - var7.y() * var6.x());
   }

   class="kw">private class="kw">static void verticalUp(double var0, double var2, int var4, @Nonnull Vector3i var5) {
      int var6 = var4 > 0 ? -1 : 1;
      if (Math.abs(var0) >= Math.abs(var2)) {
         var5.set(var0 >= 0.0 ? var6 : -var6, 0, 0);
      } else {
         var5.set(0, 0, var2 >= 0.0 ? var6 : -var6);
      }
   }

   class="kw">private class="kw">static void computeSurfaceBasis(
      @Nonnull CommandBuffer<EntityStore> var0,
      @Nonnull Ref<EntityStore> var1,
      @Nonnull Vector3i var2,
      @Nonnull Vector3i var3,
      @Nonnull Vector3i var4,
      @Nonnull Vector3i var5
   ) {
      HeadRotation var6 = var0.getComponent(var1, HeadRotation.getComponentType());
      TransformComponent var7 = var0.getComponent(var1, TransformComponent.getComponentType());
      if (var6 != null && var7 != null) {
         float var8 = ModelComponent.getEyeHeight(var1, var0);
         Vector3d var9 = var7.getPosition();
         double var10 = var9.x();
         double var12 = var9.y() + var8;
         double var14 = var9.z();
         Vector3d var16 = var6.getDirection();
         double var17 = entryDistance(var10, var16.x(), var2.x());
         double var19 = entryDistance(var12, var16.y(), var2.y());
         double var21 = entryDistance(var14, var16.z(), var2.z());
         if (var19 >= var17 && var19 >= var21) {
            var3.set(0, var16.y() >= 0.0 ? 1 : -1, 0);
         } else if (var17 >= var21) {
            var3.set(var16.x() >= 0.0 ? 1 : -1, 0, 0);
         } else {
            var3.set(0, 0, var16.z() >= 0.0 ? 1 : -1);
         }

         if (var3.y() != 0) {
            verticalUp(var16.x(), var16.z(), var3.y(), var4);
         } else {
            var4.set(0, 1, 0);
         }

         var5.set(var4.y() * var3.z() - var4.z() * var3.y(), var4.z() * var3.x() - var4.x() * var3.z(), var4.x() * var3.y() - var4.y() * var3.x());
      } else {
         computeViewBasis(var6, var3, var4, var5);
      }
   }

   class="kw">private class="kw">static double entryDistance(double var0, double var2, int var4) {
      if (var2 > 0.0) {
         class="kw">return (var4 - var0) / var2;
      } else {
         class="kw">return var2 < 0.0 ? (var4 + 1 - var0) / var2 : Double.NEGATIVE_INFINITY;
      }
   }
}