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)
T
get()
boolean
isValid(T value)
boolean
set(T value)
default boolean
set(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
DestroyableRef
that can be modified untilDestroyableRef.destroy()
is called, after which all calls toset(Object)
andisValid(Object)
will return false.
-
unmodifiable
- Returns:
- A new
Reference
that 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
- TheSupplier
which is used forget()
.setter
- TheConsumer
which is used forset(Object)
(after the filter).filter
- ThePredicate
which is used to test inputs for bothset(Object)
andisValid(Object)
.- Returns:
- A new
CallableRef
that 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
- TheSupplier
which is used forget()
setter
- TheLimitedConsumer
which is used forset(Object)
andisValid(Object)
.- Returns:
- A new
SimulatableRef
that delegates to the getter and setter for all of it's functions.
-
destroying
- Returns:
- A new
DestroyableRef
that delegates to the given reference for getting, although setting only succeeds untilDestroyableRef.destroy()
is called.
-