Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClientModConfigs {
public static void registerClientConfigs(FMLJavaModLoadingContext mlctx) {
mlctx.registerConfig(ModConfig.Type.CLIENT,
ReignOfNetherClientConfigs.SPEC,
"reignofnether-client-" + ReignOfNether.VERSION_STRING + ".toml");
"reignofnether-client.toml");

mlctx.registerExtensionPoint(
ConfigScreenHandler.ConfigScreenFactory.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.solegendary.reignofnether;

import com.solegendary.reignofnether.blocks.BlockClientEvents;
import com.solegendary.reignofnether.blocks.InvisibleBlockRenderer;
import com.solegendary.reignofnether.config.ReignOfNetherClientConfigs;
import com.solegendary.reignofnether.orthoview.OrthoviewClientEvents;
import com.solegendary.reignofnether.blocks.SkullTypes;
import com.solegendary.reignofnether.building.BuildingPlacement;
import com.solegendary.reignofnether.building.BuildingUtils;
Expand Down Expand Up @@ -181,9 +184,12 @@
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void onClientSetupEvent(FMLClientSetupEvent evt) {
// read on hot render paths, so kept in statics; the toggles write them back
OrthoviewClientEvents.hideLeavesMethod = ReignOfNetherClientConfigs.HIDE_LEAVES.get();
BlockClientEvents.nightCircleMode = ReignOfNetherClientConfigs.NIGHT_CIRCLES.get();
evt.enqueueWork(() -> {
MenuScreens.register(ContainerRegistrar.TOPDOWNGUI_CONTAINER.get(), TopdownGui::new);
ItemBlockRenderTypes.setRenderLayer(

Check warning on line 192 in src/main/java/com/solegendary/reignofnether/ClientModEvents.java

View workflow job for this annotation

GitHub Actions / build (17, ubuntu-latest)

[removal] setRenderLayer(Block,RenderType) in ItemBlockRenderTypes has been deprecated and marked for removal
BlockRegistrar.UNEXTINGUISHABLE_SOUL_FIRE.get(),
RenderType.cutout()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import com.solegendary.reignofnether.gamerules.GameruleClient;
import com.solegendary.reignofnether.player.PlayerClientEvents;
import com.solegendary.reignofnether.unit.interfaces.Unit;
import com.solegendary.reignofnether.util.WorldState;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.LivingEntity;

import java.util.*;

public class AlliancesClient {

static {
WorldState.onClientReset(AlliancesClient::resetAllAlliances);
}
private static final Minecraft MC = Minecraft.getInstance();

private static final Map<String, Set<String>> alliances = new HashMap<>();
public static final Set<String> inboundPendingAlliances = new HashSet<>();
public static final Set<String> outboundPendingAlliances = new HashSet<>();
public static final Set<String> inboundPendingAlliances = WorldState.client(new HashSet<>());
public static final Set<String> outboundPendingAlliances = WorldState.client(new HashSet<>());
public static final HashSet<String> playersWithAlliedControl = new HashSet<>();

public static boolean sharingAllyControl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import com.solegendary.reignofnether.scenario.ScenarioServerEvents;
import com.solegendary.reignofnether.scenario.ScenarioUtils;
import com.solegendary.reignofnether.unit.interfaces.Unit;
import com.solegendary.reignofnether.util.WorldState;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.*;

public class AlliancesServerEvents {
private static final Map<String, Set<String>> alliances = new HashMap<>();
public static final Map<String, Set<String>> pendingAlliances = new HashMap<>();
public static final HashSet<String> playersWithAlliedControl = new HashSet<>();
private static final Map<String, Set<String>> alliances = WorldState.server(new HashMap<>());
public static final Map<String, Set<String>> pendingAlliances = WorldState.server(new HashMap<>());
public static final HashSet<String> playersWithAlliedControl = WorldState.server(new HashSet<>());

public static boolean canControlAlly(String player, LivingEntity entity) {
return entity instanceof Unit unit && canControlAlly(player, unit.getOwnerName());
Expand Down Expand Up @@ -144,12 +144,6 @@ public static void syncAlliances() {
}

// statics outlive the world: clear them so the next world opened in this game starts clean
@SubscribeEvent
public static void onServerStopped(ServerStoppedEvent evt) {
alliances.clear();
pendingAlliances.clear();
playersWithAlliedControl.clear();
}

@SubscribeEvent
public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent evt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.solegendary.reignofnether.alliance;

import com.solegendary.reignofnether.chat.SystemMessage;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
Expand Down Expand Up @@ -63,26 +64,26 @@ private static int ally(CommandContext<CommandSourceStack> context) throws Comma

if (context.getSource().getLevel().getGameRules().getRule(GameRuleRegistrar.LOCK_ALLIANCES).get() &&
(PlayerServerEvents.isRTSPlayer(playerName) || PlayerServerEvents.isRTSPlayer(allyPlayerName))) {
player.sendSystemMessage(Component.translatable("alliance.reignofnether.alliances_lock"));
player.sendSystemMessage(SystemMessage.error(Component.translatable("alliance.reignofnether.alliances_lock")));
return 0;
}
if (context.getSource().getLevel().getGameRules().getRule(GameRuleRegistrar.COOP_MODE).get() &&
(PlayerServerEvents.isRTSPlayer(playerName) || PlayerServerEvents.isRTSPlayer(allyPlayerName))) {
player.sendSystemMessage(Component.translatable("alliance.reignofnether.alliances_lock_coop"));
player.sendSystemMessage(SystemMessage.error(Component.translatable("alliance.reignofnether.alliances_lock_coop")));
return 0;
}

if (player.equals(allyPlayer)) {
player.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_self", playerName));
player.sendSystemMessage(SystemMessage.error(Component.translatable("alliance.reignofnether.ally_self", playerName)));
return 0;
}
AlliancesServerEvents.pendingAlliances.computeIfAbsent(allyPlayerName, k -> new HashSet<>()).add(playerName);
AllianceClientboundPacket.addPendingAlliance(allyPlayerName, playerName);
context.getSource().sendSuccess(()->Component.translatable("alliance.reignofnether.sent_request", allyPlayerName), false);
context.getSource().sendSuccess(()->SystemMessage.info(Component.translatable("alliance.reignofnether.sent_request", allyPlayerName)), false);
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, allyPlayerName);
allyPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_confirm", playerName, playerName));
allyPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.ally_confirm", playerName, playerName)));
if (PlayerServerEvents.isRTSPlayer(allyPlayerName))
allyPlayer.sendSystemMessage(Component
allyPlayer.sendSystemMessage(SystemMessage.info(Component
.translatable("alliance.reignofnether.accept") // [CLick to accept]
.withStyle(Style.EMPTY
.withColor(ChatFormatting.GREEN)
Expand All @@ -96,7 +97,7 @@ private static int ally(CommandContext<CommandSourceStack> context) throws Comma
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("alliance.reignofnether.cancel")))
)
)
);
));
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, playerName);

return Command.SINGLE_SUCCESS;
Expand All @@ -113,9 +114,9 @@ private static int allyCancelRequest(CommandContext<CommandSourceStack> context)
}
AlliancesServerEvents.pendingAlliances.getOrDefault(playerName, new HashSet<>()).remove(allyPlayerName);
AllianceClientboundPacket.cancelPendingAlliance(allyPlayerName, playerName);
context.getSource().sendSuccess(()->Component.translatable("alliance.reignofnether.ally_request_cancelled_self", allyPlayerName), false);
context.getSource().sendSuccess(()->SystemMessage.info(Component.translatable("alliance.reignofnether.ally_request_cancelled_self", allyPlayerName)), false);
SoundClientboundPacket.playSoundForPlayer(SoundAction.ENEMY, allyPlayerName);
allyPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_request_cancelled", playerName));
allyPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.ally_request_cancelled", playerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.ENEMY, playerName);

return Command.SINGLE_SUCCESS;
Expand All @@ -131,19 +132,19 @@ private static int allyConfirm(CommandContext<CommandSourceStack> context) throw
AlliancesServerEvents.addAlliance(playerName, requesterPlayerName);
AlliancesServerEvents.pendingAlliances.getOrDefault(requesterPlayerName, new HashSet<>()).remove(playerName);

context.getSource().sendSuccess(()->Component.translatable("alliance.reignofnether.now_allied", requesterPlayerName), false);
context.getSource().sendSuccess(()->SystemMessage.info(Component.translatable("alliance.reignofnether.now_allied", requesterPlayerName)), false);
SoundClientboundPacket.playSoundForPlayer(SoundAction.ALLY, requesterPlayerName);
requesterPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_accepted", playerName));
requesterPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.ally_accepted", playerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.ALLY, playerName);

for (ServerPlayer serverPlayer : PlayerServerEvents.players) {
if (!serverPlayer.equals(player) && !serverPlayer.equals(requesterPlayer)) {
serverPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.now_allied_third_party", playerName, requesterPlayerName));
serverPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.now_allied_third_party", playerName, requesterPlayerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, playerName);
}
}
} else {
context.getSource().sendFailure(Component.translatable("alliance.reignofnether.no_request", requesterPlayerName));
context.getSource().sendFailure(SystemMessage.error(Component.translatable("alliance.reignofnether.no_request", requesterPlayerName)));
}
return Command.SINGLE_SUCCESS;
}
Expand All @@ -156,29 +157,29 @@ private static int disband(CommandContext<CommandSourceStack> context) throws Co

if (context.getSource().getLevel().getGameRules().getRule(GameRuleRegistrar.LOCK_ALLIANCES).get() &&
(PlayerServerEvents.isRTSPlayer(playerName) || PlayerServerEvents.isRTSPlayer(allyPlayerName))) {
player.sendSystemMessage(Component.translatable("alliance.reignofnether.alliances_lock"));
player.sendSystemMessage(SystemMessage.error(Component.translatable("alliance.reignofnether.alliances_lock")));
return 0;
}
if (context.getSource().getLevel().getGameRules().getRule(GameRuleRegistrar.COOP_MODE).get() &&
(PlayerServerEvents.isRTSPlayer(playerName) || PlayerServerEvents.isRTSPlayer(allyPlayerName))) {
player.sendSystemMessage(Component.translatable("alliance.reignofnether.alliances_lock_coop"));
player.sendSystemMessage(SystemMessage.error(Component.translatable("alliance.reignofnether.alliances_lock_coop")));
return 0;
}

if (player.equals(allyPlayer)) {
context.getSource().sendFailure(Component.translatable("alliance.reignofnether.disband_self"));
context.getSource().sendFailure(SystemMessage.error(Component.translatable("alliance.reignofnether.disband_self")));
return 0;
}
AlliancesServerEvents.removeAlliance(playerName, allyPlayerName);

player.sendSystemMessage(Component.translatable("alliance.reignofnether.disbanded", allyPlayerName));
player.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.disbanded", allyPlayerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.ENEMY, playerName);
allyPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.disbanded", playerName));
allyPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.disbanded", playerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.ENEMY, allyPlayerName);

for (ServerPlayer serverPlayer : PlayerServerEvents.players) {
if (!serverPlayer.equals(player) && !serverPlayer.equals(allyPlayer)) {
serverPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.disbanded_third_party", playerName, allyPlayerName));
serverPlayer.sendSystemMessage(SystemMessage.info(Component.translatable("alliance.reignofnether.disbanded_third_party", playerName, allyPlayerName)));
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, playerName);
}
}
Expand All @@ -190,7 +191,7 @@ private static int getAlliedControl(CommandContext<CommandSourceStack> context)
String playerName = player.getName().getString();
boolean value = AlliancesServerEvents.playersWithAlliedControl.contains(playerName);
String msgKey = value ? "alliance.reignofnether.ally_control_enabled" : "alliance.reignofnether.ally_control_disabled";
context.getSource().sendSuccess(()->Component.translatable(msgKey, playerName), false);
context.getSource().sendSuccess(()->SystemMessage.info(Component.translatable(msgKey, playerName)), false);
return Command.SINGLE_SUCCESS;
}

Expand All @@ -206,11 +207,11 @@ private static int setAlliedControl(CommandContext<CommandSourceStack> context)
AlliancesServerEvents.playersWithAlliedControl.remove(playerName);

AllianceClientboundPacket.setAllyControl(playerName, value);
context.getSource().sendSuccess(()->Component.translatable(msgKey, playerName), false);
context.getSource().sendSuccess(()->SystemMessage.info(Component.translatable(msgKey, playerName)), false);
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, playerName);

for (String allyPlayerName : AlliancesServerEvents.getAllAllies(playerName)) {
PlayerServerEvents.sendMessageToPlayerNoNewLines(allyPlayerName, msgKey, false, playerName);
PlayerServerEvents.sendMessageToPlayer(allyPlayerName, msgKey, false, playerName);
SoundClientboundPacket.playSoundForPlayer(SoundAction.CHAT, allyPlayerName);
}
return Command.SINGLE_SUCCESS;
Expand Down
Loading
Loading