77 lines
3.6 KiB
Java
77 lines
3.6 KiB
Java
package com.atsuishio.superbwarfare.network;
|
|
|
|
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
|
import com.atsuishio.superbwarfare.client.overlay.DroneUIOverlay;
|
|
import com.atsuishio.superbwarfare.client.screens.FuMO25ScreenHelper;
|
|
import com.atsuishio.superbwarfare.config.client.KillMessageConfig;
|
|
import com.atsuishio.superbwarfare.event.KillMessageHandler;
|
|
import com.atsuishio.superbwarfare.menu.EnergyMenu;
|
|
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
|
|
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
|
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
|
import com.atsuishio.superbwarfare.network.message.RadarMenuOpenMessage;
|
|
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
import com.atsuishio.superbwarfare.tools.PlayerKillRecord;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.world.damagesource.DamageType;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraftforge.fml.LogicalSide;
|
|
import net.minecraftforge.network.NetworkEvent;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Supplier;
|
|
|
|
public class ClientPacketHandler {
|
|
|
|
public static void handleGunsDataMessage(GunsDataMessage message, Supplier<NetworkEvent.Context> ctx) {
|
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
|
GunsTool.gunsData = message.gunsData;
|
|
}
|
|
}
|
|
|
|
public static void handlePlayerKillMessage(Player attacker, Entity target, boolean headshot, ResourceKey<DamageType> damageType, Supplier<NetworkEvent.Context> ctx) {
|
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
|
if (KillMessageHandler.QUEUE.size() >= KillMessageConfig.KILL_MESSAGE_COUNT.get()) {
|
|
KillMessageHandler.QUEUE.poll();
|
|
}
|
|
KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType));
|
|
}
|
|
}
|
|
|
|
public static void handleClientIndicatorMessage(ClientIndicatorMessage message, Supplier<NetworkEvent.Context> ctx) {
|
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
|
switch (message.type) {
|
|
case 1 -> CrossHairOverlay.HEAD_INDICATOR = message.value;
|
|
case 2 -> CrossHairOverlay.KILL_INDICATOR = message.value;
|
|
default -> CrossHairOverlay.HIT_INDICATOR = message.value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void handleSimulationDistanceMessage(int distance, Supplier<NetworkEvent.Context> ctx) {
|
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
|
DroneUIOverlay.MAX_DISTANCE = distance * 16;
|
|
}
|
|
}
|
|
|
|
public static void handleContainerDataMessage(int containerId, List<ContainerDataMessage.Pair> data, Supplier<NetworkEvent.Context> ctx) {
|
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
|
Minecraft mc = Minecraft.getInstance();
|
|
if (mc.player != null && mc.player.containerMenu.containerId == containerId) {
|
|
data.forEach(p -> ((EnergyMenu) mc.player.containerMenu).setData(p.id, p.data));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void handleRadarMenuOpen(RadarMenuOpenMessage message, Supplier<NetworkEvent.Context> ctx) {
|
|
FuMO25ScreenHelper.resetEntities();
|
|
FuMO25ScreenHelper.pos = message.pos;
|
|
}
|
|
|
|
public static void handleRadarMenuClose() {
|
|
FuMO25ScreenHelper.resetEntities();
|
|
FuMO25ScreenHelper.pos = null;
|
|
}
|
|
}
|