Package alexiil.mc.lib.attributes.misc
Interface Reference<T>
- All Known Subinterfaces:
StackReference
- All Known Implementing Classes:
CallableRef,DestroyableRef,Ref,SimulatableRef,SingleCopyingItemSlot,SingleFluidTank,SingleItemSlot,UnmodifiableRef
public interface Reference<T>
A reference to some object. The object can either be obtained from (
get()), or changed with
(set(Object)). Note that changing the object isn't always permitted, and so it may return false if no change
happened.-
Method Summary
Modifier and Type Method Description default DestroyableRef<T>asDestroyable()static <T> CallableRef<T>callable(java.util.function.Supplier<T> getter, java.util.function.Consumer<T> setter, java.util.function.Predicate<T> filter)static <T> DestroyableRef<T>destroying(Reference<T> ref)Tget()booleanisValid(T value)booleanset(T value)default booleanset(T value, Simulation simulation)Delegates toset(Object)if the simulation isSimulation.ACTION, otherwise it delegates toisValid(Object).static <T> SimulatableRef<T>simulating(java.util.function.Supplier<T> getter, LimitedConsumer<T> setter)static <T> UnmodifiableRef<T>unmodifiable(T obj)
-
Method Details
-
get
T get()- Returns:
- The object referenced. Note that you should generally not modify the returned value directly - instead
copy it before passing it to
set(Object)orisValid(Object)to see if your modifications are permitted.
-
set
- Returns:
- True if the new value was accepted, false otherwise.
-
isValid
- Returns:
- True if
set(Object)was called with the same value.
-
set
Delegates toset(Object)if the simulation isSimulation.ACTION, otherwise it delegates toisValid(Object). -
asDestroyable
- Returns:
- A
DestroyableRefthat can be modified untilDestroyableRef.destroy()is called, after which all calls toset(Object)andisValid(Object)will return false.
-
unmodifiable
- Returns:
- A new
Referencethat doesn't permit modifications to the given object.
-
callable
static <T> CallableRef<T> callable(java.util.function.Supplier<T> getter, java.util.function.Consumer<T> setter, java.util.function.Predicate<T> filter)- Parameters:
getter- TheSupplierwhich is used forget().setter- TheConsumerwhich is used forset(Object)(after the filter).filter- ThePredicatewhich is used to test inputs for bothset(Object)andisValid(Object).- Returns:
- A new
CallableRefthat delegates to the getter, setter, and filter for all of the functions.
-
simulating
static <T> SimulatableRef<T> simulating(java.util.function.Supplier<T> getter, LimitedConsumer<T> setter)- Parameters:
getter- TheSupplierwhich is used forget()setter- TheLimitedConsumerwhich is used forset(Object)andisValid(Object).- Returns:
- A new
SimulatableRefthat delegates to the getter and setter for all of it's functions.
-
destroying
- Returns:
- A new
DestroyableRefthat delegates to the given reference for getting, although setting only succeeds untilDestroyableRef.destroy()is called.
-