forked from friendlyhj/GrassUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventUtils.zs
More file actions
81 lines (70 loc) · 2.46 KB
/
EventUtils.zs
File metadata and controls
81 lines (70 loc) · 2.46 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#loader crafttweaker multiblocked reloadableevents
#priority 32766
import crafttweaker.item.IItemStack;
import crafttweaker.world.IWorld;
import crafttweaker.world.IBlockPos;
import crafttweaker.data.IData;
import crafttweaker.player.IPlayer;
import crafttweaker.world.IFacing;
import mods.ctutils.player.Player;
import scripts.grassUtils.Logger;
import crafttweaker.event.PlayerTickEvent;
import crafttweaker.event.PlayerRespawnEvent;
import mods.ctutils.utils.Math;
static storageData as IData[string] = {};
function getOffset(pos as IBlockPos, x as int, y as int, z as int) as IBlockPos{
var offset as IBlockPos = pos;
if (x > 0) {
offset = offset.getOffset(IFacing.east(), x);
} else if (x < 0) {
offset = offset.getOffset(IFacing.west(), -x);
}
if (y > 0) {
offset = offset.getOffset(IFacing.up(), y);
} else if (y < 0) {
offset = offset.getOffset(IFacing.down(), -y);
}
if (z > 0) {
offset = offset.getOffset(IFacing.south(), z);
} else if (z < 0) {
offset = offset.getOffset(IFacing.north(), -z);
}
return offset;
}
function spawnItem(world as IWorld, item as IItemStack, pos as IBlockPos) as bool{
return world.spawnEntity(item.createEntityItem(world, pos));
}
function enablePlayerDataKeeper() {
events.onPlayerTick(function(event as PlayerTickEvent) {
val player as IPlayer = event.player;
if (!player.world.remote && !Player.isFake(player)) {
storageData[player.id] = player.data;
}
});
events.onPlayerRespawn(function(event as PlayerRespawnEvent) {
val player as IPlayer = event.player;
if (!player.world.remote && !isNull(storageData[player.id])) {
player.update(storageData[player.id]);
}
});
}
function defaultDataHandler(data as IData, player as IPlayer) as bool {
val map = data.asMap();
if (isNull(map) || map.length != 1) {
Logger.sendError("Invalid data argment!");
return false;
}
val playerData as IData = player.data;
val key as string = map.keys[0];
if (!(playerData in key)) {
Logger.sendInfo(key ~ " tag is not found! Adding a tag with value " ~ map.values[0]);
player.update(playerData + data);
Logger.sendInfo("Added " ~ key ~ " tag");
return true;
}
return false;
}
function secondsTicker(world as IWorld, seconds as float) as bool {
val ticks as int = 20 * seconds;
return world.time % ticks == 0;
}