Contents
- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- interactivelyPickupItem(Ref, ItemStack, Vector3d, ComponentAccessor)
- throwItem(Ref, ItemStack, float, ComponentAccessor)
- throwItem(Ref, ComponentAccessor, ItemStack, Vector3d, float)
- dropItem(Ref, ItemStack, ComponentAccessor)
- canDecreaseItemStackDurability(Ref, ComponentAccessor)
- canApplyItemStackPenalties(Ref, ComponentAccessor)
- updateItemStackDurability(Ref, ItemStack, ItemContainer, int, double, ComponentAccessor)
- decreaseItemStackDurability(Ref, ItemStack, int, int, ComponentAccessor)
Class ItemUtils
java.lang.Object
com.hypixel.hytale.server.core.entity.ItemUtils
A utility class that contains a variety of useful item-related functionalities and utilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanApplyItemStackPenalties(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Returns whether broken-item penalties should be applied for the given entity.static booleancanDecreaseItemStackDurability(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Returns whether durability can be decreased for items held by the given entity.static ItemStackSlotTransactiondecreaseItemStackDurability(Ref<EntityStore> ref, ItemStack itemStack, int inventoryId, int slotId, ComponentAccessor<EntityStore> componentAccessor) Decreases the durability of an item stack if possible, applying penalties if the item breaks.static Ref<EntityStore> dropItem(Ref<EntityStore> ref, ItemStack itemStack, ComponentAccessor<EntityStore> componentAccessor) Called to attempt to drop the given item stack to the ground, with a subtle amount of force appliedstatic voidinteractivelyPickupItem(Ref<EntityStore> ref, ItemStack itemStack, org.joml.Vector3d origin, ComponentAccessor<EntityStore> componentAccessor) Called to attempt to pick up the given item stackstatic Ref<EntityStore> throwItem(Ref<EntityStore> ref, ComponentAccessor<EntityStore> store, ItemStack itemStack, org.joml.Vector3d throwDirection, float throwSpeed) Called to create a new item drop instance, based on the providedItemStack, which spawns into the world, with the applied velocity towards the given directionstatic Ref<EntityStore> throwItem(Ref<EntityStore> ref, ItemStack itemStack, float throwSpeed, ComponentAccessor<EntityStore> componentAccessor) Called to create a new item drop instance, based on the providedItemStack, which spawns into the world, with the applied velocity towards the given directionstatic ItemStackSlotTransactionupdateItemStackDurability(Ref<EntityStore> ref, ItemStack itemStack, ItemContainer container, int slotId, double durabilityChange, ComponentAccessor<EntityStore> componentAccessor) Updates the durability of an item stack in a container slot.
-
Field Details
-
LOGGER
-
-
Constructor Details
-
ItemUtils
public ItemUtils()
-
-
Method Details
-
interactivelyPickupItem
public static void interactivelyPickupItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nullable org.joml.Vector3d origin, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Called to attempt to pick up the given item stack- Parameters:
ref- The entity reference of the instigating entity.itemStack- TheItemStackinstance to attempt to pick up.origin- The origin position from which the item is being picked up, can benull.componentAccessor- TheComponentAccessorfor component access.
-
throwItem
@Nullable public static Ref<EntityStore> throwItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, float throwSpeed, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Called to create a new item drop instance, based on the providedItemStack, which spawns into the world, with the applied velocity towards the given directionThis specific method uses the current rotation of the living entity as the direction
- Parameters:
ref- The entity reference of the instigating entity.itemStack- The itemStack that we want to throwthrowSpeed- The speed at which to throw the itemcomponentAccessor- TheComponentAccessorfor component access.- Returns:
- the newly created thrown item entity instance, if successful
-
throwItem
@Nullable public static Ref<EntityStore> throwItem(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> store, @Nonnull ItemStack itemStack, @Nonnull org.joml.Vector3d throwDirection, float throwSpeed) Called to create a new item drop instance, based on the providedItemStack, which spawns into the world, with the applied velocity towards the given direction- Parameters:
ref- The entity reference of the instigating entity.store- The component accessor for componentsitemStack- The itemStack that we want to throwthrowDirection- The direction we want the velocity to be inthrowSpeed- The speed at which to throw the item- Returns:
- the newly created thrown item entity instance, if successful
-
dropItem
@Nullable public static Ref<EntityStore> dropItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Called to attempt to drop the given item stack to the ground, with a subtle amount of force applied- Parameters:
ref- The entity reference of the entity dropping the item.itemStack- TheItemStackinstance to drop.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the newly created dropped item entity instance, if successful.
-
canDecreaseItemStackDurability
public static boolean canDecreaseItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Returns whether durability can be decreased for items held by the given entity.Players in Creative mode cannot decrease durability; non-player entities cannot decrease durability at all.
- Parameters:
ref- The entity reference.accessor- TheComponentAccessorfor component access.- Returns:
trueif durability can be decreased,falseotherwise.
-
canApplyItemStackPenalties
public static boolean canApplyItemStackPenalties(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Returns whether broken-item penalties should be applied for the given entity.Players in Creative mode do not receive penalties; all other entities do.
- Parameters:
ref- The entity reference.accessor- TheComponentAccessorfor component access.- Returns:
trueif penalties should be applied,falseotherwise.
-
updateItemStackDurability
@Nonnull public static ItemStackSlotTransaction updateItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, ItemContainer container, int slotId, double durabilityChange, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Updates the durability of an item stack in a container slot.- Parameters:
ref- The entity reference.itemStack- The item stack to update.container- The container holding the item.slotId- The slot ID within the container.durabilityChange- The amount to change durability by (negative to decrease).componentAccessor- TheComponentAccessorfor component access.- Returns:
- the resulting
ItemStackSlotTransaction. The transaction fails, and the slot is left untouched, when the slot does not holditemStack.
-
decreaseItemStackDurability
@Nullable public static ItemStackSlotTransaction decreaseItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nullable ItemStack itemStack, int inventoryId, int slotId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Decreases the durability of an item stack if possible, applying penalties if the item breaks.- Parameters:
ref- The entity reference.itemStack- The item stack to decrease durability of.inventoryId- The ID of the inventory containing the item stack.slotId- The slot ID of the item stack within the inventory.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the resulting
ItemStackSlotTransactionif durability was decreased, ornullif durability could not be decreased.
-