mcapibridge 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/PKG-INFO +2 -2
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/README.MD +1 -1
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/pyproject.toml +1 -1
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mc/minecraft.py +44 -50
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mcapibridge.egg-info/PKG-INFO +2 -2
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/LICENSE +0 -0
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/setup.cfg +0 -0
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mc/__init__.py +0 -0
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mcapibridge.egg-info/SOURCES.txt +0 -0
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mcapibridge.egg-info/dependency_links.txt +0 -0
- {mcapibridge-0.2.2 → mcapibridge-0.2.3}/src/mcapibridge.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcapibridge
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Python libary for MCAPIBridge
|
|
5
5
|
Author: TaotianZhufang
|
|
6
6
|
License: MIT License
|
|
@@ -39,7 +39,7 @@ MCAPIBridge is a mod for Minecraft loaded with Fabric.This libary offers some wa
|
|
|
39
39
|
### Install
|
|
40
40
|
Ensure your mod loaded.
|
|
41
41
|
|
|
42
|
-
**Please ensure you are using the latest libary.Now version is 0.2.
|
|
42
|
+
**Please ensure you are using the latest libary.Now version is 0.2.3.**
|
|
43
43
|
|
|
44
44
|
Use pip to install this.
|
|
45
45
|
```
|
|
@@ -7,7 +7,7 @@ MCAPIBridge is a mod for Minecraft loaded with Fabric.This libary offers some wa
|
|
|
7
7
|
### Install
|
|
8
8
|
Ensure your mod loaded.
|
|
9
9
|
|
|
10
|
-
**Please ensure you are using the latest libary.Now version is 0.2.
|
|
10
|
+
**Please ensure you are using the latest libary.Now version is 0.2.3.**
|
|
11
11
|
|
|
12
12
|
Use pip to install this.
|
|
13
13
|
```
|
|
@@ -9,7 +9,7 @@ class AudioManager:
|
|
|
9
9
|
def __init__(self, mc):
|
|
10
10
|
self.mc = mc
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def loadWav(self, target, audioId, filepath):
|
|
13
13
|
with wave.open(filepath, 'rb') as wav:
|
|
14
14
|
channels = wav.getnchannels()
|
|
15
15
|
sample_width = wav.getsampwidth()
|
|
@@ -22,7 +22,7 @@ class AudioManager:
|
|
|
22
22
|
for i in range(0, len(samples), 2):
|
|
23
23
|
mono_samples.append((samples[i] + samples[i+1]) // 2)
|
|
24
24
|
frames = struct.pack(f'<{len(mono_samples)}h', *mono_samples)
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
if sample_width == 1:
|
|
27
27
|
samples = struct.unpack(f'{len(frames)}B', frames)
|
|
28
28
|
samples = [(s - 128) * 256 for s in samples]
|
|
@@ -31,74 +31,68 @@ class AudioManager:
|
|
|
31
31
|
b64_data = base64.b64encode(frames).decode('ascii')
|
|
32
32
|
|
|
33
33
|
chunk_size = 40000
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for i, chunk in enumerate(chunks):
|
|
34
|
+
for i in range(0, len(b64_data), chunk_size):
|
|
35
|
+
chunk = b64_data[i:i + chunk_size]
|
|
37
36
|
if i == 0:
|
|
38
|
-
self.mc._send(f"audio.load({target},{
|
|
37
|
+
self.mc._send(f"audio.load({target},{audioId},{sample_rate},{chunk})")
|
|
39
38
|
else:
|
|
40
|
-
self.mc._send(f"audio.stream({target},{
|
|
39
|
+
self.mc._send(f"audio.stream({target},{audioId},{sample_rate},{chunk})")
|
|
41
40
|
time.sleep(0.02)
|
|
42
|
-
|
|
43
|
-
self.mc._send(f"audio.finishLoad({target},{audio_id})")
|
|
44
41
|
|
|
42
|
+
self.mc._send(f"audio.finishLoad({target},{audioId})")
|
|
45
43
|
print(f"[Audio] Loaded {filepath}: {len(frames)} bytes, {sample_rate}Hz")
|
|
46
44
|
|
|
47
|
-
def
|
|
48
|
-
b64_data = base64.b64encode(
|
|
45
|
+
def loadRaw(self, target, audioId, pcmData, sampleRate=44100):
|
|
46
|
+
b64_data = base64.b64encode(pcmData).decode('ascii')
|
|
49
47
|
|
|
50
48
|
chunk_size = 40000
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
for i, chunk in enumerate(chunks):
|
|
49
|
+
for i in range(0, len(b64_data), chunk_size):
|
|
50
|
+
chunk = b64_data[i:i + chunk_size]
|
|
54
51
|
if i == 0:
|
|
55
|
-
self.mc._send(f"audio.load({target},{
|
|
52
|
+
self.mc._send(f"audio.load({target},{audioId},{sampleRate},{chunk})")
|
|
56
53
|
else:
|
|
57
|
-
self.mc._send(f"audio.stream({target},{
|
|
54
|
+
self.mc._send(f"audio.stream({target},{audioId},{sampleRate},{chunk})")
|
|
58
55
|
time.sleep(0.02)
|
|
56
|
+
|
|
57
|
+
self.mc._send(f"audio.finishLoad({target},{audioId})")
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
def generateTone(self, target, audioId, frequency=440, duration=1.0, sampleRate=44100):
|
|
60
|
+
numSamples = int(sampleRate * duration)
|
|
61
|
+
samples = []
|
|
62
|
+
|
|
63
|
+
for i in range(numSamples):
|
|
64
|
+
t = i / sampleRate
|
|
65
|
+
value = int(32767 * math.sin(2 * math.pi * frequency * t))
|
|
66
|
+
samples.append(value)
|
|
67
|
+
|
|
68
|
+
pcmData = struct.pack(f'<{len(samples)}h', *samples)
|
|
69
|
+
self.loadRaw(target, audioId, pcmData, sampleRate)
|
|
61
70
|
|
|
62
|
-
def play(self, target,
|
|
63
|
-
|
|
64
|
-
self.mc._send(f"audio.play({target},{
|
|
71
|
+
def play(self, target, audioId, volume=1.0, loop=False):
|
|
72
|
+
loopStr = "true" if loop else "false"
|
|
73
|
+
self.mc._send(f"audio.play({target},{audioId},{volume},{loopStr})")
|
|
65
74
|
|
|
66
|
-
def
|
|
67
|
-
self.mc._send(f"audio.
|
|
75
|
+
def play3d(self, target, audioId, x, y, z, volume=1.0, rolloff=1.0):
|
|
76
|
+
self.mc._send(f"audio.play3d({target},{audioId},{x},{y},{z},{volume},{rolloff})")
|
|
68
77
|
|
|
69
|
-
def
|
|
70
|
-
self.mc._send(f"audio.
|
|
71
|
-
|
|
72
|
-
def pause(self, target,
|
|
73
|
-
self.mc._send(f"audio.pause({target},{
|
|
78
|
+
def playAt(self, audioId, x, y, z, radius=32, volume=1.0):
|
|
79
|
+
self.mc._send(f"audio.playAt({audioId},{x},{y},{z},{radius},{volume})")
|
|
80
|
+
|
|
81
|
+
def pause(self, target, audioId):
|
|
82
|
+
self.mc._send(f"audio.pause({target},{audioId})")
|
|
74
83
|
|
|
75
|
-
def stop(self, target,
|
|
76
|
-
self.mc._send(f"audio.stop({target},{
|
|
84
|
+
def stop(self, target, audioId):
|
|
85
|
+
self.mc._send(f"audio.stop({target},{audioId})")
|
|
77
86
|
|
|
78
|
-
def unload(self, target,
|
|
79
|
-
self.mc._send(f"audio.unload({target},{
|
|
87
|
+
def unload(self, target, audioId):
|
|
88
|
+
self.mc._send(f"audio.unload({target},{audioId})")
|
|
80
89
|
|
|
81
|
-
def
|
|
90
|
+
def setVolume(self, target, audioId, volume):
|
|
82
91
|
"""(0.0 - 1.0)"""
|
|
83
|
-
self.mc._send(f"audio.volume({target},{
|
|
92
|
+
self.mc._send(f"audio.volume({target},{audioId},{volume})")
|
|
84
93
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
num_samples = int(sample_rate * duration)
|
|
89
|
-
samples = []
|
|
90
|
-
|
|
91
|
-
for i in range(num_samples):
|
|
92
|
-
t = i / sample_rate
|
|
93
|
-
value = int(32767 * math.sin(2 * math.pi * frequency * t))
|
|
94
|
-
samples.append(value)
|
|
95
|
-
|
|
96
|
-
pcm_data = struct.pack(f'<{len(samples)}h', *samples)
|
|
97
|
-
self.load_raw(target, audio_id, pcm_data, sample_rate)
|
|
98
|
-
|
|
99
|
-
def set_position(self, target, audio_id, x, y, z):
|
|
100
|
-
self.mc._send(f"audio.position({target},{audio_id},{x},{y},{z})")
|
|
101
|
-
|
|
94
|
+
def setPosition(self, target, audioId, x, y, z):
|
|
95
|
+
self.mc._send(f"audio.position({target},{audioId},{x},{y},{z})")
|
|
102
96
|
|
|
103
97
|
class Vec3:
|
|
104
98
|
def __init__(self, x, y, z):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcapibridge
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Python libary for MCAPIBridge
|
|
5
5
|
Author: TaotianZhufang
|
|
6
6
|
License: MIT License
|
|
@@ -39,7 +39,7 @@ MCAPIBridge is a mod for Minecraft loaded with Fabric.This libary offers some wa
|
|
|
39
39
|
### Install
|
|
40
40
|
Ensure your mod loaded.
|
|
41
41
|
|
|
42
|
-
**Please ensure you are using the latest libary.Now version is 0.2.
|
|
42
|
+
**Please ensure you are using the latest libary.Now version is 0.2.3.**
|
|
43
43
|
|
|
44
44
|
Use pip to install this.
|
|
45
45
|
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|