重构载具换座位功能,禁用快捷栏切换
This commit is contained in:
parent
f1d6e9e1d3
commit
ea64a53586
3 changed files with 50 additions and 19 deletions
|
@ -17,7 +17,6 @@ import com.atsuishio.superbwarfare.tools.SeekTool;
|
|||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -278,24 +277,6 @@ public class ClickHandler {
|
|||
switchZoom = !switchZoom;
|
||||
}
|
||||
}
|
||||
|
||||
// 未按住shift且在可切换座位的载具上时,发送切换座位消息
|
||||
if (!Screen.hasShiftDown() && player.getVehicle() instanceof VehicleEntity vehicle) {
|
||||
int index = -1;
|
||||
for (int slot = 0; slot < Minecraft.getInstance().options.keyHotbarSlots.length; ++slot) {
|
||||
KeyMapping keyHotbarSlot = Minecraft.getInstance().options.keyHotbarSlots[slot];
|
||||
if (key == keyHotbarSlot.getKey().getValue()) {
|
||||
index = slot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1 && index < vehicle.getMaxPassengers() && vehicle.getNthEntity(index) == null) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new ChangeVehicleSeatMessage(index));
|
||||
vehicle.changeSeat(player, index);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (player.hasEffect(ModMobEffects.SHOCK.get())) {
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.atsuishio.superbwarfare.mixins;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.network.message.ChangeVehicleSeatMessage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public LocalPlayer player;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public Options options;
|
||||
|
||||
/**
|
||||
* 未按住shift且在可切换座位的载具上时,禁用快捷栏切换,发送切换座位消息
|
||||
*/
|
||||
@Inject(method = "handleKeybinds()V", at = @At("HEAD"), cancellable = true)
|
||||
private void handleKeybinds(CallbackInfo ci) {
|
||||
if (player != null && player.getVehicle() instanceof VehicleEntity vehicle && vehicle.getMaxPassengers() > 1
|
||||
&& !Screen.hasShiftDown()) {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (options.keyHotbarSlots[i].consumeClick()) {
|
||||
ci.cancel();
|
||||
|
||||
if (i < vehicle.getMaxPassengers() && vehicle.getNthEntity(i) == null) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new ChangeVehicleSeatMessage(i));
|
||||
vehicle.changeSeat(player, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@
|
|||
"ItemInHandLayerMixin",
|
||||
"KeyMappingMixin",
|
||||
"LivingEntityRendererMixin",
|
||||
"MinecraftMixin",
|
||||
"MouseHandlerMixin"
|
||||
],
|
||||
"minVersion": "0.8",
|
||||
|
|
Loading…
Add table
Reference in a new issue