Package alexiil.mc.lib.attributes
Class CombinableAttribute<T>
java.lang.Object
alexiil.mc.lib.attributes.Attribute<T>
alexiil.mc.lib.attributes.DefaultedAttribute<T>
alexiil.mc.lib.attributes.CombinableAttribute<T>
public class CombinableAttribute<T> extends DefaultedAttribute<T>
A
DefaultedAttribute
that also provides a "get" method to combine every found attribute into a single one,
using an AttributeCombiner
.-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
CombinableAttribute(java.lang.Class<T> clazz, T defaultValue, AttributeCombiner<T> combiner)
-
Method Summary
Modifier and Type Method Description CombinableAttribute<T>
appendBlockAdder(CustomAttributeAdder<T> blockAdder)
Appends a singleCustomAttributeAdder
to the list of custom block adders.CombinableAttribute<T>
appendItemAdder(ItemAttributeAdder<T> itemAdder)
Appends a singleItemAttributeAdder
to the list of custom item adders.T
combine(java.util.List<T> list)
T
combine(java.util.List<T> firstList, java.util.List<T> secondList)
T
get(Reference<net.minecraft.item.ItemStack> stackRef)
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.T
get(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess)
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.T
get(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess, java.util.function.Predicate<T> filter)
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.T
get(Reference<net.minecraft.item.ItemStack> stackRef, java.util.function.Predicate<T> filter)
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.T
get(net.minecraft.item.ItemStack unmodifiableStack)
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.T
get(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos)
T
get(net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos, SearchOption<? super T> searchParam)
T
getFromNeighbour(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.DefaultedAttribute
getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirstFromNeighbour
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
-
Constructor Details
-
CombinableAttribute
protected CombinableAttribute(java.lang.Class<T> clazz, @Nonnull T defaultValue, AttributeCombiner<T> combiner)
-
-
Method Details
-
appendBlockAdder
Description copied from class:Attribute
Appends a singleCustomAttributeAdder
to 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:
appendBlockAdder
in classDefaultedAttribute<T>
- Returns:
- This.
-
appendItemAdder
Description copied from class:Attribute
Appends a singleItemAttributeAdder
to 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:
appendItemAdder
in classDefaultedAttribute<T>
- Returns:
- This.
-
combine
-
combine
-
get
- Returns:
- Either the
#defaultValue defaultValue
, a single instance, or acombined
instance depending on how many attribute instances could be found.
-
get
@Nonnull public final T get(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:
- Either the
#defaultValue defaultValue
, a single instance, or acombined
instance depending on how many attribute instances could be found.
-
getFromNeighbour
@Nonnull public final T getFromNeighbour(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)); -
get
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.This method is just a quicker way of calling
DefaultedAttribute.getFirst(Reference)
of a singleItemStack
which cannot be modified. Internally this creates a newUnmodifiableRef
for the reference.- Parameters:
unmodifiableStack
- AnItemStack
that may not be modified by any of the attribute instances returned.- Returns:
- The combined attribute instance found by
Attribute.getAll(ItemStack)
, or theDefaultedAttribute.defaultValue
if none were found in the givenItemStack
.
-
get
Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.- Parameters:
stackRef
- AReference
to theItemStack
to 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 combined attribute instance found by
Attribute.getAll(Reference)
, or tgeDefaultedAttribute.defaultValue
if none were found in the givenItemStack
.
-
get
@Nonnull public final T get(Reference<net.minecraft.item.ItemStack> stackRef, @Nullable java.util.function.Predicate<T> filter)Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.- Parameters:
filter
- APredicate
to test alloffered
objects before accepting them into the list. A null value equals no filter, which will not block any values.- Returns:
- The combined attribute instance found by
Attribute.getAll(Reference, Predicate)
, or theDefaultedAttribute.defaultValue
if none were found in the givenItemStack
.
-
get
@Nonnull public final T get(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess)Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.- Parameters:
stackRef
- AReference
to theItemStack
to 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
- ALimitedConsumer
which 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 combined attribute instance found by
Attribute.getAll(Reference, LimitedConsumer)
, or theDefaultedAttribute.defaultValue
if none were found in the givenItemStack
.
-
get
@Nonnull public final T get(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excess, @Nullable java.util.function.Predicate<T> filter)Obtains a combined instance of this attribute in the givenItemStack
Reference
, or theDefaultedAttribute.defaultValue
if none were found.- Parameters:
stackRef
- AReference
to theItemStack
to 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
- ALimitedConsumer
which 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
- APredicate
to test alloffered
objects before accepting them into the list. A null value equals no filter, which will not block any values.- Returns:
- The combined attribute instance found by
Attribute.getAll(Reference, LimitedConsumer, Predicate)
, or theDefaultedAttribute.defaultValue
if none were found in the givenItemStack
.
-