Class TickRateStateMachine<S extends IState>
java.lang.Object
com.minecolonies.api.entity.ai.statemachine.basestatemachine.BasicStateMachine<ITickingTransition<S>,S>
com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine<S>
- All Implemented Interfaces:
IStateMachine<ITickingTransition<S>,,S> ITickRateStateMachine<S>
public class TickRateStateMachine<S extends IState>
extends BasicStateMachine<ITickingTransition<S>,S>
implements ITickRateStateMachine<S>
Statemachine with an added tickrate limiting of transitions, allowing transitions to be checked at a lower rate. Default tickrate is 20 tps (Minecraft default).
-
Field Summary
FieldsFields inherited from class com.minecolonies.api.entity.ai.statemachine.basestatemachine.BasicStateMachine
currentStateTransitions, eventTransitionMap, transitionMap -
Constructor Summary
ConstructorsConstructorDescriptionTickRateStateMachine(S initialState, @NotNull Consumer<RuntimeException> exceptionHandler) Construct a new StateMachineTickRateStateMachine(S initialState, @NotNull Consumer<RuntimeException> exceptionHandler, int tickRate) Construct a new StateMachine -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckTransition(@NotNull ITickingTransition<S> transition) Check the condition for a transitionintReturns the current rate the statemachine is beeing ticked at.voidsetCurrentDelay(int ticksToNext) Sets the delay to next execution for the currently executed transitionvoidsetTickRate(int tickRate) Returns the current rate the statemachine is beeing ticked at.voidtick()Tick the statemachine.Methods inherited from class com.minecolonies.api.entity.ai.statemachine.basestatemachine.BasicStateMachine
addTransition, addTransitionGroup, getHistory, getState, onException, removeTransition, reset, setHistoryEnabled, transitionToNextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.minecolonies.api.entity.ai.statemachine.basestatemachine.IStateMachine
addTransition, addTransitionGroup, getHistory, getState, removeTransition, reset, setHistoryEnabled, transitionToNext
-
Field Details
-
slownessFactor
public static double slownessFactorTPS factor of the server
-
-
Constructor Details
-
TickRateStateMachine
public TickRateStateMachine(@NotNull S initialState, @NotNull @NotNull Consumer<RuntimeException> exceptionHandler) Construct a new StateMachine- Parameters:
initialState- the initial state.exceptionHandler- the exception handler.
-
TickRateStateMachine
public TickRateStateMachine(@NotNull S initialState, @NotNull @NotNull Consumer<RuntimeException> exceptionHandler, int tickRate) Construct a new StateMachine- Parameters:
initialState- the initial state.exceptionHandler- the exception handler.
-
-
Method Details
-
tick
public void tick()Tick the statemachine.- Specified by:
tickin interfaceIStateMachine<ITickingTransition<S extends IState>,S extends IState> - Specified by:
tickin interfaceITickRateStateMachine<S extends IState>- Overrides:
tickin classBasicStateMachine<ITickingTransition<S extends IState>,S extends IState>
-
checkTransition
Check the condition for a transition- Specified by:
checkTransitionin interfaceIStateMachine<ITickingTransition<S extends IState>,S extends IState> - Specified by:
checkTransitionin interfaceITickRateStateMachine<S extends IState>- Overrides:
checkTransitionin classBasicStateMachine<ITickingTransition<S extends IState>,S extends IState> - Parameters:
transition- the target to check- Returns:
- true if this target worked and we should stop executing this tick
-
getTickRate
public int getTickRate()Description copied from interface:ITickRateStateMachineReturns the current rate the statemachine is beeing ticked at.- Specified by:
getTickRatein interfaceITickRateStateMachine<S extends IState>- Returns:
- the tickrate
-
setTickRate
public void setTickRate(int tickRate) Description copied from interface:ITickRateStateMachineReturns the current rate the statemachine is beeing ticked at.- Specified by:
setTickRatein interfaceITickRateStateMachine<S extends IState>- Parameters:
tickRate- the tick rate to set.
-
setCurrentDelay
public void setCurrentDelay(int ticksToNext) Description copied from interface:ITickRateStateMachineSets the delay to next execution for the currently executed transition- Specified by:
setCurrentDelayin interfaceITickRateStateMachine<S extends IState>- Parameters:
ticksToNext-
-