调整m2hb的可用perk列表,暂时注释掉无人机相关内容

This commit is contained in:
17146 2025-06-28 01:24:14 +08:00 committed by Light_Quanta
parent 2a109cc9ef
commit c16d56821e
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 182 additions and 211 deletions

View file

@ -1,70 +1,54 @@
package com.atsuishio.superbwarfare.event; 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> * 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) //@net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Mod.MODID, value = Dist.CLIENT)
public class DroneEventHandler { public class DroneEventHandler {
@SubscribeEvent // @SubscribeEvent
public static void onClientTick(ClientTickEvent.Post event) { // public static void onClientTick(TickEvent.ClientTickEvent event) {
if (Minecraft.getInstance().screen != null) return; // if (Minecraft.getInstance().screen != null) return;
// if (event.phase != TickEvent.Phase.END) return;
var player = Minecraft.getInstance().player; // var player = Minecraft.getInstance().player;
UUID entityUUID = Monitor.getDroneUUID(player); // UUID entityUUID = Monitor.getDroneUUID(player);
if (entityUUID != null) { // if (entityUUID != null) {
ClientLevel level = player.clientLevel; // ClientLevel level = player.clientLevel;
level.entitiesForRendering().forEach(entity -> { // level.entitiesForRendering().forEach(entity -> {
if (entity.getUUID().equals(entityUUID)) { // if (entity.getUUID().equals(entityUUID)) {
DronesTool.connect(player, entity); // DronesTool.connect(player, entity);
} // }
}); // });
} // }
if (!DronesTool.hasInstanceOf(player)) return; // if (!DronesTool.hasInstanceOf(player)) return;
DronesTool instance = DronesTool.getInstanceOf(player); // DronesTool instance = DronesTool.getInstanceOf(player);
Entity stalker = instance.getDrone(); // Entity stalker = instance.getDrone();
// TODO 调整角度 // // TODO 调整角度
} // }
//
@SubscribeEvent // @SubscribeEvent
public static void onInteract(PlayerInteractEvent.EntityInteract event) { // public static void onInteract(PlayerInteractEvent.EntityInteract event) {
if (event.getSide().isClient()) { // if (event.getSide().isClient()) {
var player = event.getEntity(); // var player = event.getEntity();
if (player.isShiftKeyDown()) return; // if (player.isShiftKeyDown()) return;
if (event.getItemStack().is(ModItems.MONITOR.get())) { // if (event.getItemStack().is(ModItems.MONITOR.get())) {
DronesTool.connect(player, event.getTarget()); // DronesTool.connect(player, event.getTarget());
event.setCanceled(true); // event.setCanceled(true);
} // }
} // }
} // }
//
@SubscribeEvent // @SubscribeEvent
public static void onInputKey(InputEvent.Key event) { // public static void onInputKey(InputEvent.Key event) {
if (Minecraft.getInstance().screen != null) return; // if (Minecraft.getInstance().screen != null) return;
Player player = Minecraft.getInstance().player; // Player player = Minecraft.getInstance().player;
if (!DronesTool.hasInstanceOf(player)) return; // if (!DronesTool.hasInstanceOf(player)) return;
if (event.getAction() == InputConstants.PRESS) { // if (event.getAction() == InputConstants.PRESS) {
if (event.getKey() == ModKeyMappings.DISMOUNT.getKey().getValue()) { // if (event.getKey() == ModKeyMappings.DISMOUNT.getKey().getValue()) {
if (DronesTool.hasInstanceOf(player)) { // if (DronesTool.hasInstanceOf(player)) {
DronesTool.getInstanceOf(player).disconnect(); // DronesTool.getInstanceOf(player).disconnect();
} // }
} // }
} // }
} // }
} }

View file

@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity; import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.network.message.receive.ResetCameraTypeMessage; import com.atsuishio.superbwarfare.network.message.receive.ResetCameraTypeMessage;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.FormatTool; 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.api.distmarker.OnlyIn;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class Monitor extends Item { public class Monitor extends Item {
public static final String LINKED = "Linked"; public static final String LINKED = "Linked";
public static final String LINKED_DRONE = "LinkedDrone"; public static final String LINKED_DRONE = "LinkedDrone";
public static final String DRONE_UUID = "DroneUUID"; // public static final String DRONE_UUID = "DroneUUID";
public Monitor() { public Monitor() {
super(new Properties().stacksTo(1)); super(new Properties().stacksTo(1));
@ -199,15 +196,15 @@ public class Monitor extends Item {
} }
} }
@Nullable // @Nullable
public static UUID getDroneUUID(Player player) { // public static UUID getDroneUUID(Player player) {
if (player == null) return null; // if (player == null) return null;
if (player.getMainHandItem().is(ModItems.MONITOR.get())) { // if (player.getMainHandItem().is(ModItems.MONITOR.get())) {
var tag = NBTTool.getTag(player.getMainHandItem()); // CompoundTag tag = player.getMainHandItem().getOrCreateTag();
if (tag.contains(DRONE_UUID)) { // if (tag.contains(DRONE_UUID)) {
return tag.getUUID(DRONE_UUID); // return tag.getUUID(DRONE_UUID);
} // }
} // }
return null; // return null;
} // }
} }

View file

@ -1,142 +1,133 @@
package com.atsuishio.superbwarfare.tools; 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> * Code based on @Mafuyu404's <a href="https://github.com/Mafuyu404/DiligentStalker">DiligentStalker</a>
*/ */
public class DronesTool { public class DronesTool {
private final UUID playerUUID; // private final UUID playerUUID;
private final int droneId; // private final int droneId;
public final Level level; // public final Level level;
public static final ConcurrentHashMap<UUID, Integer> INSTANCE_MAP = new ConcurrentHashMap<>(); // public static final ConcurrentHashMap<UUID, Integer> INSTANCE_MAP = new ConcurrentHashMap<>();
//
private static final ConcurrentHashMap<UUID, DronesTool> INSTANCE_CACHE = 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, DronesTool> DRONES_CACHE = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Integer, UUID> DRONE_TO_PLAYER = new ConcurrentHashMap<>(); // private static final ConcurrentHashMap<Integer, UUID> DRONE_TO_PLAYER = new ConcurrentHashMap<>();
//
// 缓存失效时间 // // 缓存失效时间
private static final long CACHE_EXPIRE_TIME = 5000; // private static final long CACHE_EXPIRE_TIME = 5000;
private long lastAccessTime; // private long lastAccessTime;
//
public DronesTool(UUID playerUUID, int droneId, Level level) { // public DronesTool(UUID playerUUID, int droneId, Level level) {
this.playerUUID = playerUUID; // this.playerUUID = playerUUID;
this.droneId = droneId; // this.droneId = droneId;
this.level = level; // this.level = level;
this.lastAccessTime = System.currentTimeMillis(); // this.lastAccessTime = System.currentTimeMillis();
} // }
//
public Player getPlayer() { // public Player getPlayer() {
this.lastAccessTime = System.currentTimeMillis(); // this.lastAccessTime = System.currentTimeMillis();
return this.level.getPlayerByUUID(this.playerUUID); // return this.level.getPlayerByUUID(this.playerUUID);
} // }
//
public Entity getDrone() { // public Entity getDrone() {
this.lastAccessTime = System.currentTimeMillis(); // this.lastAccessTime = System.currentTimeMillis();
return this.level.getEntity(this.droneId); // return this.level.getEntity(this.droneId);
} // }
//
public static DronesTool connect(Player player, Entity stalker) { // public static DronesTool connect(Player player, Entity stalker) {
if (player == null || stalker == null) return null; // if (player == null || stalker == null) return null;
// 这边可能需要修改一下逻辑不知道原代码部分是否允许1玩家对n无人机 // // 这边可能需要修改一下逻辑不知道原代码部分是否允许1玩家对n无人机
if (hasInstanceOf(player) || hasInstanceOf(stalker)) return null; // if (hasInstanceOf(player) || hasInstanceOf(stalker)) return null;
//
if (player.level().isClientSide) { // if (player.level().isClientSide) {
// TODO 向客户端发送连接的网络包 // // TODO 向客户端发送连接的网络包
} // }
//
player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true); // player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true);
//
INSTANCE_MAP.put(player.getUUID(), stalker.getId()); // INSTANCE_MAP.put(player.getUUID(), stalker.getId());
DRONE_TO_PLAYER.put(stalker.getId(), player.getUUID()); // DRONE_TO_PLAYER.put(stalker.getId(), player.getUUID());
//
DronesTool instance = new DronesTool(player.getUUID(), stalker.getId(), player.level()); // DronesTool instance = new DronesTool(player.getUUID(), stalker.getId(), player.level());
INSTANCE_CACHE.put(player.getUUID(), instance); // INSTANCE_CACHE.put(player.getUUID(), instance);
DRONES_CACHE.put(stalker.getId(), instance); // DRONES_CACHE.put(stalker.getId(), instance);
//
return instance; // return instance;
} // }
//
public static DronesTool getInstanceOf(Entity entity) { // public static DronesTool getInstanceOf(Entity entity) {
if (entity == null) return null; // if (entity == null) return null;
//
UUID uuid = entity.getUUID(); // UUID uuid = entity.getUUID();
int id = entity.getId(); // int id = entity.getId();
//
DronesTool cache = INSTANCE_CACHE.get(uuid); // DronesTool cache = INSTANCE_CACHE.get(uuid);
if (cache != null && !isCacheExpired(cache)) { // if (cache != null && !isCacheExpired(cache)) {
return cache; // return cache;
} // }
//
cache = DRONES_CACHE.get(id); // cache = DRONES_CACHE.get(id);
if (cache != null && !isCacheExpired(cache)) { // if (cache != null && !isCacheExpired(cache)) {
return cache; // return cache;
} // }
//
boolean isPlayer = INSTANCE_MAP.containsKey(uuid); // boolean isPlayer = INSTANCE_MAP.containsKey(uuid);
boolean isDrone = DRONE_TO_PLAYER.containsKey(id); // boolean isDrone = DRONE_TO_PLAYER.containsKey(id);
//
DronesTool instance = null; // DronesTool instance = null;
if (isPlayer) { // if (isPlayer) {
var stalkerId = INSTANCE_MAP.get(uuid); // var stalkerId = INSTANCE_MAP.get(uuid);
if (stalkerId != null) { // if (stalkerId != null) {
instance = new DronesTool(uuid, stalkerId, entity.level()); // instance = new DronesTool(uuid, stalkerId, entity.level());
INSTANCE_CACHE.put(uuid, instance); // INSTANCE_CACHE.put(uuid, instance);
} // }
} else if (isDrone) { // } else if (isDrone) {
UUID playerUUID = DRONE_TO_PLAYER.get(id); // UUID playerUUID = DRONE_TO_PLAYER.get(id);
if (playerUUID != null) { // if (playerUUID != null) {
instance = new DronesTool(playerUUID, id, entity.level()); // instance = new DronesTool(playerUUID, id, entity.level());
DRONES_CACHE.put(id, instance); // DRONES_CACHE.put(id, instance);
} // }
} // }
//
return instance; // return instance;
} // }
//
public void disconnect() { // public void disconnect() {
if (level.isClientSide) { // if (level.isClientSide) {
// TODO 向客户端发送断开连接的网络包 // // TODO 向客户端发送断开连接的网络包
} // }
INSTANCE_MAP.remove(this.playerUUID); // INSTANCE_MAP.remove(this.playerUUID);
DRONE_TO_PLAYER.remove(this.droneId); // DRONE_TO_PLAYER.remove(this.droneId);
INSTANCE_CACHE.remove(this.playerUUID); // INSTANCE_CACHE.remove(this.playerUUID);
DRONES_CACHE.remove(this.droneId); // DRONES_CACHE.remove(this.droneId);
} // }
//
public static boolean hasInstanceOf(Entity entity) { // public static boolean hasInstanceOf(Entity entity) {
if (entity == null) return false; // if (entity == null) return false;
//
UUID uuid = entity.getUUID(); // UUID uuid = entity.getUUID();
if (INSTANCE_CACHE.containsKey(uuid) && !isCacheExpired(INSTANCE_CACHE.get(uuid))) { // if (INSTANCE_CACHE.containsKey(uuid) && !isCacheExpired(INSTANCE_CACHE.get(uuid))) {
return true; // return true;
} // }
//
int id = entity.getId(); // int id = entity.getId();
if (DRONES_CACHE.containsKey(id) && !isCacheExpired(DRONES_CACHE.get(id))) { // if (DRONES_CACHE.containsKey(id) && !isCacheExpired(DRONES_CACHE.get(id))) {
return true; // return true;
} // }
//
return (INSTANCE_MAP.containsKey(uuid) || INSTANCE_MAP.containsValue(id)); // return (INSTANCE_MAP.containsKey(uuid) || INSTANCE_MAP.containsValue(id));
} // }
//
private static boolean isCacheExpired(DronesTool instance) { // private static boolean isCacheExpired(DronesTool instance) {
return System.currentTimeMillis() - instance.lastAccessTime > CACHE_EXPIRE_TIME; // return System.currentTimeMillis() - instance.lastAccessTime > CACHE_EXPIRE_TIME;
} // }
//
public static void cleanupExpiredCache() { // public static void cleanupExpiredCache() {
long currentTime = System.currentTimeMillis(); // long currentTime = System.currentTimeMillis();
INSTANCE_CACHE.entrySet().removeIf(entry -> // INSTANCE_CACHE.entrySet().removeIf(entry ->
currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME); // currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
DRONES_CACHE.entrySet().removeIf(entry -> // DRONES_CACHE.entrySet().removeIf(entry ->
currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME); // currentTime - entry.getValue().lastAccessTime > CACHE_EXPIRE_TIME);
} // }
} }

View file

@ -26,7 +26,6 @@
"AvailablePerks": [ "AvailablePerks": [
"@Ammo", "@Ammo",
"superbwarfare:fourth_times_charm", "superbwarfare:fourth_times_charm",
"superbwarfare:turbo_charger",
"superbwarfare:subsistence", "superbwarfare:subsistence",
"superbwarfare:powerful_attraction", "superbwarfare:powerful_attraction",
"superbwarfare:intelligent_chip", "superbwarfare:intelligent_chip",