Skip to content

Commit ca88237

Browse files
committed
feat: unfinished PopUpTower and misc bed wars menu changes.
1 parent 9acd5aa commit ca88237

13 files changed

Lines changed: 327 additions & 3 deletions

File tree

type.bedwarsgame/src/main/java/net/swofty/type/bedwarsgame/events/ActionGameCustomItems.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minestom.server.event.entity.projectile.ProjectileCollideWithBlockEvent;
99
import net.minestom.server.event.entity.projectile.ProjectileCollideWithEntityEvent;
1010
import net.minestom.server.event.item.PlayerFinishItemUseEvent;
11+
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
1112
import net.minestom.server.event.player.PlayerUseItemEvent;
1213
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
1314
import net.minestom.server.instance.Instance;
@@ -112,4 +113,9 @@ public void run(PlayerUseItemEvent event) {
112113
TypeBedWarsGameLoader.getItemHandler().onItemUse(event);
113114
}
114115

116+
@HypixelEvent(node = EventNodes.ALL, requireDataLoaded = true)
117+
public void run(PlayerBlockPlaceEvent event) {
118+
TypeBedWarsGameLoader.getItemHandler().onBlockPlace(event);
119+
}
120+
115121
}

type.bedwarsgame/src/main/java/net/swofty/type/bedwarsgame/item/impl/Fireball.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minestom.server.event.player.PlayerUseItemEvent;
1212
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
1313
import net.minestom.server.item.ItemStack;
14+
import net.minestom.server.item.Material;
1415
import net.minestom.server.timer.TaskSchedule;
1516
import net.swofty.pvp.projectile.entities.FireballProjectile;
1617
import net.swofty.type.bedwarsgeneric.item.BedWarsItem;
@@ -25,7 +26,7 @@ public Fireball() {
2526

2627
@Override
2728
public ItemStack getBlandItem() {
28-
return null;
29+
return ItemStack.of(Material.FIRE_CHARGE);
2930
}
3031

3132
@Override
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package net.swofty.type.bedwarsgame.item.impl;
2+
3+
import net.minestom.server.MinecraftServer;
4+
import net.minestom.server.coordinate.Pos;
5+
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
6+
import net.minestom.server.instance.Instance;
7+
import net.minestom.server.instance.block.Block;
8+
import net.minestom.server.item.ItemStack;
9+
import net.minestom.server.item.Material;
10+
import net.minestom.server.timer.TaskSchedule;
11+
import net.swofty.type.bedwarsgeneric.item.BedWarsItem;
12+
import net.swofty.type.generic.gui.inventory.ItemStackCreator;
13+
14+
import java.util.concurrent.atomic.AtomicInteger;
15+
16+
public class PopupTower extends BedWarsItem {
17+
18+
public PopupTower() {
19+
super("popup_tower");
20+
}
21+
22+
private static Block mapColorToWool(String color) {
23+
if (color == null) return Block.WHITE_WOOL;
24+
return switch (color.toLowerCase()) {
25+
case "white" -> Block.WHITE_WOOL;
26+
case "orange" -> Block.ORANGE_WOOL;
27+
case "magenta" -> Block.MAGENTA_WOOL;
28+
case "light_blue", "lightblue" -> Block.LIGHT_BLUE_WOOL;
29+
case "yellow" -> Block.YELLOW_WOOL;
30+
case "lime" -> Block.LIME_WOOL;
31+
case "pink" -> Block.PINK_WOOL;
32+
case "gray" -> Block.GRAY_WOOL;
33+
case "light_gray", "lightgray" -> Block.LIGHT_GRAY_WOOL;
34+
case "cyan" -> Block.CYAN_WOOL;
35+
case "purple" -> Block.PURPLE_WOOL;
36+
case "blue" -> Block.BLUE_WOOL;
37+
case "brown" -> Block.BROWN_WOOL;
38+
case "green" -> Block.GREEN_WOOL;
39+
case "red" -> Block.RED_WOOL;
40+
case "black" -> Block.BLACK_WOOL;
41+
default -> Block.WHITE_WOOL;
42+
};
43+
}
44+
45+
@Override
46+
public ItemStack getBlandItem() {
47+
return ItemStackCreator.createNamedItemStack(Material.CHEST, "§aPop-Up Tower").build();
48+
}
49+
50+
@Override
51+
public void onBlockPlace(PlayerBlockPlaceEvent event) {
52+
event.setBlock(Block.AIR);
53+
54+
Instance instance = event.getInstance();
55+
Pos basePos = event.getBlockPosition().asPos();
56+
57+
try {
58+
instance.loadChunk(basePos).join();
59+
} catch (Exception ignored) {
60+
}
61+
62+
final int LAYERS = 4;
63+
final int RISE_TICK_INTERVAL = 2;
64+
65+
int[][] bottomPattern = new int[][]{
66+
{0, 1, 1, 1, 0},
67+
{1, 0, 5, 0, 1},
68+
{1, 0, 0, 0, 1},
69+
{0, 1, 0, 1, 0}
70+
};
71+
72+
int[][] upperPattern = new int[][]{
73+
{0, 1, 1, 1, 0},
74+
{1, 0, 5, 0, 1},
75+
{1, 0, 0, 0, 1},
76+
{0, 1, 1, 1, 0}
77+
};
78+
79+
String teamColor = event.getPlayer().getTag(net.minestom.server.tag.Tag.String("teamColor"));
80+
Block wool = mapColorToWool(teamColor);
81+
82+
AtomicInteger layerCounter = new AtomicInteger(0);
83+
84+
var player = event.getPlayer();
85+
Pos playerPos = player.getPosition();
86+
double dx = playerPos.x() - basePos.x();
87+
double dz = playerPos.z() - basePos.z();
88+
String front;
89+
if (Math.abs(dx) > Math.abs(dz)) {
90+
front = dx > 0 ? "east" : "west";
91+
} else {
92+
front = dz > 0 ? "south" : "north";
93+
}
94+
95+
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
96+
int layerIndex = layerCounter.getAndIncrement();
97+
if (layerIndex >= LAYERS) return;
98+
99+
int[][] pattern = (layerIndex <= 1) ? bottomPattern : upperPattern;
100+
int rows = pattern.length; // 4
101+
int cols = pattern[0].length; //5
102+
103+
final int pivotCol = 2;
104+
final int pivotRow = 1;
105+
for (int rz = 0; rz < rows; rz++) {
106+
for (int cx = 0; cx < cols; cx++) {
107+
int val = pattern[rz][cx];
108+
if (val == 0) continue;
109+
110+
int localX = cx - pivotCol; // left/right
111+
int localZ = rz - pivotRow; // forward/back
112+
113+
int rotX = 0, rotZ = 0;
114+
String ladderFacing = "north";
115+
switch (front) {
116+
case "south" -> {
117+
rotX = localX;
118+
rotZ = localZ;
119+
ladderFacing = "south";
120+
}
121+
case "north" -> {
122+
rotX = -localX;
123+
rotZ = -localZ;
124+
ladderFacing = "north";
125+
}
126+
case "east" -> {
127+
rotX = localZ;
128+
rotZ = -localX;
129+
ladderFacing = "east";
130+
}
131+
case "west" -> {
132+
rotX = -localZ;
133+
rotZ = localX;
134+
ladderFacing = "west";
135+
}
136+
}
137+
138+
double worldX = basePos.x() + rotX;
139+
double worldZ = basePos.z() + rotZ;
140+
141+
Pos target = new Pos(worldX, basePos.y() + layerIndex - 1, worldZ);
142+
try {
143+
if (val == 1) {
144+
if (instance.getBlock(target).isAir()) {
145+
instance.setBlock(target, wool);
146+
}
147+
} else if (val == 5) {
148+
try {
149+
instance.setBlock(target, Block.LADDER.withProperty("facing", ladderFacing));
150+
} catch (IllegalArgumentException ignored) {
151+
instance.setBlock(target, Block.LADDER);
152+
}
153+
}
154+
} catch (IllegalArgumentException e) {
155+
if (val == 1) {
156+
instance.setBlock(target, Block.WHITE_WOOL);
157+
}
158+
} catch (Exception ignored) {
159+
}
160+
}
161+
}
162+
}, TaskSchedule.tick(RISE_TICK_INTERVAL), TaskSchedule.tick(RISE_TICK_INTERVAL));
163+
}
164+
165+
}

type.bedwarsgame/src/main/java/net/swofty/type/bedwarsgame/shop/ShopManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ShopManager {
3636
private final ShopItem PICKAXE = new PickaxeShopItem();
3737
private final ShopItem AXE = new AxeShopItem();
3838
private final ShopItem FIREBALL = new FireballShopItem();
39+
private final ShopItem POPUP_TOWER = new PopupTowerItem();
3940
private final ShopItem GOLDEN_APPLE = new GappleShopItem();
4041
private final ShopItem INVISIBILITY_POTION = new PotionShopItem("Invisibility Potion", "Makes you invisible for 30 seconds", 2, 1, Currency.EMERALD, PotionType.INVISIBILITY);
4142
private final ShopItem SPEED_POTION = new PotionShopItem("Speed Potion", "Makes you fast for 30 seconds", 2, 1, Currency.EMERALD, PotionType.SWIFTNESS);
@@ -66,6 +67,7 @@ public ShopManager() {
6667
addItemToCategories(DIAMOND_ARMOR, 3);
6768
addItemToCategories(ENDER_PEARL, 7);
6869
addItemToCategories(TNT, 7);
70+
addItemToCategories(POPUP_TOWER, 7);
6971
addItemToCategories(WATER_BUCKET, 7);
7072
addItemToCategories(GOLDEN_APPLE, 7);
7173
addItemToCategories(BRIDGE_EGG, 7);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.swofty.type.bedwarsgame.shop.impl;
2+
3+
import net.minestom.server.entity.Player;
4+
import net.minestom.server.item.Material;
5+
import net.swofty.type.bedwarsgame.TypeBedWarsGameLoader;
6+
import net.swofty.type.bedwarsgame.shop.Currency;
7+
import net.swofty.type.bedwarsgame.shop.ShopItem;
8+
9+
public class PopupTowerItem extends ShopItem {
10+
11+
public PopupTowerItem() {
12+
super("Pop-Up Tower", "An utility item", 24, 1, Currency.IRON, Material.CHEST);
13+
}
14+
15+
@Override
16+
public void onPurchase(Player player) {
17+
player.getInventory().addItemStack(TypeBedWarsGameLoader.getItemHandler().getItem("popup_tower").getItemStack());
18+
}
19+
20+
}

type.bedwarsgeneric/src/main/java/net/swofty/type/bedwarsgeneric/item/BedWarsItem.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import lombok.Getter;
44
import net.kyori.adventure.nbt.CompoundBinaryTag;
55
import net.minestom.server.component.DataComponents;
6+
import net.minestom.server.event.item.ItemDropEvent;
67
import net.minestom.server.event.item.PlayerFinishItemUseEvent;
8+
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
79
import net.minestom.server.event.player.PlayerUseItemEvent;
810
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
11+
import net.minestom.server.event.trait.PlayerInstanceEvent;
912
import net.minestom.server.item.ItemStack;
1013
import net.minestom.server.item.component.CustomData;
1114
import net.swofty.type.generic.user.HypixelPlayer;
@@ -40,4 +43,16 @@ public void onItemUse(PlayerUseItemEvent event) {
4043
// stub
4144
}
4245

46+
public void onItemDrop(ItemDropEvent event) {
47+
// stub
48+
}
49+
50+
public void onItemInteract(PlayerInstanceEvent event) {
51+
// stub
52+
}
53+
54+
public void onBlockPlace(PlayerBlockPlaceEvent event) {
55+
// stub
56+
}
57+
4358
}

type.bedwarsgeneric/src/main/java/net/swofty/type/bedwarsgeneric/item/BedWarsItemHandler.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package net.swofty.type.bedwarsgeneric.item;
22

33
import net.minestom.server.component.DataComponents;
4+
import net.minestom.server.event.item.ItemDropEvent;
45
import net.minestom.server.event.item.PlayerFinishItemUseEvent;
6+
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
57
import net.minestom.server.event.player.PlayerUseItemEvent;
68
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
79
import net.minestom.server.item.ItemStack;
10+
import net.minestom.server.item.component.CustomData;
811
import net.minestom.server.tag.Tag;
912

1013
import java.util.ArrayList;
@@ -37,6 +40,7 @@ public void onItemUseOnBlock(PlayerUseItemOnBlockEvent event) {
3740
ItemStack itemStack = event.getItemStack();
3841
if (isItem(item, itemStack)) {
3942
item.onItemUseOnBlock(event);
43+
item.onItemInteract(event);
4044
}
4145
}
4246
}
@@ -46,13 +50,34 @@ public void onItemUse(PlayerUseItemEvent event) {
4650
ItemStack itemStack = event.getItemStack();
4751
if (isItem(item, itemStack)) {
4852
item.onItemUse(event);
53+
item.onItemInteract(event);
54+
}
55+
}
56+
}
57+
58+
public void onItemDrop(ItemDropEvent event) {
59+
for (BedWarsItem item : items) {
60+
ItemStack itemStack = event.getItemStack();
61+
if (isItem(item, itemStack)) {
62+
item.onItemDrop(event);
63+
}
64+
}
65+
}
66+
67+
public void onBlockPlace(PlayerBlockPlaceEvent event) {
68+
for (BedWarsItem item : items) {
69+
ItemStack itemStack = event.getPlayer().getItemInMainHand();
70+
if (isItem(item, itemStack)) {
71+
item.onBlockPlace(event);
4972
}
5073
}
5174
}
5275

5376
private boolean isItem(BedWarsItem item, ItemStack itemStack) {
54-
String itemId = itemStack.get(DataComponents.CUSTOM_DATA).getTag(Tag.String("item"));
55-
return itemId != null && itemId.equalsIgnoreCase(item.getId());
77+
CustomData data = itemStack.get(DataComponents.CUSTOM_DATA);
78+
if (data == null) return false;
79+
String id = data.getTag(Tag.String("item"));
80+
return id != null && id.equalsIgnoreCase(item.getId());
5681
}
5782

5883
}

type.bedwarslobby/src/main/java/net/swofty/type/bedwarslobby/events/ActionCustomItems.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.swofty.type.bedwarslobby.events;
22

3+
import net.minestom.server.event.item.ItemDropEvent;
34
import net.minestom.server.event.item.PlayerFinishItemUseEvent;
45
import net.minestom.server.event.player.PlayerUseItemEvent;
56
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
@@ -25,4 +26,9 @@ public void run(PlayerUseItemEvent event) {
2526
TypeBedWarsLobbyLoader.getItemHandler().onItemUse(event);
2627
}
2728

29+
@HypixelEvent(node = EventNodes.ALL, requireDataLoaded = true)
30+
public void run(ItemDropEvent event) {
31+
TypeBedWarsLobbyLoader.getItemHandler().onItemDrop(event);
32+
}
33+
2834
}

type.bedwarslobby/src/main/java/net/swofty/type/bedwarslobby/item/impl/BedWarsMenu.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package net.swofty.type.bedwarslobby.item.impl;
22

3+
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.event.ClickEvent;
5+
import net.minestom.server.event.item.ItemDropEvent;
6+
import net.minestom.server.event.trait.CancellableEvent;
7+
import net.minestom.server.event.trait.PlayerInstanceEvent;
38
import net.minestom.server.item.ItemStack;
49
import net.minestom.server.item.Material;
510
import net.swofty.type.bedwarsgeneric.item.BedWarsItem;
@@ -16,4 +21,16 @@ public ItemStack getBlandItem() {
1621
return ItemStackCreator.createNamedItemStack(Material.EMERALD, "§aBed Wars Menu & Shop §7(Right Click)").build();
1722
}
1823

24+
@Override
25+
public void onItemDrop(ItemDropEvent event) {
26+
event.setCancelled(true);
27+
}
28+
29+
@Override
30+
public void onItemInteract(PlayerInstanceEvent event) {
31+
((CancellableEvent) event).setCancelled(true);
32+
event.getPlayer().sendMessage(Component.text("§cThis Feature is not there yet. §aOpen a Pull request HERE to get it added quickly!")
33+
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Swofty-Developments/HypixelSkyBlock")));
34+
}
35+
1936
}

0 commit comments

Comments
 (0)