修复右键瞄准bug,修复/effect给自己电击效果可能引起的崩溃
This commit is contained in:
parent
0c25793a61
commit
088358c5e0
1 changed files with 52 additions and 31 deletions
|
@ -58,7 +58,6 @@ public class ClickHandler {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
event.setCanceled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,21 +86,22 @@ public class ClickHandler {
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int button = event.getButton();
|
int button = event.getButton();
|
||||||
|
|
||||||
if (player.getMainHandItem().is(ModTags.Items.GUN)
|
if (player.getMainHandItem().is(ModTags.Items.GUN)
|
||||||
|| stack.is(ModItems.MONITOR.get())
|
|| stack.is(ModItems.MONITOR.get())
|
||||||
|
|| player.hasEffect(ModMobEffects.SHOCK.get())
|
||||||
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity && player.getMainHandItem().getItem() instanceof CannonShellItem)) {
|
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity && player.getMainHandItem().getItem() instanceof CannonShellItem)) {
|
||||||
if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
||||||
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity)) {
|
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity)) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
|
@ -114,6 +114,7 @@ public class ClickHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player.getMainHandItem().is(ModTags.Items.GUN)) {
|
||||||
if (button == ModKeyMappings.FIRE.getKey().getValue()) {
|
if (button == ModKeyMappings.FIRE.getKey().getValue()) {
|
||||||
handleWeaponFirePress(player, stack);
|
handleWeaponFirePress(player, stack);
|
||||||
}
|
}
|
||||||
|
@ -129,6 +130,7 @@ public class ClickHandler {
|
||||||
switchZoom = !switchZoom;
|
switchZoom = !switchZoom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onMouseScrolling(InputEvent.MouseScrollingEvent event) {
|
public static void onMouseScrolling(InputEvent.MouseScrollingEvent event) {
|
||||||
|
@ -140,7 +142,6 @@ public class ClickHandler {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
event.setCanceled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,15 +181,15 @@ public class ClickHandler {
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setKeyState(event);
|
setKeyState(event);
|
||||||
|
|
||||||
int key = event.getKey();
|
int key = event.getKey();
|
||||||
if (event.getAction() == GLFW.GLFW_PRESS) {
|
if (event.getAction() == GLFW.GLFW_PRESS) {
|
||||||
|
|
||||||
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue()) {
|
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue()) {
|
||||||
handleDoubleJump(player);
|
handleDoubleJump(player);
|
||||||
}
|
}
|
||||||
|
@ -231,28 +232,48 @@ public class ClickHandler {
|
||||||
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(false));
|
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player.getMainHandItem().is(ModTags.Items.GUN)) {
|
||||||
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
||||||
handleWeaponFirePress(player, stack);
|
handleWeaponFirePress(player, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
||||||
handleWeaponZoomPress();
|
handleWeaponZoomPress();
|
||||||
}
|
switchZoom = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) {
|
||||||
|
handleWeaponZoomPress();
|
||||||
|
switchZoom = !switchZoom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() == GLFW.GLFW_RELEASE) {
|
|
||||||
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
||||||
handleWeaponFireRelease();
|
handleWeaponFireRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
||||||
handleWeaponZoomRelease();
|
handleWeaponZoomRelease();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue() && !switchZoom) {
|
||||||
|
handleWeaponZoomRelease();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleWeaponFirePress (Player player, ItemStack stack) {
|
public static void handleWeaponFirePress (Player player, ItemStack stack) {
|
||||||
|
|
||||||
|
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get())) {
|
if (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get())) {
|
||||||
ModUtils.PACKET_HANDLER.sendToServer(new SetFiringParametersMessage(0));
|
ModUtils.PACKET_HANDLER.sendToServer(new SetFiringParametersMessage(0));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue