ConnectedBlockShapeRule class

Пакет: com.hypixel.hytale.server.core.universe.world.connectedblocks.config.rule

Файл: com/hypixel/hytale/server/core/universe/world/connectedblocks/config/rule/ConnectedBlockShapeRule.java

extends: ConnectedBlockRule

Поля (8)

МодификаторыТипИмя
final BuilderCodec<ConnectedBlockShapeRule> CODEC
ShapeConnectedBlockRule var1
BlockType var2
int var2
ConnectedBlockShapeConfig var3
ConnectedBlockShapeConfig var4
RotationTuple var5
RotationTuple var6

Методы (7)

МодификаторыВозвратСигнатура
for for(RotationTuple var4 : this.allowedRotations)
if if(var0.allowedRotationsGroup != null)
if if(var2 == null)
if if(var3 == null || var3 != var4)
if if(this.allowedRotations != null)
if if(var5 == null)
if if(this.allowedRotations != null)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.universe.world.connectedblocks.config.rule;

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.validation.Validators;
class="kw">import com.hypixel.hytale.math.vector.Vector3iUtil;
class="kw">import com.hypixel.hytale.protocol.ShapeConnectedBlockRule;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
class="kw">import com.hypixel.hytale.server.core.universe.world.connectedblocks.config.ConnectedBlockPatternConfig;
class="kw">import com.hypixel.hytale.server.core.universe.world.connectedblocks.config.shape.ConnectedBlockShapeConfig;
class="kw">import java.util.LinkedHashSet;
class="kw">import java.util.Set;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;

class="kw">public class ConnectedBlockShapeRule class="kw">extends ConnectedBlockRule {
   class="kw">public class="kw">static class="kw">final BuilderCodec<ConnectedBlockShapeRule> CODEC = BuilderCodec.builder(ConnectedBlockShapeRule.class, ConnectedBlockShapeRule::new)
      .append(new KeyedCodec<>("PositionOffset", Vector3iUtil.CODEC, false), (var0, var1) -> var0.positionOffset.set(var1), var0 -> var0.positionOffset)
      .documentation("The block offset from the origin to check")
      .add()
      .<String>append(new KeyedCodec<>("ShapeId", Codec.STRING, true), (var0, var1) -> var0.shapeId = var1, var0 -> var0.shapeId)
      .addValidator(Validators.nonNull())
      .documentation("Key of a shape entry in the rule set's Shapes map that the neighbor must resolve to")
      .add()
      .<ConnectedBlockPatternConfig.RotationGroup>append(
         new KeyedCodec<>("AllowedRotations", ConnectedBlockPatternConfig.RotationGroup.CODEC, false),
         (var0, var1) -> var0.allowedRotationsGroup = var1,
         var0 -> var0.allowedRotationsGroup
      )
      .documentation("Rotations the neighbor's shape may have. When omitted, any rotation matches.")
      .add()
      .afterDecode(var0 -> {
         if (var0.allowedRotationsGroup != null) {
            LinkedHashSet var1 = new LinkedHashSet<>();
            var0.allowedRotationsGroup.addRotationTuples(var1);
            var0.allowedRotations = var1;
            var0.allowedRotationsGroup = null;
         }
      })
      .documentation("A connected block rule that checks if the neighbor at a position offset resolves to a specific shape")
      .build();
   class="kw">private class="kw">final Vector3i positionOffset = new Vector3i();
   class="kw">private String shapeId;
   @Nullable
   class="kw">private ConnectedBlockPatternConfig.RotationGroup allowedRotationsGroup;
   @Nullable
   class="kw">private Set<RotationTuple> allowedRotations;

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

   @Override
   class="kw">public boolean check(ConnectedBlockRule.Context var1) {
      BlockType var2 = var1.getLocalBlockType(this.positionOffset);
      if (var2 == null) {
         class="kw">return false;
      }

      ConnectedBlockShapeConfig var3 = var1.getShapeForBlockType(var2);
      ConnectedBlockShapeConfig var4 = var1.getShapeById(this.shapeId);
      if (var3 == null || var3 != var4) {
         class="kw">return false;
      }

      if (this.allowedRotations != null) {
         RotationTuple var5 = var1.getLocalRotation(this.positionOffset);
         if (var5 == null) {
            class="kw">return false;
         }

         RotationTuple var6 = RotationTuple.compose(var5, var4.getRelativeRotation());
         class="kw">return this.allowedRotations.contains(var6);
      } else {
         class="kw">return true;
      }
   }

   @Override
   class="kw">public com.hypixel.hytale.protocol.ConnectedBlockRule toPacket() {
      ShapeConnectedBlockRule var1 = new ShapeConnectedBlockRule();
      var1.positionOffset = new com.hypixel.hytale.protocol.Vector3i(this.positionOffset.x, this.positionOffset.y, this.positionOffset.z);
      var1.shapeId = this.shapeId;
      if (this.allowedRotations != null) {
         var1.allowedRotations = new int[this.allowedRotations.size()];
         int var2 = 0;

         for (RotationTuple var4 : this.allowedRotations) {
            var1.allowedRotations[var2++] = var4.index();
         }
      }

      class="kw">return var1;
   }
}