/
bouncer.rb
47 lines (40 loc) · 1.16 KB
/
bouncer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class BouncerPlugin
include Purugin::Plugin
description 'Bouncer', 0.2
class FlightInfo
INCREMENT = 0.1
MAX_HEIGHT = 2.0
attr_accessor :height, :falling
def initialize
@height, @falling = 0.0, false
end
def higher!
@height += INCREMENT if @height < MAX_HEIGHT
@falling = true
@height
end
end
def on_enable
bouncy_material = config.get!('material', 'stone')
players = {}
event(:entity_damage) do |e| # Done falling: don't take damage
e.cancelled = true if players[e.entity] && players[e.entity].falling
end
event(:player_move) do |e|
me = e.player
block = me.world.block_at(e.to).block_at(:down)
if block.is? bouncy_material # Take off
(players[me] ||= FlightInfo.new).higher!
me.velocity = me.location.direction.multiply(0.2).tap do |dir|
dir.y = players[me].height
end
me.fall_distance = 0
elsif players[me] && players[me].falling
if !block.is?(:air, bouncy_material) # not a bouncy thing. stop.
players.delete(me)
me.fall_distance = 0
end
end
end
end
end