mmb.data.variables.Variable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.data.variables;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import mmb.NN;
/**
* @author oskar
* @param type of variable
*
*/
public interface Variable extends Property{
/**
*
* @param value
*/
public void set(T value);
public static @NN Variable delegate(Supplier getter, Consumer setter){
return new Variable() {
@Override
public U get() {
return getter.get();
}
@Override
public void set(U value) {
setter.accept(value);
}
};
}
public static @NN Variable ofArraySlot(int slot, U[] array){
return delegate(() -> array[slot], val -> array[slot] = val);
}
public static @NN Variable ofListSlot(int slot, List array){
return delegate(() -> array.get(slot), val -> array.set(slot, val));
}
}