Package alexiil.mc.lib.attributes
Class DefaultedAttribute<T>
java.lang.Object
alexiil.mc.lib.attributes.Attribute<T>
alexiil.mc.lib.attributes.DefaultedAttribute<T>
- Direct Known Subclasses:
CombinableAttribute
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal TA non-null default value that can be used as a no-op value if searching failed to find any normal instances. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultedAttribute(Class<T> clazz, T defaultValue) DefaultedAttribute(Class<T> clazz, T defaultValue, CustomAttributeAdder<T> customAdder) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionappendBlockAdder(CustomAttributeAdder<T> blockAdder) Appends a singleCustomAttributeAdderto the list of custom block adders.appendItemAdder(ItemAttributeAdder<T> itemAdder) Appends a singleItemAttributeAdderto the list of custom item adders.final TObtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.final TgetFirst(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.final TgetFirst(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess, Predicate<T> filter) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.final TObtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.final TgetFirst(net.minecraft.item.ItemStack unmodifiableStack) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.final TgetFirst(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos) final TgetFirst(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos, SearchOption<? super T> searchParam) final TgetFirstFromNeighbour(net.minecraft.block.entity.BlockEntity be, net.minecraft.util.math.Direction dir) Shorter method call for the common case of: BlockEntity be = ...; Direction dir = ...; Attribute<T> attr = ...; AttributeList<T> list = attr.getAll(be.getWorld(), be.getPos().offset(dir),SearchOptions.inDirection(dir));Methods inherited from class alexiil.mc.lib.attributes.Attribute
addBlockEntityPredicateAdder, addBlockPredicateAdder, addItemPredicateAdder, appendCustomAdder, cast, equals, getAll, getAll, getAll, getAll, getAll, getAll, getAll, getAllFromNeighbour, getFirstOrNull, getFirstOrNull, getFirstOrNull, getFirstOrNull, getFirstOrNull, getFirstOrNull, getFirstOrNull, getFirstOrNullFromNeighbour, hashCode, isInstance, putBlockClassAdder, putBlockEntityClassAdder, putItemClassAdder, setBlockAdder, setBlockEntityAdder, setBlockEntityAdder, setBlockEntityAdderFN, setItemAdder
-
Field Details
-
defaultValue
A non-null default value that can be used as a no-op value if searching failed to find any normal instances.
-
-
Constructor Details
-
DefaultedAttribute
-
DefaultedAttribute
@Deprecated(since="0.5.0", forRemoval=true) public DefaultedAttribute(Class<T> clazz, @Nonnull T defaultValue, CustomAttributeAdder<T> customAdder) Deprecated, for removal: This API element is subject to removal in a future version.Kept for backwards compatibility, instead you should callDefaultedAttribute(Class, Object)followed byappendBlockAdder(CustomAttributeAdder).
-
-
Method Details
-
appendBlockAdder
Description copied from class:AttributeAppends a singleCustomAttributeAdderto the list of custom block adders. These are called only for blocks that don't implementAttributeProvider, or have an existing registration in one of the more specific methods above.- Overrides:
appendBlockAdderin classAttribute<T>- Returns:
- This.
-
appendItemAdder
Description copied from class:AttributeAppends a singleItemAttributeAdderto the list of custom item adders. These are called only for items that don't implementAttributeProviderItem, or have an existing registration in one of the more specific methods above.- Overrides:
appendItemAdderin classAttribute<T>- Returns:
- This.
-
getFirst
@Nonnull public final T getFirst(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos) - Returns:
- The first attribute instance (as obtained by
Attribute.getAll(World, BlockPos, SearchOption)), or thedefaultValueif none were found.
-
getFirst
@Nonnull public final T getFirst(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos, SearchOption<? super T> searchParam) - Parameters:
searchParam- The search parameters to use for accessing instances. Many blocks only offer attributes from a certain direction, which should be provided as aSearchOptionDirectional. A full list of possibleSearchOption's is inSearchOptions.- Returns:
- The first attribute instance (as obtained by
Attribute.getAll(World, BlockPos, SearchOption)), or thedefaultValueif the search didn't find any attribute instances at the specified position.
-
getFirstFromNeighbour
@Nonnull public final T getFirstFromNeighbour(net.minecraft.block.entity.BlockEntity be, net.minecraft.util.math.Direction dir) Shorter method call for the common case of: BlockEntity be = ...; Direction dir = ...; Attribute<T> attr = ...; AttributeList<T> list = attr.getAll(be.getWorld(), be.getPos().offset(dir),SearchOptions.inDirection(dir)); -
getFirst
Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.This method is just a quicker way of calling
getFirst(Reference)of a singleItemStackwhich cannot be modified. Internally this creates a newUnmodifiableReffor the reference.- Parameters:
unmodifiableStack- AnItemStackthat may not be modified by any of the attribute instances returned.- Returns:
- The first attribute instance found by
Attribute.getAll(ItemStack), or thedefaultValueif none were found in the givenItemStack.
-
getFirst
Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.- Parameters:
stackRef- AReferenceto theItemStackto be searched. This is a full reference, which may allow any of the returned attribute instances to modify it. (For example if it was in an inventory then changes would be correctly reflected in the backing inventory).- Returns:
- The first attribute instance found by
Attribute.getAll(Reference), or tgedefaultValueif none were found in the givenItemStack.
-
getFirst
@Nonnull public final T getFirst(Reference<net.minecraft.item.ItemStack> stackRef, @Nullable Predicate<T> filter) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.- Parameters:
filter- APredicateto test allofferedobjects before accepting them into the list. A null value equals no filter, which will not block any values.- Returns:
- The first attribute instance found by
Attribute.getAll(Reference, Predicate), or thedefaultValueif none were found in the givenItemStack.
-
getFirst
@Nonnull public final T getFirst(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.- Parameters:
stackRef- AReferenceto theItemStackto be searched. This is a full reference, which may allow any of the returned attribute instances to modify it. (For example if it was in an inventory then changes would be correctly reflected in the backing inventory).excess- ALimitedConsumerwhich allows any of the returned attribute instances to spit out excess items in addition to changing the main stack. (As this is a LimitedConsumer rather than a normal consumer it is important to note that excess items items are not guaranteed to be accepted). A null value will default toLimitedConsumer.rejecting().- Returns:
- The first attribute instance found by
Attribute.getAll(Reference, LimitedConsumer), or thedefaultValueif none were found in the givenItemStack.
-
getFirst
@Nonnull public final T getFirst(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess, @Nullable Predicate<T> filter) Obtains the first instance of this attribute in the givenItemStackReference, or thedefaultValueif none were found.- Parameters:
stackRef- AReferenceto theItemStackto be searched. This is a full reference, which may allow any of the returned attribute instances to modify it. (For example if it was in an inventory then changes would be correctly reflected in the backing inventory).excess- ALimitedConsumerwhich allows any of the returned attribute instances to spit out excess items in addition to changing the main stack. (As this is a LimitedConsumer rather than a normal consumer it is important to note that excess items items are not guaranteed to be accepted). A null value will default toLimitedConsumer.rejecting().filter- APredicateto test allofferedobjects before accepting them into the list. A null value equals no filter, which will not block any values.- Returns:
- The first attribute instance found by
Attribute.getAll(Reference, LimitedConsumer, Predicate), or thedefaultValueif none were found in the givenItemStack.
-
DefaultedAttribute(Class, Object)followed byappendBlockAdder(CustomAttributeAdder).