BlockHealthModule class

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

Файл: com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthModule.java

extends: JavaPlugin

Поля (47)

МодификаторыТипИмя
private static final ComponentType<ChunkStore, BlockHealthChunk> BLOCK_HEALTH_CHUNK_COMPONENT_TYPE
private final Archetype<ChunkStore> archetype
private final Archetype<ChunkStore> archetype
private final ComponentType<ChunkStore, BlockHealthChunk> blockHealthChunkComponentType
private final ComponentType<ChunkStore, BlockHealthChunk> blockHealthComponentChunkType
private final ComponentType<ChunkStore, BlockHealthChunk> blockHealthCunkComponentType
instance
private final ResourceType<EntityStore, TimeResource> timeResourceType
ComponentRegistryProxy var1
Instant var10
Instant var11
Ref var11
Map var12
BlockHealthChunk var12
float var13
WorldConfig var13
Iterator var14
float var14
Entry var15
FragileBlock var16
float var17
Ref var19
ChunkTracker var20
BlockHealth var21
Instant var22
float var23
var23
float var24
var24
UpdateBlockDamage var25
Map var27
WorldChunk var28
Collection var29
ObjectArrayList var30
float var32
Iterator var33
Entry var34
Vector3i var35
BlockHealthChunk var6
World var6
BlockHealthChunk var7
World var7
Vector3i var7
Store var8
ChunkStore var8
TimeResource var9
long var9

Методы (24)

МодификаторыВозвратСигнатура
public BlockHealthPacketSystempublic BlockHealthPacketSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1)
public BlockHealthSystempublic BlockHealthSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1)
public EnsureBlockHealthSystempublic EnsureBlockHealthSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1)
public PlaceBlockEventSystempublic PlaceBlockEventSystem()
public void fetchpublic void fetch(int var1, @Nonnull ArchetypeChunk<ChunkStore> var2, Store<ChunkStore> var3, CommandBuffer<ChunkStore> var4, PlayerRef var5, @Nonnull List<ToClientPacket> var6)
for for(PlayerRef var18 : var29)
abstract for for(int var26 = 0; var26 < var30.size()
static BlockHealthModule getBlockHealthModule get()
public ComponentType<ChunkStore, BlockHealthChunk> getBlockHealthChunkComponentTypeComponentType<ChunkStore, BlockHealthChunk> getBlockHealthChunkComponentType()
public Query<ChunkStore> getQuerypublic Query<ChunkStore> getQuery()
public Query<ChunkStore> getQuerypublic Query<ChunkStore> getQuery()
public Query<ChunkStore> getQuerypublic Query<ChunkStore> getQuery()
public Query<EntityStore> getQuerypublic Query<EntityStore> getQuery()
public void handlepublic void handle(int var1, @Nonnull ArchetypeChunk<EntityStore> var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4, @Nonnull PlaceBlockEvent var5)
if if(var11 != null)
if if(var17 <= 0.0F)
if if(var24 < 1.0F)
if if(var11 != null)
public boolean isParallelpublic boolean isParallel()
public void onEntityAddpublic void onEntityAdd(@Nonnull Holder<ChunkStore> var1, @Nonnull AddReason var2, @Nonnull Store<ChunkStore> var3)
public void onEntityRemovedpublic void onEntityRemoved(@Nonnull Holder<ChunkStore> var1, @Nonnull RemoveReason var2, @Nonnull Store<ChunkStore> var3)
abstract super super(var1)
abstract super super(PlaceBlockEvent.class)
public void tickpublic void tick(float var1, int var2, @Nonnull ArchetypeChunk<ChunkStore> var3, @Nonnull Store<ChunkStore> var4, @Nonnull CommandBuffer<ChunkStore> var5)

Исходный код

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

class="kw">import com.hypixel.hytale.common.plugin.PluginManifest;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.Archetype;
class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.ComponentRegistryProxy;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.RemoveReason;
class="kw">import com.hypixel.hytale.component.ResourceType;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.query.Query;
class="kw">import com.hypixel.hytale.component.system.EntityEventSystem;
class="kw">import com.hypixel.hytale.component.system.HolderSystem;
class="kw">import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.protocol.BlockPosition;
class="kw">import com.hypixel.hytale.protocol.ToClientPacket;
class="kw">import com.hypixel.hytale.protocol.packets.world.UpdateBlockDamage;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.WorldConfig;
class="kw">import com.hypixel.hytale.server.core.event.events.ecs.PlaceBlockEvent;
class="kw">import com.hypixel.hytale.server.core.modules.LegacyModule;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.ChunkTracker;
class="kw">import com.hypixel.hytale.server.core.modules.time.TimeModule;
class="kw">import com.hypixel.hytale.server.core.modules.time.TimeResource;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPlugin;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.time.Instant;
class="kw">import java.util.Collection;
class="kw">import java.util.Iterator;
class="kw">import java.util.List;
class="kw">import java.util.Map;
class="kw">import java.util.Map.Entry;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;

class="kw">public class BlockHealthModule class="kw">extends JavaPlugin {
   @Nonnull
   class="kw">public class="kw">static class="kw">final PluginManifest MANIFEST = PluginManifest.corePlugin(BlockHealthModule.class)
      .depends(LegacyModule.class)
      .depends(TimeModule.class)
      .build();
   class="kw">private class="kw">static class="kw">final long SECONDS_UNTIL_REGENERATION = 5L;
   class="kw">private class="kw">static class="kw">final float HEALING_PER_SECOND = 0.1F;
   class="kw">private class="kw">static BlockHealthModule instance;
   class="kw">private ComponentType<ChunkStore, BlockHealthChunk> blockHealthChunkComponentType;

   class="kw">public BlockHealthModule(@Nonnull JavaPluginInit var1) {
      super(var1);
      instance = this;
   }

   class="kw">public class="kw">static BlockHealthModule get() {
      class="kw">return instance;
   }

   @Override
   class="kw">protected void setup() {
      ComponentRegistryProxy var1 = this.getChunkStoreRegistry();
      this.blockHealthChunkComponentType = var1.registerComponent(BlockHealthChunk.class, "BlockHealthChunk", BlockHealthChunk.CODEC);
      this.getEntityStoreRegistry().registerSystem(new BlockHealthModule.PlaceBlockEventSystem());
      var1.registerSystem(new BlockHealthModule.EnsureBlockHealthSystem(this.blockHealthChunkComponentType));
      var1.registerSystem(new BlockHealthModule.BlockHealthSystem(this.blockHealthChunkComponentType));
      var1.registerSystem(new BlockHealthModule.BlockHealthPacketSystem(this.blockHealthChunkComponentType));
   }

   class="kw">public ComponentType<ChunkStore, BlockHealthChunk> getBlockHealthChunkComponentType() {
      class="kw">return this.blockHealthChunkComponentType;
   }

   class="kw">private class="kw">static class BlockHealthPacketSystem class="kw">extends ChunkStore.LoadPacketDataQuerySystem {
      @Nonnull
      class="kw">private class="kw">final ComponentType<ChunkStore, BlockHealthChunk> blockHealthCunkComponentType;
      @Nonnull
      class="kw">private class="kw">final Archetype<ChunkStore> archetype;

      class="kw">public BlockHealthPacketSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1) {
         this.blockHealthCunkComponentType = var1;
         this.archetype = Archetype.of(var1, WorldChunk.getComponentType());
      }

      @Nonnull
      @Override
      class="kw">public Query<ChunkStore> getQuery() {
         class="kw">return this.archetype;
      }

      @Override
      class="kw">public boolean isParallel() {
         class="kw">return true;
      }

      class="kw">public void fetch(
         int var1,
         @Nonnull ArchetypeChunk<ChunkStore> var2,
         Store<ChunkStore> var3,
         CommandBuffer<ChunkStore> var4,
         PlayerRef var5,
         @Nonnull List<ToClientPacket> var6
      ) {
         BlockHealthChunk var7 = var2.getComponent(var1, this.blockHealthCunkComponentType);
         assert var7 != null;
         var7.createBlockDamagePackets(var6);
      }
   }

   class="kw">private class="kw">static class BlockHealthSystem class="kw">extends EntityTickingSystem<ChunkStore> {
      @Nonnull
      class="kw">private class="kw">final ComponentType<ChunkStore, BlockHealthChunk> blockHealthComponentChunkType;
      @Nonnull
      class="kw">private class="kw">final ResourceType<EntityStore, TimeResource> timeResourceType;
      class="kw">private class="kw">final Archetype<ChunkStore> archetype;

      class="kw">public BlockHealthSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1) {
         this.blockHealthComponentChunkType = var1;
         this.timeResourceType = TimeResource.getResourceType();
         this.archetype = Archetype.of(var1, WorldChunk.getComponentType());
      }

      @Override
      class="kw">public Query<ChunkStore> getQuery() {
         class="kw">return this.archetype;
      }

      @Override
      class="kw">public void tick(float var1, int var2, @Nonnull ArchetypeChunk<ChunkStore> var3, @Nonnull Store<ChunkStore> var4, @Nonnull CommandBuffer<ChunkStore> var5) {
         BlockHealthChunk var6 = var3.getComponent(var2, this.blockHealthComponentChunkType);
         assert var6 != null;
         World var7 = var4.getExternalData().getWorld();
         Store var8 = var7.getEntityStore().getStore();
         TimeResource var9 = var7.getEntityStore().getStore().getResource(this.timeResourceType);
         Instant var10 = var9.getNow();
         Instant var11 = var6.getLastRepairGameTime();
         var6.setLastRepairGameTime(var10);
         if (var11 != null) {
            Map var12 = var6.getBlockFragilityMap();
            if (!var12.isEmpty()) {
               float var13 = (float)(var10.toEpochMilli() - var11.toEpochMilli()) / 1000.0F;
               Iterator var14 = var12.entrySet().iterator();

               while (var14.hasNext()) {
                  Entry var15 = var14.next();
                  FragileBlock var16 = var15.getValue();
                  float var17 = var16.getDurationSeconds() - var13;
                  if (var17 <= 0.0F) {
                     var14.remove();
                  } else {
                     var16.setDurationSeconds(var17);
                  }
               }
            }

            Map var27 = var6.getBlockHealthMap();
            if (!var27.isEmpty()) {
               WorldChunk var28 = var3.getComponent(var2, WorldChunk.getComponentType());
               assert var28 != null;
               Collection var29 = var7.getPlayerRefs();
               ObjectArrayList var30 = new ObjectArrayList(var29.size());

               for (PlayerRef var18 : var29) {
                  Ref var19 = var18.getReference();
                  if (var19 != null && var19.isValid()) {
                     ChunkTracker var20 = var8.getComponent(var19, ChunkTracker.getComponentType());
                     assert var20 != null;
                     if (var20.isLoaded(var28.getIndex())) {
                        var30.add(var18);
                     }
                  }
               }

               float var32 = (float)(var10.toEpochMilli() - var11.toEpochMilli()) / 1000.0F;
               Iterator var33 = var27.entrySet().iterator();

               while (var33.hasNext()) {
                  Entry var34 = var33.next();
                  Vector3i var35 = var34.getKey();
                  BlockHealth var21 = var34.getValue();
                  Instant var22 = var21.getLastDamageGameTime().plusSeconds(5L);
                  if (!var10.isBefore(var22)) {
                     float var23 = 0.1F * var32;
                     float var24 = var21.getHealth() + var23;
                     if (var24 < 1.0F) {
                        var21.setHealth(var24);
                     } else {
                        var33.remove();
                        var24 = BlockHealth.NO_DAMAGE_INSTANCE.getHealth();
                        var23 = var24 - var21.getHealth();
                     }

                     UpdateBlockDamage var25 = new UpdateBlockDamage(new BlockPosition(var35.x(), var35.y(), var35.z()), var24, var23);

                     for (int var26 = 0; var26 < var30.size(); var26++) {
                        ((PlayerRef)var30.get(var26)).getPacketHandler().writeNoCache(var25);
                     }
                  }
               }
            }
         }
      }
   }

   class="kw">private class="kw">static class EnsureBlockHealthSystem class="kw">extends HolderSystem<ChunkStore> {
      @Nonnull
      class="kw">private class="kw">final ComponentType<ChunkStore, BlockHealthChunk> blockHealthChunkComponentType;

      class="kw">public EnsureBlockHealthSystem(@Nonnull ComponentType<ChunkStore, BlockHealthChunk> var1) {
         this.blockHealthChunkComponentType = var1;
      }

      @Override
      class="kw">public Query<ChunkStore> getQuery() {
         class="kw">return WorldChunk.getComponentType();
      }

      @Override
      class="kw">public void onEntityAdd(@Nonnull Holder<ChunkStore> var1, @Nonnull AddReason var2, @Nonnull Store<ChunkStore> var3) {
         var1.ensureComponent(this.blockHealthChunkComponentType);
      }

      @Override
      class="kw">public void onEntityRemoved(@Nonnull Holder<ChunkStore> var1, @Nonnull RemoveReason var2, @Nonnull Store<ChunkStore> var3) {
      }
   }

   class="kw">public class="kw">static class PlaceBlockEventSystem class="kw">extends EntityEventSystem<EntityStore, PlaceBlockEvent> {
      @Nonnull
      class="kw">private class="kw">static class="kw">final ComponentType<ChunkStore, BlockHealthChunk> BLOCK_HEALTH_CHUNK_COMPONENT_TYPE = BlockHealthModule.get()
         .getBlockHealthChunkComponentType();

      class="kw">public PlaceBlockEventSystem() {
         super(PlaceBlockEvent.class);
      }

      class="kw">public void handle(
         int var1,
         @Nonnull ArchetypeChunk<EntityStore> var2,
         @Nonnull Store<EntityStore> var3,
         @Nonnull CommandBuffer<EntityStore> var4,
         @Nonnull PlaceBlockEvent var5
      ) {
         World var6 = var4.getExternalData().getWorld();
         Vector3i var7 = var5.getTargetBlock();
         ChunkStore var8 = var6.getChunkStore();
         long var9 = ChunkUtil.indexChunkFromBlock(var7.x, var7.z);
         Ref var11 = var8.getChunkReference(var9);
         if (var11 != null) {
            BlockHealthChunk var12 = var8.getStore().getComponent(var11, BLOCK_HEALTH_CHUNK_COMPONENT_TYPE);
            assert var12 != null;
            WorldConfig var13 = var6.getGameplayConfig().getWorldConfig();
            float var14 = var13.getBlockPlacementFragilityTimer();
            var12.makeBlockFragile(var7, var14);
         }
      }

      @Nullable
      @Override
      class="kw">public Query<EntityStore> getQuery() {
         class="kw">return Archetype.empty();
      }
   }
}