禁用载具数字键切换物品
This commit is contained in:
parent
0ff0e619df
commit
4dab918583
3 changed files with 56 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.mixins;
|
package com.atsuishio.superbwarfare.mixins;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModMobEffects;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.Input;
|
import net.minecraft.client.player.Input;
|
||||||
import net.minecraft.client.player.KeyboardInput;
|
import net.minecraft.client.player.KeyboardInput;
|
||||||
|
@ -10,10 +11,9 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import com.atsuishio.superbwarfare.init.ModMobEffects;
|
|
||||||
|
|
||||||
@Mixin(KeyboardInput.class)
|
@Mixin(KeyboardInput.class)
|
||||||
public abstract class KeyMappingMixin extends Input {
|
public abstract class KeyboardInputMixin extends Input {
|
||||||
|
|
||||||
// 按键修改mixin
|
// 按键修改mixin
|
||||||
@Inject(method = "tick", at = @At("RETURN"))
|
@Inject(method = "tick", at = @At("RETURN"))
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.atsuishio.superbwarfare.mixins;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(KeyMapping.class)
|
||||||
|
public class KeymappingMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private InputConstants.Key key;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private int clickCount;
|
||||||
|
|
||||||
|
@Inject(method = "consumeClick()Z", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void consumeClick(CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
Player player = Minecraft.getInstance().player;
|
||||||
|
if (player == null || !(player.getVehicle() instanceof VehicleEntity vehicle)) return;
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
if (Minecraft.getInstance().options.keyHotbarSlots[i].getKey() == key) {
|
||||||
|
if (vehicle.getMaxPassengers() > 1
|
||||||
|
&& Screen.hasShiftDown()
|
||||||
|
&& i < vehicle.getMaxPassengers()
|
||||||
|
&& vehicle.getNthEntity(i) == null
|
||||||
|
) {
|
||||||
|
if (this.clickCount > 0) {
|
||||||
|
--this.clickCount;
|
||||||
|
}
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vehicle instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.banHand(player)) {
|
||||||
|
if (this.clickCount > 0) {
|
||||||
|
--this.clickCount;
|
||||||
|
}
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,8 @@
|
||||||
"ClientPlayerEntityMixin",
|
"ClientPlayerEntityMixin",
|
||||||
"GameRendererMixin",
|
"GameRendererMixin",
|
||||||
"ItemInHandLayerMixin",
|
"ItemInHandLayerMixin",
|
||||||
"KeyMappingMixin",
|
"KeyboardInputMixin",
|
||||||
|
"KeymappingMixin",
|
||||||
"LivingEntityRendererMixin",
|
"LivingEntityRendererMixin",
|
||||||
"MinecraftMixin",
|
"MinecraftMixin",
|
||||||
"MouseHandlerMixin"
|
"MouseHandlerMixin"
|
||||||
|
|
Loading…
Add table
Reference in a new issue