优化配件按键
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(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(EditModeMessage.class, EditModeMessage::encode, EditModeMessage::new, EditModeMessage::handler);
|
||||
addNetworkMessage(EditMessage.class, EditMessage::encode, EditMessage::new, EditMessage::handler);
|
||||
addNetworkMessage(EditModeMessage.class, EditModeMessage::encode, EditModeMessage::decode, EditModeMessage::handler);
|
||||
addNetworkMessage(EditMessage.class, EditMessage::encode, EditMessage::decode, EditMessage::handler);
|
||||
|
||||
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())));
|
||||
|
|
|
@ -160,12 +160,29 @@ public class ClickHandler {
|
|||
setKeyState(event);
|
||||
|
||||
int key = event.getKey();
|
||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
||||
if (event.getAction() == GLFW.GLFW_PRESS) {
|
||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue()) {
|
||||
handleDoubleJump(player);
|
||||
}
|
||||
if (key == ModKeyMappings.CONFIG.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setKeyState(InputEvent.Key event) {
|
||||
|
|
|
@ -103,75 +103,11 @@ public class ModKeyMappings {
|
|||
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");
|
||||
|
||||
public static final KeyMapping EDIT_MODE = new KeyMapping("key.superbwarfare.edit_mode", GLFW.GLFW_KEY_H, "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 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;
|
||||
}
|
||||
};
|
||||
public static final KeyMapping EDIT_MODE = new KeyMapping("key.superbwarfare.edit_mode", GLFW.GLFW_KEY_H, "key.categories.superbwarfare");
|
||||
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");
|
||||
public static final KeyMapping EDIT_MAGAZINE = new KeyMapping("key.superbwarfare.edit_magazine", GLFW.GLFW_KEY_DOWN, "key.categories.superbwarfare");
|
||||
public static final KeyMapping EDIT_STOCK = new KeyMapping("key.superbwarfare.edit_stock", GLFW.GLFW_KEY_RIGHT, "key.categories.superbwarfare");
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
|
||||
|
|
|
@ -17,8 +17,8 @@ public class EditMessage {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public EditMessage(FriendlyByteBuf buffer) {
|
||||
this.type = buffer.readInt();
|
||||
public static EditMessage decode(FriendlyByteBuf buffer) {
|
||||
return new EditMessage(buffer.readInt());
|
||||
}
|
||||
|
||||
public static void encode(EditMessage message, FriendlyByteBuf buffer) {
|
||||
|
|
|
@ -16,8 +16,8 @@ public class EditModeMessage {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public EditModeMessage(FriendlyByteBuf buffer) {
|
||||
this.type = buffer.readInt();
|
||||
public static EditModeMessage decode(FriendlyByteBuf buffer) {
|
||||
return new EditModeMessage(buffer.readInt());
|
||||
}
|
||||
|
||||
public static void encode(EditModeMessage message, FriendlyByteBuf buffer) {
|
||||
|
@ -32,15 +32,10 @@ public class EditModeMessage {
|
|||
|
||||
public static void pressAction(Player player, int type) {
|
||||
if (player == null) return;
|
||||
// security measure to prevent arbitrary chunk generation
|
||||
if (!player.level().isLoaded(player.blockPosition()))
|
||||
return;
|
||||
if (type == 0) {
|
||||
EditMode(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EditMode(Player player) {
|
||||
if (!player.level().isLoaded(player.blockPosition())) return;
|
||||
|
||||
if (type == 0) {
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
||||
|
||||
|
@ -52,3 +47,4 @@ public class EditModeMessage {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue