调整m2hb的可用perk列表,暂时注释掉无人机相关内容
This commit is contained in:
parent
2a109cc9ef
commit
c16d56821e
4 changed files with 182 additions and 211 deletions
|
@ -1,70 +1,54 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
||||
import com.atsuishio.superbwarfare.item.Monitor;
|
||||
import com.atsuishio.superbwarfare.tools.DronesTool;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.InputEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Code based on @Mafuyu404's <a href="https://github.com/Mafuyu404/DiligentStalker">DiligentStalker</a>
|
||||
*/
|
||||
//@net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Mod.MODID, value = Dist.CLIENT)
|
||||
public class DroneEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(ClientTickEvent.Post event) {
|
||||
if (Minecraft.getInstance().screen != null) return;
|
||||
|
||||
var player = Minecraft.getInstance().player;
|
||||
UUID entityUUID = Monitor.getDroneUUID(player);
|
||||
if (entityUUID != null) {
|
||||
ClientLevel level = player.clientLevel;
|
||||
level.entitiesForRendering().forEach(entity -> {
|
||||
if (entity.getUUID().equals(entityUUID)) {
|
||||
DronesTool.connect(player, entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!DronesTool.hasInstanceOf(player)) return;
|
||||
DronesTool instance = DronesTool.getInstanceOf(player);
|
||||
Entity stalker = instance.getDrone();
|
||||
// TODO 调整角度?
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onInteract(PlayerInteractEvent.EntityInteract event) {
|
||||
if (event.getSide().isClient()) {
|
||||
var player = event.getEntity();
|
||||
if (player.isShiftKeyDown()) return;
|
||||
if (event.getItemStack().is(ModItems.MONITOR.get())) {
|
||||
DronesTool.connect(player, event.getTarget());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onInputKey(InputEvent.Key event) {
|
||||
if (Minecraft.getInstance().screen != null) return;
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (!DronesTool.hasInstanceOf(player)) return;
|
||||
if (event.getAction() == InputConstants.PRESS) {
|
||||
if (event.getKey() == ModKeyMappings.DISMOUNT.getKey().getValue()) {
|
||||
if (DronesTool.hasInstanceOf(player)) {
|
||||
DronesTool.getInstanceOf(player).disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// @SubscribeEvent
|
||||
// public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
// if (Minecraft.getInstance().screen != null) return;
|
||||
// if (event.phase != TickEvent.Phase.END) return;
|
||||
// var player = Minecraft.getInstance().player;
|
||||
// UUID entityUUID = Monitor.getDroneUUID(player);
|
||||
// if (entityUUID != null) {
|
||||
// ClientLevel level = player.clientLevel;
|
||||
// level.entitiesForRendering().forEach(entity -> {
|
||||
// if (entity.getUUID().equals(entityUUID)) {
|
||||
// DronesTool.connect(player, entity);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// if (!DronesTool.hasInstanceOf(player)) return;
|
||||
// DronesTool instance = DronesTool.getInstanceOf(player);
|
||||
// Entity stalker = instance.getDrone();
|
||||
// // TODO 调整角度?
|
||||
// }
|
||||
//
|
||||
// @SubscribeEvent
|
||||
// public static void onInteract(PlayerInteractEvent.EntityInteract event) {
|
||||
// if (event.getSide().isClient()) {
|
||||
// var player = event.getEntity();
|
||||
// if (player.isShiftKeyDown()) return;
|
||||
// if (event.getItemStack().is(ModItems.MONITOR.get())) {
|
||||
// DronesTool.connect(player, event.getTarget());
|
||||
// event.setCanceled(true);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @SubscribeEvent
|
||||
// public static void onInputKey(InputEvent.Key event) {
|
||||
// if (Minecraft.getInstance().screen != null) return;
|
||||
// Player player = Minecraft.getInstance().player;
|
||||
// if (!DronesTool.hasInstanceOf(player)) return;
|
||||
// if (event.getAction() == InputConstants.PRESS) {
|
||||
// if (event.getKey() == ModKeyMappings.DISMOUNT.getKey().getValue()) {
|
||||
// if (DronesTool.hasInstanceOf(player)) {
|
||||
// DronesTool.getInstanceOf(player).disconnect();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.item;
|
|||
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ResetCameraTypeMessage;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
|
@ -30,18 +29,16 @@ import net.neoforged.api.distmarker.Dist;
|
|||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Monitor extends Item {
|
||||
|
||||
public static final String LINKED = "Linked";
|
||||
public static final String LINKED_DRONE = "LinkedDrone";
|
||||
public static final String DRONE_UUID = "DroneUUID";
|
||||
// public static final String DRONE_UUID = "DroneUUID";
|
||||
|
||||
public Monitor() {
|
||||
super(new Properties().stacksTo(1));
|
||||
|
@ -199,15 +196,15 @@ public class Monitor extends Item {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UUID getDroneUUID(Player player) {
|
||||
if (player == null) return null;
|
||||
if (player.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
var tag = NBTTool.getTag(player.getMainHandItem());
|
||||
if (tag.contains(DRONE_UUID)) {
|
||||
return tag.getUUID(DRONE_UUID);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// @Nullable
|
||||
// public static UUID getDroneUUID(Player player) {
|
||||
// if (player == null) return null;
|
||||
// if (player.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
// CompoundTag tag = player.getMainHandItem().getOrCreateTag();
|
||||
// if (tag.contains(DRONE_UUID)) {
|
||||
// return tag.getUUID(DRONE_UUID);
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,142 +1,133 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Code based on @Mafuyu404's <a href="https://github.com/Mafuyu404/DiligentStalker">DiligentStalker</a>
|
||||
*/
|
||||
public class DronesTool {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private final int droneId;
|
||||
public final Level level;
|
||||
public static final ConcurrentHashMap<UUID, Integer> INSTANCE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ConcurrentHashMap<UUID, DronesTool> INSTANCE_CACHE = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentHashMap<Integer, DronesTool> DRONES_CACHE = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentHashMap<Integer, UUID> DRONE_TO_PLAYER = new ConcurrentHashMap<>();
|
||||
|
||||
// 缓存失效时间
|
||||
private static final long CACHE_EXPIRE_TIME = 5000;
|
||||
private long lastAccessTime;
|
||||
|
||||
public DronesTool(UUID playerUUID, int droneId, Level level) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.droneId = droneId;
|
||||
this.level = level;
|
||||
this.lastAccessTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
this.lastAccessTime = System.currentTimeMillis();
|
||||
return this.level.getPlayerByUUID(this.playerUUID);
|
||||
}
|
||||
|
||||
public Entity getDrone() {
|
||||
this.lastAccessTime = System.currentTimeMillis();
|
||||
return this.level.getEntity(this.droneId);
|
||||
}
|
||||
|
||||
public static DronesTool connect(Player player, Entity stalker) {
|
||||
if (player == null || stalker == null) return null;
|
||||
// 这边可能需要修改一下逻辑,不知道原代码部分是否允许1玩家对n无人机
|
||||
if (hasInstanceOf(player) || hasInstanceOf(stalker)) return null;
|
||||
|
||||
if (player.level().isClientSide) {
|
||||
// TODO 向客户端发送连接的网络包
|
||||
}
|
||||
|
||||
player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true);
|
||||
|
||||
INSTANCE_MAP.put(player.getUUID(), stalker.getId());
|
||||
DRONE_TO_PLAYER.put(stalker.getId(), player.getUUID());
|
||||
|
||||
DronesTool instance = new DronesTool(player.getUUID(), stalker.getId(), player.level());
|
||||
INSTANCE_CACHE.put(player.getUUID(), instance);
|
||||
DRONES_CACHE.put(stalker.getId(), instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static DronesTool getInstanceOf(Entity entity) {
|
||||
if (entity == null) return null;
|
||||
|
||||
UUID uuid = entity.getUUID();
|
||||
int id = entity.getId();
|
||||
|
||||
DronesTool cache = INSTANCE_CACHE.get(uuid);
|
||||
if (cache != null && !isCacheExpired(cache)) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
cache = DRONES_CACHE.get(id);
|
||||
if (cache != null && !isCacheExpired(cache)) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
boolean isPlayer = INSTANCE_MAP.containsKey(uuid);
|
||||
boolean isDrone = DRONE_TO_PLAYER.containsKey(id);
|
||||
|
||||
DronesTool instance = null;
|
||||
if (isPlayer) {
|
||||
var stalkerId = INSTANCE_MAP.get(uuid);
|
||||
if (stalkerId != null) {
|
||||
instance = new DronesTool(uuid, stalkerId, entity.level());
|
||||
INSTANCE_CACHE.put(uuid, instance);
|
||||
}
|
||||
} else if (isDrone) {
|
||||
UUID playerUUID = DRONE_TO_PLAYER.get(id);
|
||||
if (playerUUID != null) {
|
||||
instance = new DronesTool(playerUUID, id, entity.level());
|
||||
DRONES_CACHE.put(id, instance);
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (level.isClientSide) {
|
||||
// TODO 向客户端发送断开连接的网络包
|
||||
}
|
||||
INSTANCE_MAP.remove(this.playerUUID);
|
||||
DRONE_TO_PLAYER.remove(this.droneId);
|
||||
INSTANCE_CACHE.remove(this.playerUUID);
|
||||
DRONES_CACHE.remove(this.droneId);
|
||||
}
|
||||
|
||||
public static boolean hasInstanceOf(Entity entity) {
|
||||
if (entity == null) return false;
|
||||
|
||||
UUID uuid = entity.getUUID();
|
||||
if (INSTANCE_CACHE.containsKey(uuid) && !isCacheExpired(INSTANCE_CACHE.get(uuid))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = entity.getId();
|
||||
if (DRONES_CACHE.containsKey(id) && !isCacheExpired(DRONES_CACHE.get(id))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (INSTANCE_MAP.containsKey(uuid) || INSTANCE_MAP.containsValue(id));
|
||||
}
|
||||
|
||||
private static boolean isCacheExpired(DronesTool instance) {
|
||||
return System.currentTimeMillis() - instance.lastAccessTime > CACHE_EXPIRE_TIME;
|
||||
}
|
||||
|
||||
public static void cleanupExpiredCache() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
INSTANCE_CACHE.entrySet().removeIf(entry ->
|
||||
currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
|
||||
DRONES_CACHE.entrySet().removeIf(entry ->
|
||||
currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
|
||||
}
|
||||
// private final UUID playerUUID;
|
||||
// private final int droneId;
|
||||
// public final Level level;
|
||||
// public static final ConcurrentHashMap<UUID, Integer> INSTANCE_MAP = new ConcurrentHashMap<>();
|
||||
//
|
||||
// private static final ConcurrentHashMap<UUID, DronesTool> INSTANCE_CACHE = new ConcurrentHashMap<>();
|
||||
// private static final ConcurrentHashMap<Integer, DronesTool> DRONES_CACHE = new ConcurrentHashMap<>();
|
||||
// private static final ConcurrentHashMap<Integer, UUID> DRONE_TO_PLAYER = new ConcurrentHashMap<>();
|
||||
//
|
||||
// // 缓存失效时间
|
||||
// private static final long CACHE_EXPIRE_TIME = 5000;
|
||||
// private long lastAccessTime;
|
||||
//
|
||||
// public DronesTool(UUID playerUUID, int droneId, Level level) {
|
||||
// this.playerUUID = playerUUID;
|
||||
// this.droneId = droneId;
|
||||
// this.level = level;
|
||||
// this.lastAccessTime = System.currentTimeMillis();
|
||||
// }
|
||||
//
|
||||
// public Player getPlayer() {
|
||||
// this.lastAccessTime = System.currentTimeMillis();
|
||||
// return this.level.getPlayerByUUID(this.playerUUID);
|
||||
// }
|
||||
//
|
||||
// public Entity getDrone() {
|
||||
// this.lastAccessTime = System.currentTimeMillis();
|
||||
// return this.level.getEntity(this.droneId);
|
||||
// }
|
||||
//
|
||||
// public static DronesTool connect(Player player, Entity stalker) {
|
||||
// if (player == null || stalker == null) return null;
|
||||
// // 这边可能需要修改一下逻辑,不知道原代码部分是否允许1玩家对n无人机
|
||||
// if (hasInstanceOf(player) || hasInstanceOf(stalker)) return null;
|
||||
//
|
||||
// if (player.level().isClientSide) {
|
||||
// // TODO 向客户端发送连接的网络包
|
||||
// }
|
||||
//
|
||||
// player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true);
|
||||
//
|
||||
// INSTANCE_MAP.put(player.getUUID(), stalker.getId());
|
||||
// DRONE_TO_PLAYER.put(stalker.getId(), player.getUUID());
|
||||
//
|
||||
// DronesTool instance = new DronesTool(player.getUUID(), stalker.getId(), player.level());
|
||||
// INSTANCE_CACHE.put(player.getUUID(), instance);
|
||||
// DRONES_CACHE.put(stalker.getId(), instance);
|
||||
//
|
||||
// return instance;
|
||||
// }
|
||||
//
|
||||
// public static DronesTool getInstanceOf(Entity entity) {
|
||||
// if (entity == null) return null;
|
||||
//
|
||||
// UUID uuid = entity.getUUID();
|
||||
// int id = entity.getId();
|
||||
//
|
||||
// DronesTool cache = INSTANCE_CACHE.get(uuid);
|
||||
// if (cache != null && !isCacheExpired(cache)) {
|
||||
// return cache;
|
||||
// }
|
||||
//
|
||||
// cache = DRONES_CACHE.get(id);
|
||||
// if (cache != null && !isCacheExpired(cache)) {
|
||||
// return cache;
|
||||
// }
|
||||
//
|
||||
// boolean isPlayer = INSTANCE_MAP.containsKey(uuid);
|
||||
// boolean isDrone = DRONE_TO_PLAYER.containsKey(id);
|
||||
//
|
||||
// DronesTool instance = null;
|
||||
// if (isPlayer) {
|
||||
// var stalkerId = INSTANCE_MAP.get(uuid);
|
||||
// if (stalkerId != null) {
|
||||
// instance = new DronesTool(uuid, stalkerId, entity.level());
|
||||
// INSTANCE_CACHE.put(uuid, instance);
|
||||
// }
|
||||
// } else if (isDrone) {
|
||||
// UUID playerUUID = DRONE_TO_PLAYER.get(id);
|
||||
// if (playerUUID != null) {
|
||||
// instance = new DronesTool(playerUUID, id, entity.level());
|
||||
// DRONES_CACHE.put(id, instance);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return instance;
|
||||
// }
|
||||
//
|
||||
// public void disconnect() {
|
||||
// if (level.isClientSide) {
|
||||
// // TODO 向客户端发送断开连接的网络包
|
||||
// }
|
||||
// INSTANCE_MAP.remove(this.playerUUID);
|
||||
// DRONE_TO_PLAYER.remove(this.droneId);
|
||||
// INSTANCE_CACHE.remove(this.playerUUID);
|
||||
// DRONES_CACHE.remove(this.droneId);
|
||||
// }
|
||||
//
|
||||
// public static boolean hasInstanceOf(Entity entity) {
|
||||
// if (entity == null) return false;
|
||||
//
|
||||
// UUID uuid = entity.getUUID();
|
||||
// if (INSTANCE_CACHE.containsKey(uuid) && !isCacheExpired(INSTANCE_CACHE.get(uuid))) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// int id = entity.getId();
|
||||
// if (DRONES_CACHE.containsKey(id) && !isCacheExpired(DRONES_CACHE.get(id))) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return (INSTANCE_MAP.containsKey(uuid) || INSTANCE_MAP.containsValue(id));
|
||||
// }
|
||||
//
|
||||
// private static boolean isCacheExpired(DronesTool instance) {
|
||||
// return System.currentTimeMillis() - instance.lastAccessTime > CACHE_EXPIRE_TIME;
|
||||
// }
|
||||
//
|
||||
// public static void cleanupExpiredCache() {
|
||||
// long currentTime = System.currentTimeMillis();
|
||||
// INSTANCE_CACHE.entrySet().removeIf(entry ->
|
||||
// currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
|
||||
// DRONES_CACHE.entrySet().removeIf(entry ->
|
||||
// currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"AvailablePerks": [
|
||||
"@Ammo",
|
||||
"superbwarfare:fourth_times_charm",
|
||||
"superbwarfare:turbo_charger",
|
||||
"superbwarfare:subsistence",
|
||||
"superbwarfare:powerful_attraction",
|
||||
"superbwarfare:intelligent_chip",
|
||||
|
|
Loading…
Add table
Reference in a new issue