generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fr translation + Mixin clean + Networking bug fix
- Loading branch information
1 parent
62216d3
commit 6aecc88
Showing
14 changed files
with
292 additions
and
226 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
66 changes: 60 additions & 6 deletions
66
src/main/java/fr/vana_mod/nicofighter45/main/server/ServerInitializer.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 |
---|---|---|
@@ -1,24 +1,78 @@ | ||
package fr.vana_mod.nicofighter45.main.server; | ||
|
||
import fr.vana_mod.nicofighter45.main.CommonInitializer; | ||
import net.fabricmc.api.DedicatedServerModInitializer; | ||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.*; | ||
|
||
public class ServerInitializer implements DedicatedServerModInitializer { | ||
|
||
public static final String SERVER_MSG_PREFIX = "§8[§6Server§8] §f"; | ||
public static final String BROADCAST_MSG_PREFIX = "§8[§4BROADCAST§8] §f"; | ||
|
||
public static Map<UUID, CustomPlayer> players = new HashMap<>(); | ||
private static final Map<UUID, CustomPlayer> players = new HashMap<>(); | ||
public static boolean isOn = true; | ||
|
||
public static boolean jump = false; | ||
|
||
@Override | ||
public void onInitializeServer() { | ||
System.out.println("The Server Side is loading"); | ||
} | ||
|
||
@Contract(pure = true) | ||
public static @NotNull Set<UUID> getPlayersUUID(){ | ||
return players.keySet(); | ||
} | ||
|
||
public static void setPlayerHearts(@NotNull ServerPlayerEntity player, int hearts){ | ||
players.get(player.getUuid()).setHeart(hearts); | ||
sendInfoToClient(player); | ||
} | ||
|
||
public static void setPlayerRegen(@NotNull ServerPlayerEntity player, int regen){ | ||
players.get(player.getUuid()).setRegen(regen); | ||
sendInfoToClient(player); | ||
} | ||
|
||
public static void setPlayerBase(@NotNull ServerPlayerEntity player, BlockPos base){ | ||
players.get(player.getUuid()).setBase(base); | ||
sendInfoToClient(player); | ||
} | ||
|
||
public static @Nullable CustomPlayer getNullableCustomPlayer(UUID uuid){ | ||
if(!players.containsKey(uuid)){ | ||
return null; | ||
} | ||
return players.get(uuid); | ||
} | ||
|
||
public static CustomPlayer getCustomPlayer(UUID uuid){ | ||
return players.get(uuid); | ||
} | ||
|
||
public static void newPlayer(@NotNull ServerPlayerEntity player){ | ||
players.put(player.getUuid(), new CustomPlayer(10, 0, Objects.requireNonNull(player.getServer()).getOverworld().getSpawnPos())); | ||
sendInfoToClient(player); | ||
} | ||
|
||
public static void loadPlayer(@NotNull UUID uuid, CustomPlayer customPlayer){ | ||
players.put(uuid, customPlayer); | ||
} | ||
|
||
private static void sendInfoToClient(@NotNull ServerPlayerEntity player){ | ||
CustomPlayer customPlayer = getCustomPlayer(player.getUuid()); | ||
PacketByteBuf buf = PacketByteBufs.create(); | ||
buf.writeInt(customPlayer.getHeart()); | ||
buf.writeInt(customPlayer.getRegen()); | ||
buf.writeBlockPos(customPlayer.getBase()); | ||
ServerPlayNetworking.send(player, CommonInitializer.UPDATE_CUSTOM_PLAYER_PACKET, buf); | ||
} | ||
|
||
} |
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
Oops, something went wrong.