优化交互按键处理逻辑
This commit is contained in:
parent
cdebcd298a
commit
b3c4f0bce2
4 changed files with 33 additions and 50 deletions
|
@ -212,6 +212,9 @@ public class ClickHandler {
|
|||
if (key == ModKeyMappings.FIRE_MODE.getKey().getValue()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new FireModeMessage(0));
|
||||
}
|
||||
if (key == ModKeyMappings.INTERACT.getKey().getValue()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new InteractMessage(0));
|
||||
}
|
||||
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue() && ClientEventHandler.burstFireSize == 0) {
|
||||
ClientEventHandler.holdFire = false;
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new EditModeMessage(0));
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.init;
|
|||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.network.message.BreathMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.InteractMessage;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -22,22 +21,7 @@ public class ModKeyMappings {
|
|||
public static final KeyMapping FIRE_MODE = new KeyMapping("key.superbwarfare.fire_mode", GLFW.GLFW_KEY_N, "key.categories.superbwarfare");
|
||||
public static final KeyMapping SENSITIVITY_INCREASE = new KeyMapping("key.superbwarfare.sensitivity_increase", GLFW.GLFW_KEY_PAGE_UP, "key.categories.superbwarfare");
|
||||
public static final KeyMapping SENSITIVITY_REDUCE = new KeyMapping("key.superbwarfare.sensitivity_reduce", GLFW.GLFW_KEY_PAGE_DOWN, "key.categories.superbwarfare");
|
||||
|
||||
public static final KeyMapping INTERACT = new KeyMapping("key.superbwarfare.interact", GLFW.GLFW_KEY_X, "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 InteractMessage(0));
|
||||
if (Minecraft.getInstance().player != null) {
|
||||
InteractMessage.pressAction(Minecraft.getInstance().player, 0);
|
||||
}
|
||||
}
|
||||
isDownOld = isDown;
|
||||
}
|
||||
};
|
||||
public static final KeyMapping INTERACT = new KeyMapping("key.superbwarfare.interact", GLFW.GLFW_KEY_X, "key.categories.superbwarfare");
|
||||
|
||||
public static final KeyMapping BREATH = new KeyMapping("key.superbwarfare.breath", GLFW.GLFW_KEY_LEFT_CONTROL, "key.categories.superbwarfare") {
|
||||
private boolean isDownOld = false;
|
||||
|
|
|
@ -37,9 +37,7 @@ public class FireModeMessage {
|
|||
context.enqueueWork(() -> {
|
||||
if (context.getSender() == null) return;
|
||||
|
||||
if (message.type == 0) {
|
||||
changeFireMode(context.getSender());
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
|
|
@ -41,22 +41,21 @@ public class InteractMessage {
|
|||
NetworkEvent.Context context = contextSupplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
if (context.getSender() != null) {
|
||||
pressAction(context.getSender(), message.type);
|
||||
handleInteract(context.getSender(), message.type);
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
||||
public static void pressAction(Player player, int type) {
|
||||
public static void handleInteract(Player player, int type) {
|
||||
Level level = player.level();
|
||||
|
||||
if (type == 0) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (player.getMainHandItem().is(ModTags.Items.GUN)) {
|
||||
double block_range = player.getBlockReach();
|
||||
double entity_range = player.getBlockReach();
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
double blockRange = player.getBlockReach();
|
||||
double entityRange = player.getBlockReach();
|
||||
|
||||
Vec3 looking = Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(block_range)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos());
|
||||
Vec3 looking = Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(blockRange)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos());
|
||||
BlockPos blockPos = BlockPos.containing(looking.x(), looking.y(), looking.z());
|
||||
level.getBlockState(blockPos).use(player.level(), player, InteractionHand.MAIN_HAND, BlockHitResult.miss(new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()), Direction.UP, blockPos));
|
||||
|
||||
|
@ -64,9 +63,9 @@ public class InteractMessage {
|
|||
bell.attemptToRing(level, blockPos, player.getDirection().getOpposite());
|
||||
}
|
||||
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, entity_range);
|
||||
if (lookingEntity == null)
|
||||
return;
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, entityRange);
|
||||
if (lookingEntity == null) return;
|
||||
|
||||
player.interactOn(lookingEntity, InteractionHand.MAIN_HAND);
|
||||
} else if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked") && !player.getCooldowns().isOnCooldown(stack.getItem())) {
|
||||
DroneEntity drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone"));
|
||||
|
@ -77,12 +76,11 @@ public class InteractMessage {
|
|||
player.level().getBlockState(blockPos).use(player.level(), player, InteractionHand.MAIN_HAND, BlockHitResult.miss(new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()), Direction.UP, blockPos));
|
||||
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(drone, 2);
|
||||
if (lookingEntity == null)
|
||||
return;
|
||||
if (lookingEntity == null) return;
|
||||
|
||||
player.attack(lookingEntity);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 13);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue