-
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.
Rework action targeting to support custom targets
- Loading branch information
1 parent
ac536ef
commit 2dc7c6d
Showing
35 changed files
with
386 additions
and
149 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/lovetropics/minigames/common/core/game/behavior/action/ActionTarget.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,23 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.action; | ||
|
||
import com.lovetropics.minigames.common.core.game.IGamePhase; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GameEventListeners; | ||
import com.mojang.datafixers.util.Either; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.util.ExtraCodecs; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public interface ActionTarget<T> { | ||
Codec<ActionTarget<?>> CODEC = ExtraCodecs.lazyInitializedCodec(() -> ActionTargetTypes.REGISTRY.get().getCodec()) | ||
.dispatch(ActionTarget::type, Function.identity()); | ||
Codec<ActionTarget<?>> FALLBACK_PLAYER = ExtraCodecs.xor(CODEC, PlayerActionTarget.Target.CODEC) | ||
.xmap(e -> e.map(Function.identity(), PlayerActionTarget::new), Either::left); | ||
|
||
List<T> resolve(IGamePhase phase, Iterable<T> sources); | ||
|
||
boolean apply(IGamePhase game, GameEventListeners listeners, GameActionContext context, Iterable<T> sources); | ||
|
||
Codec<? extends ActionTarget<T>> type(); | ||
} |
42 changes: 42 additions & 0 deletions
42
...in/java/com/lovetropics/minigames/common/core/game/behavior/action/ActionTargetTypes.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,42 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.action; | ||
|
||
import com.lovetropics.minigames.Constants; | ||
import com.lovetropics.minigames.LoveTropics; | ||
import com.lovetropics.minigames.common.core.game.predicate.entity.EntityPredicate; | ||
import com.lovetropics.minigames.common.core.game.predicate.entity.EntityTypeEntityPredicate; | ||
import com.lovetropics.minigames.common.util.registry.LoveTropicsRegistrate; | ||
import com.mojang.serialization.Codec; | ||
import com.tterrag.registrate.util.entry.RegistryEntry; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.IForgeRegistry; | ||
import net.minecraftforge.registries.RegistryBuilder; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ActionTargetTypes { | ||
public static final ResourceKey<Registry<Codec<? extends ActionTarget<?>>>> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(Constants.MODID, "action_target_types")); | ||
public static final DeferredRegister<Codec<? extends ActionTarget<?>>> REGISTER = DeferredRegister.create(REGISTRY_KEY, Constants.MODID); | ||
|
||
public static final Supplier<IForgeRegistry<Codec<? extends ActionTarget<?>>>> REGISTRY = REGISTER.makeRegistry(() -> new RegistryBuilder<Codec<? extends ActionTarget<?>>>() | ||
.disableSync() | ||
.disableSaving()); | ||
|
||
private static final LoveTropicsRegistrate REGISTRATE = LoveTropics.registrate(); | ||
|
||
public static final RegistryObject<Codec<PlayerActionTarget>> PLAYER = register("player", PlayerActionTarget.CODEC); | ||
public static final RegistryObject<Codec<PlotActionTarget>> PLOT = register("plot", PlotActionTarget.CODEC); | ||
public static final RegistryObject<Codec<NoneActionTarget>> NONE = register("none", NoneActionTarget.CODEC); | ||
|
||
public static <T extends ActionTarget<?>> RegistryObject<Codec<T>> register(final String name, final Codec<T> codec) { | ||
return REGISTER.register(name, () -> codec); | ||
} | ||
|
||
public static void init(IEventBus modBus) { | ||
REGISTER.register(modBus); | ||
} | ||
} |
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
Oops, something went wrong.