Skip to content

Commit b650e84

Browse files
feat: tree system
1 parent 1e17964 commit b650e84

8 files changed

Lines changed: 684 additions & 0 deletions

File tree

type.generic/src/main/java/net/swofty/type/generic/command/commands/MessageCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import net.swofty.type.generic.HypixelGenericLoader;
88
import net.swofty.type.generic.command.CommandParameters;
99
import net.swofty.type.generic.command.HypixelCommand;
10+
import net.swofty.type.generic.data.DataHandler;
11+
import net.swofty.type.generic.data.HypixelDataHandler;
1012
import net.swofty.type.generic.data.HypixelDataHandler;
1113
import net.swofty.type.generic.user.HypixelPlayer;
1214
import net.swofty.type.generic.user.categories.Rank;
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package net.swofty.type.skyblockgeneric.commands;
2+
3+
import net.minestom.server.command.builder.arguments.ArgumentEnum;
4+
import net.minestom.server.command.builder.arguments.ArgumentType;
5+
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
6+
import net.minestom.server.instance.SharedInstance;
7+
import net.swofty.type.generic.command.CommandParameters;
8+
import net.swofty.type.generic.command.HypixelCommand;
9+
import net.swofty.type.skyblockgeneric.tree.SkyBlockTree;
10+
import net.swofty.type.skyblockgeneric.tree.TreeConfig;
11+
import net.swofty.type.skyblockgeneric.tree.TreeType;
12+
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
13+
import net.swofty.type.generic.user.categories.Rank;
14+
15+
@CommandParameters(
16+
aliases = "tree",
17+
description = "Generates a tree at your location",
18+
usage = "/generatetree <type> [minHeight maxHeight] [minWidth maxWidth]",
19+
permission = Rank.ADMIN,
20+
allowsConsole = false
21+
)
22+
public class GenerateTreeCommand extends HypixelCommand {
23+
@Override
24+
public void registerUsage(MinestomCommand command) {
25+
ArgumentEnum<TreeType> treeTypeArg = ArgumentType.Enum("type", TreeType.class);
26+
ArgumentInteger minHeightArg = ArgumentType.Integer("minHeight");
27+
ArgumentInteger maxHeightArg = ArgumentType.Integer("maxHeight");
28+
ArgumentInteger minWidthArg = ArgumentType.Integer("minWidth");
29+
ArgumentInteger maxWidthArg = ArgumentType.Integer("maxWidth");
30+
31+
// Just type - use defaults
32+
command.addSyntax((sender, context) -> {
33+
if (!permissionCheck(sender)) return;
34+
35+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
36+
TreeType type = context.get(treeTypeArg);
37+
38+
generateTree(player, type, type.getDefaultConfig());
39+
}, treeTypeArg);
40+
41+
// Type + height
42+
command.addSyntax((sender, context) -> {
43+
if (!permissionCheck(sender)) return;
44+
45+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
46+
TreeType type = context.get(treeTypeArg);
47+
int minHeight = context.get(minHeightArg);
48+
int maxHeight = context.get(maxHeightArg);
49+
50+
if (minHeight > maxHeight) {
51+
player.sendMessage("§cMinimum height cannot be greater than maximum height!");
52+
return;
53+
}
54+
55+
if (minHeight < 2 || maxHeight > 50) {
56+
player.sendMessage("§cHeight must be between 2 and 50!");
57+
return;
58+
}
59+
60+
TreeConfig customConfig = type.getDefaultConfig()
61+
.withMinHeight(minHeight)
62+
.withMaxHeight(maxHeight);
63+
64+
generateTree(player, type, customConfig);
65+
}, treeTypeArg, minHeightArg, maxHeightArg);
66+
67+
// Type + height + width
68+
command.addSyntax((sender, context) -> {
69+
if (!permissionCheck(sender)) return;
70+
71+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
72+
TreeType type = context.get(treeTypeArg);
73+
int minHeight = context.get(minHeightArg);
74+
int maxHeight = context.get(maxHeightArg);
75+
int minWidth = context.get(minWidthArg);
76+
int maxWidth = context.get(maxWidthArg);
77+
78+
if (minHeight > maxHeight) {
79+
player.sendMessage("§cMinimum height cannot be greater than maximum height!");
80+
return;
81+
}
82+
83+
if (minWidth > maxWidth) {
84+
player.sendMessage("§cMinimum width cannot be greater than maximum width!");
85+
return;
86+
}
87+
88+
if (minHeight < 2 || maxHeight > 50) {
89+
player.sendMessage("§cHeight must be between 2 and 50!");
90+
return;
91+
}
92+
93+
if (minWidth < 1 || maxWidth > 20) {
94+
player.sendMessage("§cWidth must be between 1 and 20!");
95+
return;
96+
}
97+
98+
TreeConfig customConfig = type.getDefaultConfig()
99+
.withMinHeight(minHeight)
100+
.withMaxHeight(maxHeight)
101+
.withMinWidth(minWidth)
102+
.withMaxWidth(maxWidth);
103+
104+
generateTree(player, type, customConfig);
105+
}, treeTypeArg, minHeightArg, maxHeightArg, minWidthArg, maxWidthArg);
106+
}
107+
108+
private void generateTree(SkyBlockPlayer player, TreeType type, TreeConfig config) {
109+
SkyBlockTree tree = new SkyBlockTree(
110+
0,
111+
player.getPosition().blockX(),
112+
player.getPosition().blockY(),
113+
player.getPosition().blockZ(),
114+
type,
115+
config
116+
);
117+
118+
tree.build((SharedInstance) player.getInstance());
119+
120+
player.sendMessage("§aGenerated " + type.name().toLowerCase().replace("_", " ") +
121+
" tree! Height: " + config.minHeight() + "-" + config.maxHeight() +
122+
", Width: " + config.minWidth() + "-" + config.maxWidth());
123+
}
124+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.swofty.type.skyblockgeneric.tree;
2+
3+
import lombok.Getter;
4+
5+
import java.util.concurrent.ThreadLocalRandom;
6+
7+
@Getter
8+
public enum BranchDirection {
9+
NORTH(0, -1),
10+
SOUTH(0, 1),
11+
EAST(1, 0),
12+
WEST(-1, 0),
13+
NORTH_EAST(1, -1),
14+
NORTH_WEST(-1, -1),
15+
SOUTH_EAST(1, 1),
16+
SOUTH_WEST(-1, 1);
17+
18+
private final int xOffset;
19+
private final int zOffset;
20+
21+
BranchDirection(int xOffset, int zOffset) {
22+
this.xOffset = xOffset;
23+
this.zOffset = zOffset;
24+
}
25+
26+
public static BranchDirection random() {
27+
BranchDirection[] values = values();
28+
return values[ThreadLocalRandom.current().nextInt(values.length)];
29+
}
30+
31+
public static BranchDirection randomCardinal() {
32+
BranchDirection[] cardinals = {NORTH, SOUTH, EAST, WEST};
33+
return cardinals[ThreadLocalRandom.current().nextInt(cardinals.length)];
34+
}
35+
36+
public boolean isOpposite(BranchDirection other) {
37+
return this.xOffset == -other.xOffset && this.zOffset == -other.zOffset;
38+
}
39+
}

0 commit comments

Comments
 (0)