-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use separate behaviours for game end effects in Crafing Bee and Conne…
…ct Four
- Loading branch information
Showing
8 changed files
with
95 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...a/com/lovetropics/minigames/common/core/game/behavior/instances/action/DelayedAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.instances.action; | ||
|
||
import com.lovetropics.minigames.common.core.game.IGamePhase; | ||
import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior; | ||
import com.lovetropics.minigames.common.core.game.behavior.action.ActionTarget; | ||
import com.lovetropics.minigames.common.core.game.behavior.action.GameActionList; | ||
import com.lovetropics.minigames.common.core.game.behavior.action.NoneActionTarget; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.util.valueproviders.IntProvider; | ||
|
||
public record DelayedAction<T>( | ||
IntProvider delay, | ||
GameActionList<?> actions, | ||
ActionTarget<T> target | ||
) implements IGameBehavior { | ||
public static final MapCodec<DelayedAction<?>> CODEC = RecordCodecBuilder.mapCodec(i -> i.group( | ||
IntProvider.POSITIVE_CODEC.fieldOf("delay").forGetter(b -> b.delay), | ||
GameActionList.MAP_CODEC.forGetter(c -> c.actions), | ||
ActionTarget.CODEC.optionalFieldOf("target", NoneActionTarget.INSTANCE).forGetter(c -> c.target) | ||
).apply(i, DelayedAction::new)); | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) { | ||
actions.register(game, events); | ||
|
||
target.listenAndCaptureSource(events, (context, targets) -> { | ||
int ticks = delay.sample(game.random()); | ||
game.scheduler().runAfterTicks(ticks, () -> { | ||
if (actions.target.type() == target.type()) { | ||
actions.applyIf(target::type, game, context, targets); | ||
} else { | ||
actions.apply(game, context); | ||
} | ||
}); | ||
return true; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters