Skip to content

Commit a6bd7cf

Browse files
authored
Merge pull request #20 from oasoobi/dev
added new features
2 parents 9307358 + fc03651 commit a6bd7cf

29 files changed

+123
-28
lines changed

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"header": {
4-
"name": "Note Block+ v2.0.7",
4+
"name": "Note Block+ v2.0.8",
55
"description": "音ブロックの音階を表示するアドオン。 \nTwitter(X) :@oasoby",
66
"min_engine_version": [
77
1,
@@ -12,7 +12,7 @@
1212
"version": [
1313
2,
1414
0,
15-
7
15+
8
1616
]
1717
},
1818
"modules": [
Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const Instruments = {
3434
"composter": "bass",
3535
"bee_nest": "bass",
3636
"beehive": "bass",
37+
"smoker": "bass_drum",
3738
"amethyst_block": "bass_drum", //アメジスト系
3839
"soul_sand": "cow_bell",
3940
"glass": "clicks_and_sticks", //ガラス系
@@ -161,7 +162,7 @@ export const Scales = {
161162
"Sol#",
162163
"La",
163164
"La#",
164-
"Si",
165+
"Si(Ti)",
165166
"Do",
166167
"Do#",
167168
"Re",
@@ -173,7 +174,7 @@ export const Scales = {
173174
"Sol#",
174175
"La",
175176
"La#",
176-
"Si",
177+
"Si(Ti)",
177178
"Do",
178179
"Do#",
179180
"Re",
@@ -212,4 +213,52 @@ export const Scales = {
212213
}
213214
}
214215

215-
export const VERSION = "2.0.7";
216+
export const NoteBlockPitches = [
217+
0.500, // F#3
218+
0.530, // G3
219+
0.561, // G#3
220+
0.595, // A3
221+
0.630, // A#3
222+
0.667, // B3
223+
0.707, // C4
224+
0.749, // C#4
225+
0.794, // D4
226+
0.841, // D#4
227+
0.891, // E4
228+
0.944, // F4
229+
1.000, // F#4
230+
1.059, // G4
231+
1.122, // G#4
232+
1.189, // A4
233+
1.260, // A#4
234+
1.335, // B4
235+
1.414, // C5
236+
1.498, // C#5
237+
1.587, // D5
238+
1.682, // D#5
239+
1.782, // E5
240+
1.888, // F5
241+
2.000 // F#5
242+
];
243+
244+
export const NoteBlockSounds = {
245+
"piano": "note.harp",
246+
"bass": "note.bass",
247+
"bass_drum": "note.bd",
248+
"cow_bell": "note.cow_bell",
249+
"clicks_and_sticks": "note.hat",
250+
"flute": "note.flute",
251+
"pling_piano": "note.pling",
252+
"snare_drum": "note.snare",
253+
"bells": "note.bell",
254+
"chimes": "note.chime",
255+
"guitar": "note.guitar",
256+
"xylophone": "note.xylophone",
257+
"iron_xylophone": "note.iron_xylophone",
258+
"didgeridoo": "note.didgeridoo",
259+
"bit": "note.bit",
260+
"banjo": "note.banjo"
261+
};
262+
263+
264+
export const VERSION = "2.0.8";

scripts/main.js

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BlockTypes, BlockVolume, Player, system, world } from "@minecraft/server";
1+
import { BlockVolume, Player, system, world } from "@minecraft/server";
22
import { ModalFormData } from "@minecraft/server-ui";
3-
import { Instruments, InstrumentsTranslateKey, Scales, VERSION } from "./datalist.js";
3+
import { Instruments, InstrumentsTranslateKey, NoteBlockPitches, NoteBlockSounds, Scales, VERSION } from "./data.js";
44

55
const DefaultConfig = {
66
scale_notation: 1,
@@ -26,12 +26,19 @@ world.afterEvents.playerSpawn.subscribe(e => {
2626
if (e.player.getDynamicProperty("isEnable") == undefined) {
2727
e.player.setDynamicProperty("isEnable", true);
2828
}
29+
if (e.player.getDynamicProperty("isReverseNoteWithSneakEnabled") == undefined) {
30+
e.player.setDynamicProperty("isReverseNoteWithSneakEnabled", false);
31+
}
32+
if (e.player.getDynamicProperty("distance") == undefined) {
33+
e.player.setDynamicProperty("distance", 10);
34+
}
2935
})
3036

3137
world.afterEvents.playerSpawn.subscribe(() => {
3238
if (world.getAllPlayers().length < 2) {
33-
world.sendMessage(`\n§l§eNoteblock+ v${VERSION} created by oasobi\n§r§p---------------------\nNoteBlockPlus v${VERSION}が正常に読み込まれました。\nこのメッセージが表示されなくなった場合は、以下のリンクにアクセスしてください。\nhttps://go.oasoobi.net/NoteBlockPlus\n\nNoteBlockPlus has been loaded successfully.
34-
If this message no longer appears, please check for updates at https://go.oasoobi.net/NoteBlockPlus.\n§r`);
39+
system.run(() => {
40+
world.sendMessage(`\n§l§eNoteblock+ v${VERSION} created by oasobi\n§r§p---------------------\nNoteBlockPlus v${VERSION}が正常に読み込まれました。\nこのメッセージが表示されなくなった場合は、以下のリンクにアクセスしてください。\nhttps://go.oasoobi.net/NoteBlockPlus\n\nNoteBlockPlus v${VERSION} has been loaded successfully!\nIf you no longer see this message, please check for updates at https://go.oasoobi.net/NoteBlockPlus.§r`);
41+
})
3542
}
3643

3744
})
@@ -45,7 +52,7 @@ system.runInterval(() => {
4552
const scaleNotation = player.getDynamicProperty("scale_notation");
4653
const isDisplayClick = player.getDynamicProperty("is_display_click_count");
4754
const isDisplayInstrument = player.getDynamicProperty("is_display_instrument");
48-
const view = player.getBlockFromViewDirection({ maxDistance: 10 });
55+
const view = player.getBlockFromViewDirection({ maxDistance: player.getDynamicProperty("distance") + 1 });
4956

5057
if (!view) return player.onScreenDisplay.setActionBar(" ");
5158
const block = view.block;
@@ -93,11 +100,9 @@ system.runInterval(() => {
93100
}
94101
}
95102
//ブロックをもとに戻す
96-
system.run(() => {
97-
const volume = new BlockVolume({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }, { x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z });
98-
block.dimension.fillBlocks(volume, "minecraft:air");
99-
block.dimension.getBlock({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }).setPermutation(permutation);
100-
})
103+
const volume = new BlockVolume({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }, { x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z });
104+
block.dimension.fillBlocks(volume, "minecraft:air");
105+
block.dimension.getBlock({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }).setPermutation(permutation);
101106
})
102107
})
103108

@@ -109,21 +114,26 @@ system.afterEvents.scriptEventReceive.subscribe(e => {
109114
.title("設定")
110115
.dropdown("\n言語", ["English", "日本語"], sourceEntity.getDynamicProperty("language"))
111116
.dropdown("音階の表示形式", ["イタリア式(ドレミ)", "国際式(C,C#,D)"], sourceEntity.getDynamicProperty("scale_notation"))
117+
.slider("距離", 1, 20, 1, sourceEntity.getDynamicProperty("distance"))
112118
.toggle("楽器を表示する", sourceEntity.getDynamicProperty("is_display_instrument"))
113119
.toggle("クリック数を表示する", sourceEntity.getDynamicProperty("is_display_click_count"))
120+
.toggle("しゃがみながら右クリックで音階を一つ下げる", sourceEntity.getDynamicProperty("isReverseNoteWithSneakEnabled"))
121+
.label("* この機能は実験的なものです。使用は自己責任でお願いします。")
114122
.toggle("デフォルトに戻す")
115123
.label("* デフォルトに戻すを選択すると、言語以外の設定が初期化されます。")
116124
.submitButton("適用")
117125
.show(sourceEntity).then(res => {
118126
if (res.canceled) return;
119-
if (res.formValues[4]) {
127+
if (res.formValues[6]) {
120128
initializeConfig(sourceEntity);
121129
} else {
122130
//設定の変更
123131
sourceEntity.setDynamicProperty("language", res.formValues[0]);
124132
sourceEntity.setDynamicProperty("scale_notation", res.formValues[1])
125-
sourceEntity.setDynamicProperty("is_display_instrument", res.formValues[2])
126-
sourceEntity.setDynamicProperty("is_display_click_count", res.formValues[3])
133+
sourceEntity.setDynamicProperty("distance", res.formValues[2])
134+
sourceEntity.setDynamicProperty("is_display_instrument", res.formValues[3])
135+
sourceEntity.setDynamicProperty("is_display_click_count", res.formValues[4])
136+
sourceEntity.setDynamicProperty("isReverseNoteWithSneakEnabled", res.formValues[5])
127137
}
128138

129139
system.run(() => {
@@ -140,20 +150,25 @@ system.afterEvents.scriptEventReceive.subscribe(e => {
140150
.title("Settings")
141151
.dropdown("\nLanguage", ["English", "日本語"], sourceEntity.getDynamicProperty("language"))
142152
.dropdown("Scale notation", ["solfege(do,re,mi)", "international(C,C#,D)"], sourceEntity.getDynamicProperty("scale_notation"))
153+
.slider("Distance", 1, 20, 1, sourceEntity.getDynamicProperty("distance"))
143154
.toggle("Display Instruments", sourceEntity.getDynamicProperty("is_display_instrument"))
144155
.toggle("Display clicks", sourceEntity.getDynamicProperty("is_display_click_count"))
156+
.toggle("Sneak + Right Click to decrease the scale by one step", sourceEntity.getDynamicProperty("isReverseNoteWithSneakEnabled"))
157+
.label("* This is an experimental feature. Use at your own risk.")
145158
.toggle("Restore settings")
146159
.label("* If you select Restore settings, all settings except language will be reset.")
147160
.submitButton("Apply")
148161
.show(sourceEntity).then(res => {
149162
if (res.canceled) return;
150-
if (res.formValues[4]) {
163+
if (res.formValues[6]) {
151164
initializeConfig(sourceEntity);
152165
} else {
153166
sourceEntity.setDynamicProperty("language", res.formValues[0]);
154167
sourceEntity.setDynamicProperty("scale_notation", res.formValues[1])
155-
sourceEntity.setDynamicProperty("is_display_instrument", res.formValues[2])
156-
sourceEntity.setDynamicProperty("is_display_click_count", res.formValues[3])
168+
sourceEntity.setDynamicProperty("distance", res.formValues[2])
169+
sourceEntity.setDynamicProperty("is_display_instrument", res.formValues[3])
170+
sourceEntity.setDynamicProperty("is_display_click_count", res.formValues[4])
171+
sourceEntity.setDynamicProperty("isReverseNoteWithSneakEnabled", res.formValues[5])
157172
}
158173

159174
system.run(() => {
@@ -177,11 +192,7 @@ system.afterEvents.scriptEventReceive.subscribe(e => {
177192
}
178193
})
179194
} else if (id == "note:version") {
180-
if (sourceEntity.getDynamicProperty("language") == 1) {
181-
sourceEntity.sendMessage(`§eNoteBlock+ v${VERSION} を使用しています。`);
182-
} else {
183-
sourceEntity.sendMessage(`§eYou are using NoteBlock+ v${VERSION}.`);
184-
}
195+
sourceEntity.sendMessage(`§eNoteBlock+ v${VERSION}`);
185196
}
186197
})
187198

@@ -194,3 +205,38 @@ function initializeConfig(player) {
194205
player.setDynamicProperty("is_display_instrument", DefaultConfig.is_display_instrument);
195206
player.setDynamicProperty("is_display_click_count", DefaultConfig.is_display_click_count);
196207
}
208+
209+
world.beforeEvents.playerInteractWithBlock.subscribe(e => {
210+
const { block, player } = e;
211+
if (block.typeId == "minecraft:noteblock" && player.isSneaking && player.getDynamicProperty("isReverseNoteWithSneakEnabled") && player.getDynamicProperty("isEnable")) {
212+
e.cancel = true;
213+
system.run(() => {
214+
const permutation = block.dimension.getBlock({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }).permutation;
215+
world.structureManager.place(world.structureManager.get("__noteblocks"), block.dimension, { x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z });
216+
const chestInv = block.dimension.getBlock({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }).getComponent("minecraft:inventory").container;
217+
chestInv.addItem(block.getItemStack(1, true)); //音ブロックをデータ付きでチェストに追加
218+
for (let i = 0; i < chestInv.size; i++) {
219+
const slot = chestInv.getSlot(i);
220+
if (1 < slot.amount) { //アイテムが二個あるスロットを確認
221+
system.run(() => {
222+
world.structureManager.place(world.structureManager.get(`${i - 1 < 0 ? 24 : i - 1}`), block.dimension, block.location);
223+
let instrument = "piano";
224+
const underblock = block.below(1); //1ブロック下のブロックを取得
225+
const keys = Object.keys(Instruments)
226+
for (const key of keys) {
227+
if (underblock.typeId.includes(key)) {
228+
instrument = Instruments[key];
229+
break;
230+
}
231+
}
232+
player.dimension.playSound(NoteBlockSounds[instrument], block.location, { pitch: NoteBlockPitches[i - 1 < 0 ? 24 : i - 1], volume: 100 });
233+
})
234+
break;
235+
}
236+
}
237+
const volume = new BlockVolume({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }, { x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z });
238+
block.dimension.fillBlocks(volume, "minecraft:air");
239+
block.dimension.getBlock({ x: block.location.x, y: block.dimension.heightRange.max - 1, z: block.location.z }).setPermutation(permutation);
240+
})
241+
}
242+
})

structures/0.mcstructure

361 Bytes
Binary file not shown.

structures/1.mcstructure

361 Bytes
Binary file not shown.

structures/10.mcstructure

361 Bytes
Binary file not shown.

structures/11.mcstructure

361 Bytes
Binary file not shown.

structures/12.mcstructure

361 Bytes
Binary file not shown.

structures/13.mcstructure

361 Bytes
Binary file not shown.

structures/14.mcstructure

361 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)