summaryrefslogtreecommitdiff
path: root/src/main/java/luckyblock/action/LuckyActionHolder.java
blob: b18ad673cc7019d21092f9c902b701c926689fe1 (plain)
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
package luckyblock.action;

import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import luckyblock.action.triggers.*;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;

import java.util.ArrayList;
import java.util.List;

public class LuckyActionHolder {
    private static final List<ILuckyTrigger> cmdList = new ArrayList<>();

    static {
        cmdList.add(new BroadcastTrigger());
        cmdList.add(new SummonItemTrigger());
        cmdList.add(new SummonTrigger());
        cmdList.add(new TrappedRoomTrigger());
    }

    public String type = "";
    public int weight = -1;
    public List<String> queue;

    @SerializedName("delay-queue")
    public List<Integer> delay_queue;
    public JsonElement json;
    public List<String> items;
    public List<String> mobs;
    public int count = 1;
    public int height = 0;
    @SerializedName("is-powered")
    public boolean is_powered = false;
    @SerializedName("wall-block")
    public String wall_block = "minecraft:stone_bricks";
    public int radius = 3;

    public void execute(Level level, BlockPos pos) {
        if (!(level instanceof ServerLevel serverLevel)) { return; }

        for (ILuckyTrigger c : cmdList) {
            if (this.type != null && this.type.equals(c.getName())) {
                c.execute(serverLevel, pos, this, level.getRandom());
                break;
            }
        }

        if (this.queue != null && !this.queue.isEmpty()) {
            for (int i=0;i<this.queue.size();i++) {
                String next = this.queue.get(i);
                int delayTicks = 0;
                if (this.delay_queue != null && i<this.delay_queue.size()) {
                    delayTicks = this.delay_queue.get(i) * 20;
                }
                LuckyActionManager.enqueue(next, pos, serverLevel, delayTicks);
            }
        }
    }

}