Skip to content

Commit

Permalink
✨ Play sound when can not paste. (Close #23)
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Oct 6, 2023
1 parent f3a170d commit f0a7485
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
56 changes: 43 additions & 13 deletions common/src/main/java/cx/rain/mc/nbtedit/gui/NBTEditGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.nbt.CollectionTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
Expand Down Expand Up @@ -304,11 +305,22 @@ private void copySelected() {
}

setFocused(focused);
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

private void paste() {
var focused = getFocused();

if (focused != null) {
var tag = focused.getTag();
if (!(tag instanceof CompoundTag)
&& !(tag instanceof CollectionTag<?>)) {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
return;
}

var node = NBTEdit.getInstance().getClient().getClipboard();
if (node != null) {
focused.setShowChildren(true);
Expand All @@ -328,6 +340,8 @@ private void paste() {
setFocused(node);
update(true);
}
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

Expand Down Expand Up @@ -591,28 +605,44 @@ public boolean onKeyPress(int keyCode, int scanCode, int modifiers) {
}

if (keyCode == GLFW.GLFW_KEY_C && modifiers == GLFW.GLFW_MOD_CONTROL) {
copySelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
if (getFocused() != null) {
copySelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

if (keyCode == GLFW.GLFW_KEY_V && modifiers == GLFW.GLFW_MOD_CONTROL) {
paste();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
if (getFocused() != null) {
paste();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

if (keyCode == GLFW.GLFW_KEY_X && modifiers == GLFW.GLFW_MOD_CONTROL) {
copySelected();
deleteSelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
if (getFocused() != null) {
copySelected();
deleteSelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

if (keyCode == GLFW.GLFW_KEY_D && modifiers == GLFW.GLFW_MOD_CONTROL) {
deleteSelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
if (getFocused() != null) {
deleteSelected();
updateButtons();
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
} else {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.VILLAGER_NO, 1));
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cx.rain.mc.nbtedit.gui.screen;

import com.mojang.blaze3d.vertex.PoseStack;
import cx.rain.mc.nbtedit.NBTEdit;
import cx.rain.mc.nbtedit.gui.NBTEditGui;
import cx.rain.mc.nbtedit.nbt.NBTTree;
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/cx/rain/mc/nbtedit/nbt/NBTTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void setShowChildren(boolean value) {

public static final String TAG_NAME = "name";
public static final String TAG_TYPE = "type";
public static final String TAG_LIST_TYPE = "type";
public static final String TAG_LIST_TYPE = "elementType";
public static final String TAG_VALUE = "value";

public static Node<Tag> fromString(String data) {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

fabric.loom.multiProjectOptimisation=true
enabled_platforms=fabric,forge

archives_base_name=nbtedit
Expand Down

0 comments on commit f0a7485

Please sign in to comment.