Contents
- Description
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getComponentType()
- getCoopAsset()
- tryPutResident(CapturedNPCMetadata, WorldTimeResource)
- tryPutWildResidentFromWild(Store, Ref, WorldTimeResource, Vector3i)
- getCoopAcceptsNPC(String)
- generateProduceToInventory(WorldTimeResource)
- gatherProduceFromContainer(ItemContainer)
- ensureSpawnResidentsInWorld(World, Store, Vector3d, Vector3d)
- ensureNoResidentsInWorld(Store)
- shouldResidentsBeInCoop(WorldTimeResource)
- getNextScheduledTick(WorldTimeResource)
- handleResidentDespawn(UUID)
- handleBlockBroken(World, WorldTimeResource, Store, int, int, int)
- hasProduce()
- clone()
Class CoopBlock
java.lang.Object
com.hypixel.hytale.builtin.adventure.farming.states.CoopBlock
- All Implemented Interfaces:
Component<ChunkStore>, Cloneable
A component that represents a farming coop block.
It manages residents (NPCs) and their produce generation, as well as item storage.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA record that represents a single resident of a farming coop. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BuilderCodec<CoopBlock> The codec used to parseCoopBlockinstances.static final StringA state indicating that the coop is ready to produce items.Fields inherited from interface Component
EMPTY_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionDefault Constructor for aCoopBlockinstance.CoopBlock(String farmingCoopId, List<CoopBlock.CoopResident> residents, ItemContainer itemContainer) Default Constructor for aCoopBlockinstance. -
Method Summary
Modifier and TypeMethodDescriptionclone()booleanensureNoResidentsInWorld(Store<EntityStore> store) Ensures that no residents are currently deployed in the world.booleanensureSpawnResidentsInWorld(World world, Store<EntityStore> store, org.joml.Vector3d coopLocation, org.joml.Vector3d spawnOffset) Ensures that all residents are spawned in the world at the given coop location with the specified spawn offset.voidgatherProduceFromContainer(ItemContainer playerInventory) Called to gather all produce from the coop's inventory into the player's inventory.booleangenerateProduceToInventory(WorldTimeResource worldTimeResource) Called to attempt to generate produce from residents to the coop's inventory.static ComponentType<ChunkStore, CoopBlock> booleangetCoopAcceptsNPC(String npcNameKey) Checks whether the coop accepts NPCs of the given role index.getNextScheduledTick(WorldTimeResource worldTimeResource) Calculates the next scheduled tick time for resident movement based on the world time.voidhandleBlockBroken(World world, WorldTimeResource worldTimeResource, Store<EntityStore> store, int blockX, int blockY, int blockZ) Called to handle the breaking of the coop block in the world.voidhandleResidentDespawn(UUID entityUuid) Called to handle the despawn of a resident with the given entity UUID.booleanbooleanshouldResidentsBeInCoop(WorldTimeResource worldTimeResource) Determines whether the residents of the coop should currently be in the coop based on the world time.booleantryPutResident(CapturedNPCMetadata metadata, WorldTimeResource worldTimeResource) Called to attempt to add the given resident to the coop.booleantryPutWildResidentFromWild(Store<EntityStore> store, Ref<EntityStore> entityRef, WorldTimeResource worldTimeResource, org.joml.Vector3i coopLocation) Called to attempt to add the given wild NPC as a resident to the coop.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
cloneSerializable
-
Field Details
-
STATE_PRODUCE
A state indicating that the coop is ready to produce items.- See Also:
-
CODEC
The codec used to parseCoopBlockinstances.
-
-
Constructor Details
-
CoopBlock
public CoopBlock()Default Constructor for aCoopBlockinstance. -
CoopBlock
public CoopBlock(@Nonnull String farmingCoopId, @Nonnull List<CoopBlock.CoopResident> residents, @Nonnull ItemContainer itemContainer) Default Constructor for aCoopBlockinstance.- 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
-
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:
trueif the resident was successfully added,falseotherwise.
-
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- TheStore<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:
trueif the resident was successfully added,falseotherwise.
-
getCoopAcceptsNPC
Checks whether the coop accepts NPCs of the given role index.- Parameters:
npcNameKey- The role id of the NPC to check.- Returns:
trueif the coop accepts the NPC group,falseotherwise.
-
generateProduceToInventory
Called to attempt to generate produce from residents to the coop's inventory.- Parameters:
worldTimeResource- The world time resource of the world.- Returns:
trueif any persisted coop state changed (produce timestamps or inventory).
-
gatherProduceFromContainer
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- TheStore<EntityStore>for component access.coopLocation- The location of the coop in the world.spawnOffset- The offset to apply when spawning residents.- Returns:
trueif any persisted resident state changed (a resident was deployed).
-
ensureNoResidentsInWorld
Ensures that no residents are currently deployed in the world.- Parameters:
store- TheStore<EntityStore>for component access.- Returns:
trueif any persisted resident state changed (recalled, relabeled or dropped).
-
shouldResidentsBeInCoop
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:
trueif the residents should be in the coop,falseotherwise.
-
getNextScheduledTick
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, ornullif not applicable.
-
handleResidentDespawn
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- TheStore<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:
trueif the coop has any produce in its inventory,falseotherwise.
-
clone
- Specified by:
clonein interfaceComponent<ChunkStore>- Returns:
- a clone instance of the original component instance.
-