15 | * Note that {@link AttributeProvider} is called before this, if the {@link Block} implements it. However if
16 | * the {@link Block} doesn't actually add any objects of the correct type then this will still be called. */
17 | public interface AttributeProviderBlockEntity {
18 |
19 | /** Adds every instance of the given attribute in this block entity to the resulting list. Note that this must never
20 | * add wrapped versions of an attribute to the resulting list as the caller is responsible for doing that
21 | * instead. */
22 | void addAllAttributes(AttributeList> to);
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/alexiil/mc/lib/attributes/AttributeProviderItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 AlexIIL
3 | *
4 | * This Source Code Form is subject to the terms of the Mozilla Public
5 | * License, v. 2.0. If a copy of the MPL was not distributed with this
6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 | */
8 | package alexiil.mc.lib.attributes;
9 |
10 | import net.minecraft.item.Item;
11 | import net.minecraft.item.ItemStack;
12 |
13 | import alexiil.mc.lib.attributes.misc.LimitedConsumer;
14 | import alexiil.mc.lib.attributes.misc.Reference;
15 |
16 | /** An {@link Item} that contains attributes. */
17 | public interface AttributeProviderItem {
18 |
19 | /** Adds every attribute instance to the given list that the item itself cannot be expected to add support for.
20 | *
21 | * @param stack A {@link Reference} to the stack to test for. If any of the added attributes need to modify the
22 | * stack then they should do that by setting the given {@link Reference#set(Object)}, rather than
23 | * modifying the stack directly.
24 | * @param excess If interacting with any of the returned attributes produces excess {@link ItemStack}'s then they
25 | * should be added to this {@link LimitedConsumer}. */
26 | void addAllAttributes(Reference
16 | * The main point is that instance must be designed directly for the given attribute, or the implementation must be
17 | * the best possible version for the actual instance. */
18 | INSTANCE,
19 |
20 | // Should any more be defined? I'm not sure what other kinds of implementations will actually happen.
21 |
22 | /** Lowest priority of all the source types - when the implementation is just a wrapper over a different API, and as
23 | * such it may suffer from poorer performance or be a poor fit for the target interface/class. */
24 | COMPAT_WRAPPER;
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/alexiil/mc/lib/attributes/AttributeUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 AlexIIL
3 | *
4 | * This Source Code Form is subject to the terms of the Mozilla Public
5 | * License, v. 2.0. If a copy of the MPL was not distributed with this
6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 | */
8 | package alexiil.mc.lib.attributes;
9 |
10 | /** Misleadingly named class: this only stores the boolean checker {@link #EXPENSIVE_DEBUG_CHECKS}, and doesn't actually
11 | * have any other utility methods. */
12 | public final class AttributeUtil {
13 | private AttributeUtil() {}
14 |
15 | // Ensure that it defaults to true, unless some-one explicitly goes looking for this
16 | public static final boolean EXPENSIVE_DEBUG_CHECKS
17 | = !Boolean.getBoolean("libblockattributes.disable_expensive_debug_checks");
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/alexiil/mc/lib/attributes/Attributes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 AlexIIL
3 | *
4 | * This Source Code Form is subject to the terms of the Mozilla Public
5 | * License, v. 2.0. If a copy of the MPL was not distributed with this
6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 | */
8 | package alexiil.mc.lib.attributes;
9 |
10 | import javax.annotation.Nonnull;
11 |
12 | /** Static factories for {@link Attribute} instances. */
13 | public final class Attributes {
14 | private Attributes() {}
15 |
16 | public static