Skip to content

Commit 544e887

Browse files
committed
Added more sounds and moon jump
Added slow falling on fly Scale speed with health Reorganized and documented code
1 parent 46dcca3 commit 544e887

File tree

8 files changed

+137
-11
lines changed

8 files changed

+137
-11
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"format_version": "1.10.0",
3+
"particle_effect": {
4+
"description": {
5+
"identifier": "whynot:moon_jump",
6+
"basic_render_parameters": {
7+
"material": "particles_alpha",
8+
"texture": "textures/particle/moon_jump"
9+
}
10+
},
11+
"components": {
12+
"minecraft:emitter_rate_instant": {
13+
"num_particles": 1
14+
},
15+
"minecraft:emitter_lifetime_once": {
16+
"active_time": 1
17+
},
18+
"minecraft:emitter_shape_point": {
19+
"direction": [0, -1, 0]
20+
},
21+
"minecraft:particle_lifetime_expression": {
22+
"max_lifetime": "16 / 20.0"
23+
},
24+
"minecraft:particle_initial_speed": 2,
25+
"minecraft:particle_motion_dynamic": {},
26+
"minecraft:particle_appearance_billboard": {
27+
"size": ["variable.size", "variable.size"],
28+
"facing_camera_mode": "emitter_transform_xz",
29+
"uv": {
30+
"texture_width": 32,
31+
"texture_height": 224,
32+
"flipbook": {
33+
"base_UV": [0, 0],
34+
"size_UV": [32, 32],
35+
"step_UV": [0, 32],
36+
"frames_per_second": 8,
37+
"max_frame": 16,
38+
"stretch_to_lifetime": true
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
23.5 KB
Binary file not shown.
57.5 KB
Binary file not shown.
24.5 KB
Binary file not shown.
22.7 KB
Binary file not shown.

resource_packs/whynot/sounds/sound_definitions.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
"camino_recorra_tu_pasado": {
55
"category": "music",
66
"sounds": ["sounds/camino_recorra_tu_pasado"]
7+
},
8+
"light_dash": {
9+
"category": "player",
10+
"sounds": ["sounds/light/light_dash"]
11+
},
12+
"light_beam_start": {
13+
"category": "player",
14+
"sounds": ["sounds/light/light_beam_start"],
15+
"volume": 0.01
16+
},
17+
"light_beam_loop": {
18+
"category": "player",
19+
"volume": 0.01,
20+
"sounds": ["sounds/light/light_beam_loop"]
21+
},
22+
"moon_jump": {
23+
"category": "player",
24+
"volume": 0.01,
25+
"sounds": ["sounds/light/moon_jump"]
726
}
827
}
928
}
724 Bytes
Loading

scripts/addons/lightFruit/lightFruit.ts

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ButtonState, EffectTypes, EntityInventoryComponent, EquipmentSlot, InputButton, ItemLockMode, ItemStack, Player, StartupEvent, system, Vector3, world } from "@minecraft/server";
1+
import { ButtonState, EffectTypes, EntityHealthComponent, EntityInventoryComponent, EquipmentSlot, InputButton, InputPermissionCategory, ItemLockMode, ItemStack, MolangVariableMap, Player, StartupEvent, system, Vector3, world } from "@minecraft/server";
22
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
33
import { directionVector, entityGetSlot, entityHasSlotTag } from "../../utility";
44
import { V3 } from "../../math/vectorUtils";
5-
import { deg2Rad } from "../../math/general";
5+
import { deg2Rad, remap } from "../../math/general";
66

77
let light: ItemStack
88
const fCooldownTime = 80
@@ -13,6 +13,9 @@ enum States {
1313
}
1414
const flyTurnCooldownTime: number = 10
1515
const flyTurnCooldown: Map<string, number> = new Map()
16+
const flySoundCooldown: Map<string, number> = new Map()
17+
const airTime: Map<string, number> = new Map()
18+
const airJumps: Map<string, number> = new Map()
1619
const flyingAngles: Map<string, Vector3> = new Map()
1720
// Defining setters for ability cooldowns
1821
Object.defineProperties(Player.prototype, {
@@ -71,12 +74,37 @@ export function main() {
7174
if (!entityHasSlotTag(player, EquipmentSlot.Mainhand, "whynot:light")) return;
7275

7376
if (button != InputButton.Jump) return
74-
if (!player.isOnGround && pressed && player.state == States.NORMAL && player.fCooldown <= 0) {
75-
player.state = States.FLYING
76-
flyingAngles.set(player.id, player.getViewDirection());
77+
// Activate fly
78+
if (((airTime.get(player.id) ?? 0) > 2) && pressed && player.state == States.NORMAL) {
79+
if (player.fCooldown <= 0 && player.isSneaking) {
80+
player.state = States.FLYING
81+
flyingAngles.set(player.id, player.getViewDirection());
82+
player.addEffect(MinecraftEffectTypes.SlowFalling, 20000000, {showParticles: false})
83+
player.playSound("light_dash")
84+
player.playSound("light_beam_start")
85+
86+
flySoundCooldown.set(player.id, 0)
87+
flyTurnCooldown.set(player.id, 0)
88+
player.inputPermissions.setPermissionCategory(InputPermissionCategory.Movement, false)
89+
} else if ((airJumps.get(player.id) ?? 0) > 0) {
90+
player.applyImpulse(V3.make(0, -player.getVelocity().y + 0.75, 0))
91+
let molangSize1 = new MolangVariableMap(); molangSize1.setFloat("size", 1.0 / 2.0)
92+
let molangSize2 = new MolangVariableMap(); molangSize2.setFloat("size", 1.3 / 2.0)
93+
let molangSize3 = new MolangVariableMap(); molangSize3.setFloat("size", 1.5 / 2.0)
94+
player.spawnParticle("whynot:moon_jump", V3.add(player.location, V3.make(0, 0, 0)), molangSize1)
95+
player.spawnParticle("whynot:moon_jump", V3.add(player.location, V3.make(0, -0.2, 0)), molangSize2)
96+
player.spawnParticle("whynot:moon_jump", V3.add(player.location, V3.make(0, -0.4, 0)), molangSize3)
97+
player.playSound("moon_jump")
98+
airJumps.set(player.id, (airJumps.get(player.id) ?? 0) - 1)
99+
}
77100
}
101+
// Deactivate fly
78102
if (!pressed && player.state == States.FLYING) {
103+
player.inputPermissions.setPermissionCategory(InputPermissionCategory.Movement, true)
79104
player.state = States.NORMAL
105+
player.removeEffect(MinecraftEffectTypes.SlowFalling);
106+
player.addEffect(MinecraftEffectTypes.SlowFalling, 25, {showParticles: false})
107+
80108
player.removeEffect(MinecraftEffectTypes.Invisibility)
81109
}
82110
})
@@ -88,36 +116,71 @@ export function main() {
88116
system.runInterval(mainTick)
89117
}
90118

119+
91120
function mainTick() {
92121
world.getAllPlayers().forEach(player => {
122+
// Set Airtime
123+
if (player.isOnGround) {
124+
if (player.state != States.FLYING) {
125+
player.removeEffect(MinecraftEffectTypes.SlowFalling);
126+
airJumps.set(player.id, 10)
127+
128+
129+
}
130+
airTime.set(player.id, 0)
131+
}
132+
else airTime.set(player.id, (airTime.get(player.id) ?? 0) + 1)
133+
93134
if (player.state == States.FLYING) {
135+
94136
player.addEffect(MinecraftEffectTypes.Invisibility, 20000000, {showParticles: false})
95137
player.fCooldown = fCooldownTime
138+
139+
// If viewing angle change is significant change direction
96140
const viewDir = player.getViewDirection();
97141
const addVel = V3.normalize(flyingAngles.get(player.id) ?? viewDir);
98142
if (V3.dot(viewDir, addVel) < flyTurnThreshold && (flyTurnCooldown.get(player.id) ?? 0) <= 0) {
99143
flyingAngles.set(player.id, viewDir);
144+
player.playSound("light_dash")
100145
}
146+
147+
// Scale speed from health
148+
const health = player.getComponent(EntityHealthComponent.componentId) as EntityHealthComponent;
149+
const speed = remap(health.currentValue, health.effectiveMin, health.effectiveMax, 0.1, 1.0);
150+
const vel = V3.scale(addVel, speed)
101151
player.clearVelocity();
102-
player.applyImpulse(addVel);
152+
player.applyImpulse(vel);
103153

104-
const vel = player.getVelocity();
105-
const blockHit = player.dimension.getBlockFromRay(player.location, vel, {maxDistance: 1, includeLiquidBlocks:false, includePassableBlocks: false})
106-
if ((flyTurnCooldown.get(player.id) ?? 0) > 0) {
107-
flyTurnCooldown.set(player.id, (flyTurnCooldown.get(player.id) ?? 0) - 1)
108-
}
154+
// Get block in path and bounce if needed
155+
const blockHit = player.dimension.getBlockFromRay(player.location, vel, {maxDistance: 2, includeLiquidBlocks:false, includePassableBlocks: false})
109156
if (blockHit && blockHit.block.isSolid) {
110157
const bounced = V3.reflect(vel, directionVector(blockHit.face));
111158
flyingAngles.set(player.id, bounced);
112159
flyTurnCooldown.set(player.id, flyTurnCooldownTime)
160+
player.playSound("light_dash")
161+
}
162+
163+
// Reduce fly turn cooldown
164+
let currFlyTurnCooldown = flyTurnCooldown.get(player.id) ?? 0;
165+
if (currFlyTurnCooldown > 0) flyTurnCooldown.set(player.id, currFlyTurnCooldown - 1);
166+
167+
let currSoundCooldon = flySoundCooldown.get(player.id) ?? 0;
168+
if (currSoundCooldon > 0) flySoundCooldown.set(player.id, currSoundCooldon - 1);
169+
else {
170+
player.playSound("light_beam_loop", {volume: 10})
171+
// player.playSound("light_beam_loop", {volume: 10})
172+
flySoundCooldown.set(player.id, 7) //8.58
113173
}
114174
}
175+
176+
// Reduce all cooldowns
115177
if (player.zCooldown > 0) player.zCooldown--;
116178
if (player.xCooldown > 0) player.xCooldown--;
117179
if (player.cCooldown > 0) player.cCooldown--;
118180
if (player.vCooldown > 0) player.vCooldown--;
119181
if (player.fCooldown > 0) player.fCooldown--;
120182

183+
// If player is holding light display cooldowns
121184
if (!entityHasSlotTag(player, EquipmentSlot.Mainhand, "whynot:light")) return
122185
player.onScreenDisplay.setActionBar(`Z: ${player.zCooldown} X: ${player.xCooldown} C: ${player.cCooldown} V: ${player.vCooldown} F: ${player.fCooldown}`)
123186
})

0 commit comments

Comments
 (0)