去除战术冲刺的按键绑定和网络包

This commit is contained in:
Atsuihsio 2024-08-01 21:43:18 +08:00
parent 106bed9aff
commit 5171d31245
6 changed files with 12 additions and 77 deletions

View file

@ -108,7 +108,6 @@ public class ModUtils {
addNetworkMessage(DroneMovementMessage.class, DroneMovementMessage::encode, DroneMovementMessage::decode, DroneMovementMessage::handler); addNetworkMessage(DroneMovementMessage.class, DroneMovementMessage::encode, DroneMovementMessage::decode, DroneMovementMessage::handler);
addNetworkMessage(DroneFireMessage.class, DroneFireMessage::buffer, DroneFireMessage::new, DroneFireMessage::handler); addNetworkMessage(DroneFireMessage.class, DroneFireMessage::buffer, DroneFireMessage::new, DroneFireMessage::handler);
addNetworkMessage(SimulationDistanceMessage.class, SimulationDistanceMessage::encode, SimulationDistanceMessage::decode, SimulationDistanceMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); addNetworkMessage(SimulationDistanceMessage.class, SimulationDistanceMessage::encode, SimulationDistanceMessage::decode, SimulationDistanceMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
addNetworkMessage(TacticalSprintMessage.class, TacticalSprintMessage::encode, TacticalSprintMessage::decode, TacticalSprintMessage::handler);
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)), event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get()))); Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));

View file

@ -125,6 +125,17 @@ public class PlayerEventHandler {
capability.tacticalSprint = false; capability.tacticalSprint = false;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });
player.getPersistentData().putBoolean("canTacticalSprint", true);
}
if (player.isSprinting()
&& !(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).tacticalSprintExhaustion
&& player.getPersistentData().getBoolean("canTacticalSprint")) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.tacticalSprint = true;
capability.syncPlayerVariables(player);
});
player.getPersistentData().putBoolean("canTacticalSprint", false);
} }
if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).tacticalSprint) { if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).tacticalSprint) {
@ -132,7 +143,7 @@ public class PlayerEventHandler {
capability.tacticalSprintTime = Mth.clamp(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).tacticalSprintTime - sprint_cost,0,600); capability.tacticalSprintTime = Mth.clamp(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).tacticalSprintTime - sprint_cost,0,600);
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 2, 1, false, false)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 2, 0, false, false));
} else { } else {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {

View file

@ -194,31 +194,13 @@ public class ModKeyMappings {
isDownOld = isDown; isDownOld = isDown;
} }
}; };
public static final KeyMapping TACTICAL_SPRINT = new KeyMapping("key.superbwarfare.tactical_sprint", GLFW.GLFW_KEY_LEFT_CONTROL, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@Override
public void setDown(boolean isDown) {
super.setDown(isDown);
if (isDownOld != isDown && isDown) {
ModUtils.PACKET_HANDLER.sendToServer(new TacticalSprintMessage(true));
TACTICAL_SPRINT_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - TACTICAL_SPRINT_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new TacticalSprintMessage(false));
}
isDownOld = isDown;
}
};
private static long FORWARD_LASTPRESS = 0; private static long FORWARD_LASTPRESS = 0;
private static long BACKWARD_LASTPRESS = 0; private static long BACKWARD_LASTPRESS = 0;
private static long LEFT_LASTPRESS = 0; private static long LEFT_LASTPRESS = 0;
private static long RIGHT_LASTPRESS = 0; private static long RIGHT_LASTPRESS = 0;
private static long UP_LASTPRESS = 0; private static long UP_LASTPRESS = 0;
private static long DOWN_LASTPRESS = 0; private static long DOWN_LASTPRESS = 0;
private static long TACTICAL_SPRINT_LASTPRESS = 0;
@SubscribeEvent @SubscribeEvent
public static void registerKeyMappings(RegisterKeyMappingsEvent event) { public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
@ -234,8 +216,6 @@ public class ModKeyMappings {
event.register(RIGHT); event.register(RIGHT);
event.register(UP); event.register(UP);
event.register(DOWN); event.register(DOWN);
event.register(TACTICAL_SPRINT);
} }
@Mod.EventBusSubscriber({Dist.CLIENT}) @Mod.EventBusSubscriber({Dist.CLIENT})
@ -255,7 +235,6 @@ public class ModKeyMappings {
RIGHT.consumeClick(); RIGHT.consumeClick();
UP.consumeClick(); UP.consumeClick();
DOWN.consumeClick(); DOWN.consumeClick();
TACTICAL_SPRINT.consumeClick();
} }
} }
} }

View file

@ -1,52 +0,0 @@
package net.mcreator.superbwarfare.network.message;
import net.mcreator.superbwarfare.entity.DroneEntity;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;
import software.bernie.geckolib.animatable.GeoItem;
import java.util.function.Supplier;
public class TacticalSprintMessage {
private final boolean sprint;
public TacticalSprintMessage(boolean sprint) {
this.sprint = sprint;
}
public static TacticalSprintMessage decode(FriendlyByteBuf buffer) {
return new TacticalSprintMessage(buffer.readBoolean());
}
public static void encode(TacticalSprintMessage message, FriendlyByteBuf buffer) {
buffer.writeBoolean(message.sprint);
}
public static void handler(TacticalSprintMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
if (context.getSender() != null) {
Player player = context.getSender();
if (message.sprint) {
player.setSprinting(true);
if (!(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).tacticalSprintExhaustion) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.tacticalSprint = true;
capability.syncPlayerVariables(player);
});
}
}
}
});
context.setPacketHandled(true);
}
}

View file

@ -220,7 +220,6 @@
"key.superbwarfare.right": "Right", "key.superbwarfare.right": "Right",
"key.superbwarfare.up": "Up", "key.superbwarfare.up": "Up",
"key.superbwarfare.down": "Down", "key.superbwarfare.down": "Down",
"key.superbwarfare.tactical_sprint": "Tactical Sprint",
"effect.superbwarfare.shock": "Shock", "effect.superbwarfare.shock": "Shock",
"item.minecraft.potion.effect.superbwarfare_shock": "Potion of Shock", "item.minecraft.potion.effect.superbwarfare_shock": "Potion of Shock",

View file

@ -220,7 +220,6 @@
"key.superbwarfare.right": "向右移动", "key.superbwarfare.right": "向右移动",
"key.superbwarfare.up": "上升", "key.superbwarfare.up": "上升",
"key.superbwarfare.down": "下降", "key.superbwarfare.down": "下降",
"key.superbwarfare.tactical_sprint": "战术冲刺",
"effect.superbwarfare.shock": "电击", "effect.superbwarfare.shock": "电击",
"item.minecraft.potion.effect.superbwarfare_shock": "电击药水", "item.minecraft.potion.effect.superbwarfare_shock": "电击药水",