优化配件按键
This commit is contained in:
parent
72cab16f45
commit
8446dc0365
5 changed files with 42 additions and 93 deletions
|
@ -125,8 +125,8 @@ public class ModUtils {
|
||||||
addNetworkMessage(ShootMessage.class, ShootMessage::encode, ShootMessage::decode, ShootMessage::handler);
|
addNetworkMessage(ShootMessage.class, ShootMessage::encode, ShootMessage::decode, ShootMessage::handler);
|
||||||
addNetworkMessage(ShootClientMessage.class, ShootClientMessage::encode, ShootClientMessage::decode, ShootClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(ShootClientMessage.class, ShootClientMessage::encode, ShootClientMessage::decode, ShootClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
addNetworkMessage(DrawClientMessage.class, DrawClientMessage::encode, DrawClientMessage::decode, DrawClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(DrawClientMessage.class, DrawClientMessage::encode, DrawClientMessage::decode, DrawClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
addNetworkMessage(EditModeMessage.class, EditModeMessage::encode, EditModeMessage::new, EditModeMessage::handler);
|
addNetworkMessage(EditModeMessage.class, EditModeMessage::encode, EditModeMessage::decode, EditModeMessage::handler);
|
||||||
addNetworkMessage(EditMessage.class, EditMessage::encode, EditMessage::new, EditMessage::handler);
|
addNetworkMessage(EditMessage.class, EditMessage::encode, EditMessage::decode, EditMessage::handler);
|
||||||
|
|
||||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
||||||
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
||||||
|
|
|
@ -160,11 +160,28 @@ public class ClickHandler {
|
||||||
setKeyState(event);
|
setKeyState(event);
|
||||||
|
|
||||||
int key = event.getKey();
|
int key = event.getKey();
|
||||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
if (event.getAction() == GLFW.GLFW_PRESS) {
|
||||||
handleDoubleJump(player);
|
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue()) {
|
||||||
}
|
handleDoubleJump(player);
|
||||||
if (key == ModKeyMappings.CONFIG.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
}
|
||||||
handleConfigScreen(player);
|
if (key == ModKeyMappings.CONFIG.getKey().getValue()) {
|
||||||
|
handleConfigScreen(player);
|
||||||
|
}
|
||||||
|
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue()) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new EditModeMessage(0));
|
||||||
|
}
|
||||||
|
if (key == ModKeyMappings.EDIT_SCOPE.getKey().getValue()) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new EditMessage(0));
|
||||||
|
}
|
||||||
|
if (key == ModKeyMappings.EDIT_BARREL.getKey().getValue()) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new EditMessage(1));
|
||||||
|
}
|
||||||
|
if (key == ModKeyMappings.EDIT_MAGAZINE.getKey().getValue()) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new EditMessage(2));
|
||||||
|
}
|
||||||
|
if (key == ModKeyMappings.EDIT_STOCK.getKey().getValue()) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new EditMessage(3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,75 +103,11 @@ public class ModKeyMappings {
|
||||||
public static final KeyMapping CONFIG = new KeyMapping("key.superbwarfare.config", KeyConflictContext.IN_GAME,
|
public static final KeyMapping CONFIG = new KeyMapping("key.superbwarfare.config", KeyConflictContext.IN_GAME,
|
||||||
KeyModifier.ALT, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "key.categories.superbwarfare");
|
KeyModifier.ALT, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "key.categories.superbwarfare");
|
||||||
|
|
||||||
public static final KeyMapping EDIT_MODE = new KeyMapping("key.superbwarfare.edit_mode", GLFW.GLFW_KEY_H, "key.categories.superbwarfare") {
|
public static final KeyMapping EDIT_MODE = new KeyMapping("key.superbwarfare.edit_mode", GLFW.GLFW_KEY_H, "key.categories.superbwarfare");
|
||||||
private boolean isDownOld = false;
|
public static final KeyMapping EDIT_SCOPE = new KeyMapping("key.superbwarfare.edit_scope", GLFW.GLFW_KEY_UP, "key.categories.superbwarfare");
|
||||||
|
public static final KeyMapping EDIT_BARREL = new KeyMapping("key.superbwarfare.edit_barrel", GLFW.GLFW_KEY_LEFT, "key.categories.superbwarfare");
|
||||||
@Override
|
public static final KeyMapping EDIT_MAGAZINE = new KeyMapping("key.superbwarfare.edit_magazine", GLFW.GLFW_KEY_DOWN, "key.categories.superbwarfare");
|
||||||
public void setDown(boolean isDown) {
|
public static final KeyMapping EDIT_STOCK = new KeyMapping("key.superbwarfare.edit_stock", GLFW.GLFW_KEY_RIGHT, "key.categories.superbwarfare");
|
||||||
super.setDown(isDown);
|
|
||||||
if (isDownOld != isDown && isDown) {
|
|
||||||
ModUtils.PACKET_HANDLER.sendToServer(new EditModeMessage(0));
|
|
||||||
EditModeMessage.pressAction(Minecraft.getInstance().player, 0);
|
|
||||||
}
|
|
||||||
isDownOld = isDown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final KeyMapping EDIT_SCOPE = new KeyMapping("key.superbwarfare.edit_scope", GLFW.GLFW_KEY_UP, "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 EditMessage(0));
|
|
||||||
EditMessage.pressAction(Minecraft.getInstance().player, 0);
|
|
||||||
}
|
|
||||||
isDownOld = isDown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final KeyMapping EDIT_BARREL = new KeyMapping("key.superbwarfare.edit_barrel", GLFW.GLFW_KEY_LEFT, "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 EditMessage(1));
|
|
||||||
EditMessage.pressAction(Minecraft.getInstance().player, 1);
|
|
||||||
}
|
|
||||||
isDownOld = isDown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final KeyMapping EDIT_MAGAZINE = new KeyMapping("key.superbwarfare.edit_magazine", GLFW.GLFW_KEY_DOWN, "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 EditMessage(2));
|
|
||||||
EditMessage.pressAction(Minecraft.getInstance().player, 2);
|
|
||||||
}
|
|
||||||
isDownOld = isDown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final KeyMapping EDIT_STOCK = new KeyMapping("key.superbwarfare.edit_stock", GLFW.GLFW_KEY_RIGHT, "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 EditMessage(3));
|
|
||||||
EditMessage.pressAction(Minecraft.getInstance().player, 3);
|
|
||||||
}
|
|
||||||
isDownOld = isDown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
|
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
|
||||||
|
|
|
@ -17,8 +17,8 @@ public class EditMessage {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditMessage(FriendlyByteBuf buffer) {
|
public static EditMessage decode(FriendlyByteBuf buffer) {
|
||||||
this.type = buffer.readInt();
|
return new EditMessage(buffer.readInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(EditMessage message, FriendlyByteBuf buffer) {
|
public static void encode(EditMessage message, FriendlyByteBuf buffer) {
|
||||||
|
|
|
@ -16,8 +16,8 @@ public class EditModeMessage {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditModeMessage(FriendlyByteBuf buffer) {
|
public static EditModeMessage decode(FriendlyByteBuf buffer) {
|
||||||
this.type = buffer.readInt();
|
return new EditModeMessage(buffer.readInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(EditModeMessage message, FriendlyByteBuf buffer) {
|
public static void encode(EditModeMessage message, FriendlyByteBuf buffer) {
|
||||||
|
@ -32,23 +32,19 @@ public class EditModeMessage {
|
||||||
|
|
||||||
public static void pressAction(Player player, int type) {
|
public static void pressAction(Player player, int type) {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
// security measure to prevent arbitrary chunk generation
|
|
||||||
if (!player.level().isLoaded(player.blockPosition()))
|
if (!player.level().isLoaded(player.blockPosition())) return;
|
||||||
return;
|
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
EditMode(player);
|
ItemStack mainHandItem = player.getMainHandItem();
|
||||||
}
|
var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
||||||
}
|
|
||||||
|
|
||||||
public static void EditMode(Player player) {
|
if (mainHandItem.is(ModTags.Items.CAN_CUSTOM_GUN)) {
|
||||||
ItemStack mainHandItem = player.getMainHandItem();
|
cap.ifPresent(capability -> {
|
||||||
var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
capability.edit = !cap.orElse(new ModVariables.PlayerVariables()).edit;
|
||||||
|
|
||||||
if (mainHandItem.is(ModTags.Items.CAN_CUSTOM_GUN)) {
|
|
||||||
cap.ifPresent(capability -> {
|
|
||||||
capability.edit = !cap.orElse(new ModVariables.PlayerVariables()).edit;
|
|
||||||
capability.syncPlayerVariables(player);
|
capability.syncPlayerVariables(player);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue