注册无人机操控的键位

This commit is contained in:
Atsuihsio 2024-07-28 00:51:53 +08:00
parent 09bb7bb287
commit f4fee211e9
6 changed files with 140 additions and 50 deletions

View file

@ -160,25 +160,7 @@ public class ClickHandler {
setKeyState(event.getKey(), clicked ? 1 : 0); setKeyState(event.getKey(), clicked ? 1 : 0);
int button = event.getKey();
if (button == GLFW.GLFW_KEY_A) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(0, clicked));
}
if (button == GLFW.GLFW_KEY_D) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(1, clicked));
}
if (button == GLFW.GLFW_KEY_W) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(2, clicked));
}
if (button == GLFW.GLFW_KEY_S) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(3, clicked));
}
if (button == GLFW.GLFW_KEY_SPACE) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(4, clicked));
}
if (button == GLFW.GLFW_KEY_LEFT_SHIFT) {
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(5, clicked));
}
} }
} }

View file

@ -244,7 +244,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
droneDrop(player); droneDrop(player);
} }
if (this.entityData.get(KAMIKAZE)) { if (this.entityData.get(KAMIKAZE)) {
kamikazeExplosion(player); this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION),player), 10000);
} }
} }
this.getPersistentData().putBoolean("firing", false); this.getPersistentData().putBoolean("firing", false);
@ -263,17 +263,6 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
} }
} }
private void kamikazeExplosion(Player player) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), player, player), 150,
this.getX(), this.getY(), this.getZ(), 12.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION)), 10000);
}
@Override @Override
public InteractionResult mobInteract(Player player, InteractionHand hand) { public InteractionResult mobInteract(Player player, InteractionHand hand) {
super.mobInteract(player, hand); super.mobInteract(player, hand);
@ -401,13 +390,11 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
Monitor.disLink(stack); Monitor.disLink(stack);
} }
}); });
if (this.entityData.get(KAMIKAZE)){
destroyExplosion(player);
} }
} else {
if (this.entityData.get(KAMIKAZE)){ if (this.entityData.get(KAMIKAZE)){
destroyExplosion2(); kamikazeExplosion(source.getEntity());
}
} }
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
@ -417,25 +404,16 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
} }
private void destroyExplosion(Player player) { private void kamikazeExplosion(Entity source) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), player, player), 40, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), source, source), 150,
this.getX(), this.getY(), this.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 12.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
} }
private void destroyExplosion2() {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this), 40,
this.getX(), this.getY(), this.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
@Override @Override
public EntityDimensions getDimensions(Pose p_33597_) { public EntityDimensions getDimensions(Pose p_33597_) {

View file

@ -98,6 +98,111 @@ public class ModKeyMappings {
} }
}; };
public static final KeyMapping FORWARD = new KeyMapping("key.superbwarfare.forward", GLFW.GLFW_KEY_W, "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 DroneMovementMessage(2, true));
FORWARD_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - FORWARD_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(2, false));
}
isDownOld = isDown;
}
};
public static final KeyMapping BACKWARD = new KeyMapping("key.superbwarfare.backward", GLFW.GLFW_KEY_S, "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 DroneMovementMessage(3, true));
BACKWARD_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - BACKWARD_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(3, false));
}
isDownOld = isDown;
}
};
public static final KeyMapping LEFT = new KeyMapping("key.superbwarfare.left", GLFW.GLFW_KEY_A, "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 DroneMovementMessage(0, true));
LEFT_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - LEFT_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(0, false));
}
isDownOld = isDown;
}
};
public static final KeyMapping RIGHT = new KeyMapping("key.superbwarfare.right", GLFW.GLFW_KEY_D, "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 DroneMovementMessage(1, true));
RIGHT_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - RIGHT_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(1, false));
}
isDownOld = isDown;
}
};
public static final KeyMapping UP = new KeyMapping("key.superbwarfare.up", GLFW.GLFW_KEY_SPACE, "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 DroneMovementMessage(4, true));
UP_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - UP_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(4, false));
}
isDownOld = isDown;
}
};
public static final KeyMapping DOWN = new KeyMapping("key.superbwarfare.down", GLFW.GLFW_KEY_LEFT_SHIFT, "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 DroneMovementMessage(5, true));
DOWN_LASTPRESS = System.currentTimeMillis();
} else if (isDownOld != isDown) {
int dt = (int) (System.currentTimeMillis() - DOWN_LASTPRESS);
ModUtils.PACKET_HANDLER.sendToServer(new DroneMovementMessage(5, false));
}
isDownOld = isDown;
}
};
private static long FORWARD_LASTPRESS = 0;
private static long BACKWARD_LASTPRESS = 0;
private static long LEFT_LASTPRESS = 0;
private static long RIGHT_LASTPRESS = 0;
private static long UP_LASTPRESS = 0;
private static long DOWN_LASTPRESS = 0;
@SubscribeEvent @SubscribeEvent
public static void registerKeyMappings(RegisterKeyMappingsEvent event) { public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
event.register(RELOAD); event.register(RELOAD);
@ -106,6 +211,13 @@ public class ModKeyMappings {
event.register(SENSITIVITY_INCREASE); event.register(SENSITIVITY_INCREASE);
event.register(SENSITIVITY_REDUCE); event.register(SENSITIVITY_REDUCE);
event.register(INTERACT); event.register(INTERACT);
event.register(FORWARD);
event.register(BACKWARD);
event.register(LEFT);
event.register(RIGHT);
event.register(UP);
event.register(DOWN);
} }
@Mod.EventBusSubscriber({Dist.CLIENT}) @Mod.EventBusSubscriber({Dist.CLIENT})
@ -119,6 +231,12 @@ public class ModKeyMappings {
SENSITIVITY_INCREASE.consumeClick(); SENSITIVITY_INCREASE.consumeClick();
SENSITIVITY_REDUCE.consumeClick(); SENSITIVITY_REDUCE.consumeClick();
INTERACT.consumeClick(); INTERACT.consumeClick();
FORWARD.consumeClick();
BACKWARD.consumeClick();
LEFT.consumeClick();
RIGHT.consumeClick();
UP.consumeClick();
DOWN.consumeClick();
} }
} }
} }

View file

@ -208,6 +208,12 @@
"key.superbwarfare.sensitivity_increase": "Increase Sensitivity", "key.superbwarfare.sensitivity_increase": "Increase Sensitivity",
"key.superbwarfare.sensitivity_reduce": "Reduce Sensitivity", "key.superbwarfare.sensitivity_reduce": "Reduce Sensitivity",
"key.superbwarfare.interact": "Interact", "key.superbwarfare.interact": "Interact",
"key.superbwarfare.forward": "Forward",
"key.superbwarfare.backward": "Backward",
"key.superbwarfare.left": "Left",
"key.superbwarfare.right": "Right",
"key.superbwarfare.up": "Up",
"key.superbwarfare.down": "Down",
"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

@ -208,6 +208,12 @@
"key.superbwarfare.sensitivity_increase": "增加灵敏度", "key.superbwarfare.sensitivity_increase": "增加灵敏度",
"key.superbwarfare.sensitivity_reduce": "减少灵敏度", "key.superbwarfare.sensitivity_reduce": "减少灵敏度",
"key.superbwarfare.interact": "交互", "key.superbwarfare.interact": "交互",
"key.superbwarfare.forward": "向前移动",
"key.superbwarfare.backward": "向后移动",
"key.superbwarfare.left": "向左移动",
"key.superbwarfare.right": "向右移动",
"key.superbwarfare.up": "上升",
"key.superbwarfare.down": "下降",
"effect.superbwarfare.shock": "电击", "effect.superbwarfare.shock": "电击",
"item.minecraft.potion.effect.superbwarfare_shock": "电击药水", "item.minecraft.potion.effect.superbwarfare_shock": "电击药水",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 430 B

After

Width:  |  Height:  |  Size: 516 B