BlockAnimationSection class

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

Файл: com/hypixel/hytale/server/core/modules/blockanimation/BlockAnimationSection.java

implements: Component<ChunkStore>

Поля (11)

МодификаторыТипИмя
private static final ArrayCodec<BlockAnimationSection.SerializedEntry> ARRAY_CODEC
private static final RecordCodec<BlockAnimationSection.SerializedEntry> CODEC
final int VERSION
int[] var1
int[] var2
BlockAnimationSection.SerializedEntry[] var2
boolean var3
ArrayList var3
int var4
Float var8
var8

Методы (19)

МодификаторыВозвратСигнатура
private record SerializedEntryrecord SerializedEntry(int index, float speed)
public void clearPendingPhasesvoid clearPendingPhases()
public BlockAnimationSection.SerializedEntry[] decodepublic BlockAnimationSection.SerializedEntry[] decode(@Nonnull BsonValue var1, @Nonnull ExtraInfo var2)
for for(int var7 : var2)
for for(BlockAnimationSection.SerializedEntry var5 : var1)
for for(int var3 = 0; var3 < var1.length; var3++)
public long getRevisionlong getRevision()
public float getSpeedfloat getSpeed(int var1)
public boolean hasPendingPhasesboolean hasPendingPhases()
public boolean hasSpeedboolean hasSpeed(int var1)
if if(!var3)
if if(var1 != null)
public boolean isEmptyboolean isEmpty()
static boolean isValidIndexboolean isValidIndex(int var0)
public boolean removeSpeedboolean removeSpeed(int var1)
public boolean setPhaseboolean setPhase(int var1, float var2)
private void setSerializedEntriesvoid setSerializedEntries(@Nullable BlockAnimationSection.SerializedEntry[] var1)
private void setSerializedRevisionvoid setSerializedRevision(long var1)
public boolean setSpeedboolean setSpeed(int var1, float var2)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.ExtraInfo;
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.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.record.RecordCodec;
class="kw">import com.hypixel.hytale.component.Component;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.packets.world.BlockAnimationEntry;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import it.unimi.dsi.fastutil.ints.Int2FloatMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
class="kw">import java.util.ArrayList;
class="kw">import java.util.Arrays;
class="kw">import java.util.function.IntFunction;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.bson.BsonValue;

class="kw">public class BlockAnimationSection class="kw">implements Component<ChunkStore> {
   class="kw">public class="kw">static class="kw">final int VERSION = 0;
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   class="kw">public class="kw">static class="kw">final BuilderCodec<BlockAnimationSection> CODEC = BuilderCodec.<BlockAnimationSection>builder(
         BlockAnimationSection.class, BlockAnimationSection::new
      )
      .versioned()
      .codecVersion(0)
      .append(new KeyedCodec<>("Revision", Codec.LONG), BlockAnimationSection::setSerializedRevision, BlockAnimationSection::getRevision)
      .add()
      .append(
         new KeyedCodec<>("Entries", BlockAnimationSection.SerializedEntry.ARRAY_CODEC),
         BlockAnimationSection::setSerializedEntries,
         BlockAnimationSection::getSerializedEntries
      )
      .add()
      .build();
   @Nonnull
   class="kw">private class="kw">final Int2FloatMap speeds;
   class="kw">private long revision;
   @Nonnull
   class="kw">private class="kw">transient Int2FloatMap pendingPhases;

   class="kw">public BlockAnimationSection() {
      this.speeds = new Int2FloatOpenHashMap();
      this.pendingPhases = new Int2FloatOpenHashMap();
   }

   class="kw">private BlockAnimationSection(@Nonnull Int2FloatMap var1, long var2) {
      this.speeds = var1;
      this.revision = var2;
      this.pendingPhases = new Int2FloatOpenHashMap();
   }

   @Nonnull
   class="kw">public class="kw">static ComponentType<ChunkStore, BlockAnimationSection> getComponentType() {
      class="kw">return BlockAnimationModule.get().getBlockAnimationSectionComponentType();
   }

   class="kw">public boolean hasSpeed(int var1) {
      class="kw">return this.speeds.containsKey(var1);
   }

   class="kw">public float getSpeed(int var1) {
      class="kw">return this.speeds.get(var1);
   }

   class="kw">public boolean setSpeed(int var1, float var2) {
      if (isValidIndex(var1) && BlockAnimationModule.isValidSpeed(var2)) {
         boolean var3 = !this.speeds.containsKey(var1) || Float.floatToIntBits(this.speeds.get(var1)) != Float.floatToIntBits(var2);
         if (!var3) {
            class="kw">return false;
         }

         this.speeds.put(var1, var2);
         this.revision++;
         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   class="kw">public boolean setPhase(int var1, float var2) {
      if (isValidIndex(var1) && Float.isFinite(var2) && this.speeds.containsKey(var1)) {
         this.pendingPhases.put(var1, var2);
         this.revision++;
         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   class="kw">public boolean removeSpeed(int var1) {
      if (!this.speeds.containsKey(var1)) {
         class="kw">return false;
      }

      this.speeds.remove(var1);
      this.pendingPhases.remove(var1);
      this.revision++;
      class="kw">return true;
   }

   class="kw">public boolean isEmpty() {
      class="kw">return this.speeds.isEmpty();
   }

   class="kw">public long getRevision() {
      class="kw">return this.revision;
   }

   @Nonnull
   class="kw">public BlockAnimationEntry[] toEntries(@Nonnull BlockSection var1) {
      int[] var2 = this.speeds.keySet().toIntArray();
      Arrays.sort(var2);
      ArrayList var3 = new ArrayList<>(var2.length);

      for (int var7 : var2) {
         Float var8 = null;
         if (this.pendingPhases.containsKey(var7)) {
            var8 = this.pendingPhases.get(var7);
         }

         var3.add(new BlockAnimationEntry(var7, var1.get(var7), this.speeds.get(var7), var8));
      }

      class="kw">return var3.toArray(BlockAnimationEntry[]::new);
   }

   class="kw">public void clearPendingPhases() {
      this.pendingPhases.clear();
   }

   class="kw">public boolean hasPendingPhases() {
      class="kw">return !this.pendingPhases.isEmpty();
   }

   @Nonnull
   @Override
   class="kw">public Component<ChunkStore> clone() {
      class="kw">return new BlockAnimationSection(new Int2FloatOpenHashMap(this.speeds), this.revision);
   }

   class="kw">private void setSerializedRevision(long var1) {
      this.revision = Math.max(var1, 0L);
   }

   class="kw">private void setSerializedEntries(@Nullable BlockAnimationSection.SerializedEntry[] var1) {
      this.speeds.clear();
      if (var1 != null) {
         for (BlockAnimationSection.SerializedEntry var5 : var1) {
            if (var5 != null && isValidIndex(var5.index()) && BlockAnimationModule.isValidSpeed(var5.speed())) {
               this.speeds.put(var5.index(), var5.speed());
            }
         }
      }
   }

   @Nonnull
   class="kw">private BlockAnimationSection.SerializedEntry[] getSerializedEntries() {
      int[] var1 = this.speeds.keySet().toIntArray();
      Arrays.sort(var1);
      BlockAnimationSection.SerializedEntry[] var2 = new BlockAnimationSection.SerializedEntry[var1.length];

      for (int var3 = 0; var3 < var1.length; var3++) {
         int var4 = var1[var3];
         var2[var3] = new BlockAnimationSection.SerializedEntry(var4, this.speeds.get(var4));
      }

      class="kw">return var2;
   }

   @Nonnull
   int[] getIndices() {
      class="kw">return this.speeds.keySet().toIntArray();
   }

   class="kw">private class="kw">static boolean isValidIndex(int var0) {
      class="kw">return var0 >= 0 && var0 < 32768;
   }

   class="kw">private record SerializedEntry(int index, float speed) {
      class="kw">private class="kw">static class="kw">final RecordCodec<BlockAnimationSection.SerializedEntry> CODEC = RecordCodec.builder(BlockAnimationSection.SerializedEntry.class)
         .append(new KeyedCodec<>("Index", Codec.INTEGER), BlockAnimationSection.SerializedEntry::index)
         .append(new KeyedCodec<>("Speed", Codec.FLOAT), BlockAnimationSection.SerializedEntry::speed)
         .build(BlockAnimationSection.SerializedEntry::new);
      class="kw">private class="kw">static class="kw">final ArrayCodec<BlockAnimationSection.SerializedEntry> ARRAY_CODEC = new ArrayCodec<BlockAnimationSection.SerializedEntry>(
         CODEC, BlockAnimationSection.SerializedEntry[]::new
      ) {
         class="kw">public BlockAnimationSection.SerializedEntry[] decode(@Nonnull BsonValue var1, @Nonnull ExtraInfo var2) {
            if (var1.isArray() && var1.asArray().size() > 32768) {
               BlockAnimationSection.LOGGER
                  .at(Level.WARNING)
                  .log("Rejected a block animation entry array with %d entries. The maximum is %d.", var1.asArray().size(), 32768);
               class="kw">return new BlockAnimationSection.SerializedEntry[0];
            } else {
               class="kw">return (BlockAnimationSection.SerializedEntry[])super.decode(var1, var2);
            }
         }
      };

      class="kw">private SerializedEntry {
      }
   }
}