Class CoopBlock

java.lang.Object
com.hypixel.hytale.builtin.adventure.farming.states.CoopBlock
All Implemented Interfaces:
Component<ChunkStore>, Cloneable

public class CoopBlock extends Object implements Component<ChunkStore>
A component that represents a farming coop block.

It manages residents (NPCs) and their produce generation, as well as item storage.

  • Field Details

  • Constructor Details

    • CoopBlock

      public CoopBlock()
      Default Constructor for a CoopBlock instance.
    • CoopBlock

      public CoopBlock(@Nonnull String farmingCoopId, @Nonnull List<CoopBlock.CoopResident> residents, @Nonnull ItemContainer itemContainer)
      Default Constructor for a CoopBlock instance.
      Parameters:
      farmingCoopId - The ID of the farming coop asset.
      residents - The list of residents in the coop.
      itemContainer - The item container for storing produce.
  • Method Details

    • getComponentType

      public static ComponentType<ChunkStore, CoopBlock> getComponentType()
    • getCoopAsset

      @Nullable public FarmingCoopAsset getCoopAsset()
    • tryPutResident

      public boolean tryPutResident(@Nonnull CapturedNPCMetadata metadata, @Nonnull WorldTimeResource worldTimeResource)
      Called to attempt to add the given resident to the coop.
      Parameters:
      metadata - The metadata of the NPC to add as a resident.
      worldTimeResource - The world time resource of the world.
      Returns:
      true if the resident was successfully added, false otherwise.
    • tryPutWildResidentFromWild

      public boolean tryPutWildResidentFromWild(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> entityRef, @Nonnull WorldTimeResource worldTimeResource, @Nonnull org.joml.Vector3i coopLocation)
      Called to attempt to add the given wild NPC as a resident to the coop.
      Parameters:
      store - The Store<EntityStore> for component access.
      entityRef - The entity reference of the NPC to add.
      worldTimeResource - The world time resource of the world.
      coopLocation - The location of the coop in the world.
      Returns:
      true if the resident was successfully added, false otherwise.
    • getCoopAcceptsNPC

      public boolean getCoopAcceptsNPC(String npcNameKey)
      Checks whether the coop accepts NPCs of the given role index.
      Parameters:
      npcNameKey - The role id of the NPC to check.
      Returns:
      true if the coop accepts the NPC group, false otherwise.
    • generateProduceToInventory

      public boolean generateProduceToInventory(@Nonnull WorldTimeResource worldTimeResource)
      Called to attempt to generate produce from residents to the coop's inventory.
      Parameters:
      worldTimeResource - The world time resource of the world.
      Returns:
      true if any persisted coop state changed (produce timestamps or inventory).
    • gatherProduceFromContainer

      public void gatherProduceFromContainer(@Nonnull ItemContainer playerInventory)
      Called to gather all produce from the coop's inventory into the player's inventory.
      Parameters:
      playerInventory - The player's inventory to gather produce into.
    • ensureSpawnResidentsInWorld

      public boolean ensureSpawnResidentsInWorld(@Nonnull World world, @Nonnull Store<EntityStore> store, @Nonnull org.joml.Vector3d coopLocation, @Nonnull org.joml.Vector3d spawnOffset)
      Ensures that all residents are spawned in the world at the given coop location with the specified spawn offset.
      Parameters:
      world - The world to spawn residents in.
      store - The Store<EntityStore> for component access.
      coopLocation - The location of the coop in the world.
      spawnOffset - The offset to apply when spawning residents.
      Returns:
      true if any persisted resident state changed (a resident was deployed).
    • ensureNoResidentsInWorld

      public boolean ensureNoResidentsInWorld(@Nonnull Store<EntityStore> store)
      Ensures that no residents are currently deployed in the world.
      Parameters:
      store - The Store<EntityStore> for component access.
      Returns:
      true if any persisted resident state changed (recalled, relabeled or dropped).
    • shouldResidentsBeInCoop

      public boolean shouldResidentsBeInCoop(@Nonnull WorldTimeResource worldTimeResource)
      Determines whether the residents of the coop should currently be in the coop based on the world time.
      Parameters:
      worldTimeResource - The world time resource of the world.
      Returns:
      true if the residents should be in the coop, false otherwise.
    • getNextScheduledTick

      @Nullable public Instant getNextScheduledTick(@Nonnull WorldTimeResource worldTimeResource)
      Calculates the next scheduled tick time for resident movement based on the world time.
      Parameters:
      worldTimeResource - The world time resource of the world.
      Returns:
      the next scheduled tick time as an Instant, or null if not applicable.
    • handleResidentDespawn

      public void handleResidentDespawn(@Nonnull UUID entityUuid)
      Called to handle the despawn of a resident with the given entity UUID.
      Parameters:
      entityUuid - The UUID of the despawned entity.
    • handleBlockBroken

      public void handleBlockBroken(@Nonnull World world, @Nonnull WorldTimeResource worldTimeResource, @Nonnull Store<EntityStore> store, int blockX, int blockY, int blockZ)
      Called to handle the breaking of the coop block in the world.
      Parameters:
      world - The world where the block was broken.
      worldTimeResource - The world time resource of the world.
      store - The Store<EntityStore> for component access.
      blockX - The X position of the broken block.
      blockY - The Y position of the broken block.
      blockZ - The Z position of the broken block.
    • hasProduce

      public boolean hasProduce()
      Returns:
      true if the coop has any produce in its inventory, false otherwise.
    • clone

      public Component<ChunkStore> clone()
      Specified by:
      clone in interface Component<ChunkStore>
      Returns:
      a clone instance of the original component instance.