-
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.
Showing
9 changed files
with
135 additions
and
7 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
39 changes: 39 additions & 0 deletions
39
...com/lovetropics/minigames/common/core/game/behavior/instances/team/SyncTeamsBehavior.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,39 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.instances.team; | ||
|
||
import com.lovetropics.minigames.common.core.game.GameException; | ||
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.event.EventRegistrar; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GamePhaseEvents; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GameTeamEvents; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateSender; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
import com.lovetropics.minigames.common.core.game.client_state.instance.TeamMembersClientState; | ||
import com.lovetropics.minigames.common.core.game.state.team.GameTeamKey; | ||
import com.lovetropics.minigames.common.core.game.state.team.TeamState; | ||
import com.lovetropics.minigames.common.core.network.LoveTropicsNetwork; | ||
import com.lovetropics.minigames.common.core.network.SetGameClientStateMessage; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraftforge.network.PacketDistributor; | ||
|
||
public class SyncTeamsBehavior implements IGameBehavior { | ||
public static final Codec<SyncTeamsBehavior> CODEC = Codec.unit(SyncTeamsBehavior::new); | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) throws GameException { | ||
events.listen(GameTeamEvents.SET_GAME_TEAM, (player, teams, team) -> sendSync(teams, team)); | ||
events.listen(GameTeamEvents.REMOVE_FROM_TEAM, (player, teams, team) -> { | ||
sendSync(teams, team); | ||
GameClientStateSender.get().byPlayer(player).enqueueRemove(GameClientStateTypes.TEAM_MEMBERS.get()); | ||
}); | ||
|
||
events.listen(GamePhaseEvents.STOP, reason -> LoveTropicsNetwork.CHANNEL.send(PacketDistributor.ALL.with(() -> null), SetGameClientStateMessage.remove(GameClientStateTypes.TEAM_MEMBERS.get()))); | ||
} | ||
|
||
private void sendSync(TeamState teams, GameTeamKey key) { | ||
final var team = teams.getPlayersForTeam(key); | ||
team.forEach(player -> GameClientStateSender.get().byPlayer(player).enqueueSet(new TeamMembersClientState(team.stream().filter(p -> p != player) | ||
.map(ServerPlayer::getUUID).toList()))); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...om/lovetropics/minigames/common/core/game/client_state/instance/GlowTeamMembersState.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,15 @@ | ||
package com.lovetropics.minigames.common.core.game.client_state.instance; | ||
|
||
import com.lovetropics.minigames.common.core.game.client_state.GameClientState; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
|
||
public class GlowTeamMembersState implements GameClientState { | ||
public static final GlowTeamMembersState INSTANCE = new GlowTeamMembersState(); | ||
private GlowTeamMembersState() {} | ||
|
||
@Override | ||
public GameClientStateType<?> getType() { | ||
return GameClientStateTypes.GLOW_TEAM_MEMBERS.get(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../lovetropics/minigames/common/core/game/client_state/instance/TeamMembersClientState.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,21 @@ | ||
package com.lovetropics.minigames.common.core.game.client_state.instance; | ||
|
||
import com.lovetropics.minigames.common.core.game.client_state.GameClientState; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.UUIDUtil; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record TeamMembersClientState(List<UUID> teamMembers) implements GameClientState { | ||
public static final Codec<TeamMembersClientState> CODEC = UUIDUtil.CODEC.listOf().fieldOf("members") | ||
.xmap(TeamMembersClientState::new, TeamMembersClientState::teamMembers) | ||
.codec(); | ||
|
||
@Override | ||
public GameClientStateType<?> getType() { | ||
return GameClientStateTypes.TEAM_MEMBERS.get(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/lovetropics/minigames/mixin/client/MinecraftMixin.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,33 @@ | ||
package com.lovetropics.minigames.mixin.client; | ||
|
||
import com.lovetropics.minigames.client.game.ClientGameStateManager; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MinecraftMixin { | ||
@Nullable | ||
@Shadow | ||
private LocalPlayer player; | ||
|
||
@Inject(at = @At("HEAD"), method = "shouldEntityAppearGlowing", cancellable = true) | ||
private void ltminigames$glowingTeamMembers(Entity entity, CallbackInfoReturnable<Boolean> cir) { | ||
if (entity.getType() == EntityType.PLAYER && ClientGameStateManager.getOrNull(GameClientStateTypes.GLOW_TEAM_MEMBERS) != null) { | ||
final var team = ClientGameStateManager.getOrNull(GameClientStateTypes.TEAM_MEMBERS); | ||
|
||
if (team != null && (team.teamMembers().contains(entity.getUUID()) || player == entity)) { | ||
cir.setReturnValue(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