Skip to content

Commit 5999264

Browse files
committed
feat: add Totem of Corruption to Deployable Display
1 parent bb7c570 commit 5999264

File tree

4 files changed

+103
-43
lines changed

4 files changed

+103
-43
lines changed

src/main/java/com/fix3dll/skyblockaddons/features/deployable/Deployable.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public enum Deployable {
2121
SOS_FLARE(1.25, 30, 25, 10, 5, "c0062cc98ebda72a6a4b89783adcef2815b483a01d73ea87b3df76072a89d13b", 40*40, "sos"),
2222

2323
// Umberella
24-
UMBERELLA("Umberella ", 5, 30*30, "umberella");
24+
UMBERELLA("Umberella ", 5, 30*30, "umberella"),
25+
26+
// Totem of Corruption
27+
TOTEM_OF_CORRUPTION("Totem of Corruption", 30*30, "totem_of_corruption");
2528

2629
/**
2730
* Start of the display name of the actual floating deployable entity.
@@ -79,32 +82,41 @@ public enum Deployable {
7982

8083
// Orbs
8184
Deployable(String display, double healthRegen, double manaRegen, int strength, double vitality, double mending, int rangeSquared, String resourcePath) {
85+
this(rangeSquared, resourcePath);
8286
this.display = display;
8387
this.healthRegen = healthRegen;
8488
this.manaRegen = manaRegen;
8589
this.strength = strength;
8690
this.vitality = vitality;
8791
this.mending = mending;
88-
this.rangeSquared = rangeSquared;
89-
this.resourceLocation = SkyblockAddons.resourceLocation("deployables/"+resourcePath+".png");
9092
}
9193

9294
// Flares
9395
Deployable(double manaRegen, double vitality, int trueDefense, int ferocity, int bonusAttackSpeed, String textureId, int rangeSquared, String resourcePath) {
96+
this(rangeSquared, resourcePath);
9497
this.manaRegen = manaRegen;
9598
this.vitality = vitality;
9699
this.trueDefense = trueDefense;
97100
this.ferocity = ferocity;
98101
this.bonusAttackSpeed = bonusAttackSpeed;
99-
this.rangeSquared = rangeSquared;
100-
this.resourceLocation = SkyblockAddons.resourceLocation("deployables/"+resourcePath+".png");
101102
this.textureId = textureId;
102103
}
103104

104105
// Umberella
105106
Deployable(String display, int trophyFishChance, int rangeSquared, String resourcePath) {
107+
this(rangeSquared, resourcePath);
106108
this.display = display;
107109
this.trophyFishChance = trophyFishChance;
110+
}
111+
112+
// Totem of Corruption
113+
Deployable(String display, int rangeSquared, String resourcePath) {
114+
this(rangeSquared, resourcePath);
115+
this.display = display;
116+
}
117+
118+
// Base
119+
Deployable(int rangeSquared, String resourcePath) {
108120
this.rangeSquared = rangeSquared;
109121
this.resourceLocation = SkyblockAddons.resourceLocation("deployables/"+resourcePath+".png");
110122
}

src/main/java/com/fix3dll/skyblockaddons/features/deployable/DeployableManager.java

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.AllArgsConstructor;
66
import lombok.Getter;
77
import net.minecraft.client.Minecraft;
8+
import net.minecraft.network.chat.Component;
89
import net.minecraft.world.entity.EntityType;
910
import net.minecraft.world.entity.EquipmentSlot;
1011
import net.minecraft.world.entity.decoration.ArmorStand;
@@ -28,7 +29,9 @@ public class DeployableManager {
2829

2930
/** The DeployableManager instance. */
3031
@Getter private static final DeployableManager instance = new DeployableManager();
32+
private static final Minecraft MC = Minecraft.getInstance();
3133
private static final Pattern POWER_ORB_PATTERN = Pattern.compile("[A-Za-z ]* (?<seconds>[0-9]*)s");
34+
private static final Pattern TOTEM_PATTERN = Pattern.compile("Remaining: (?:(?<minutes>\\d{1,2})m )?(?<seconds>\\d{1,2})s");
3235

3336
/** Entry displaying {@link Deployable#SOS_FLARE} at 90 seconds for the edit screen */
3437
public static ArmorStand DUMMY_ARMOR_STAND;
@@ -37,7 +40,7 @@ public class DeployableManager {
3740
private final Map<Deployable, DeployableEntry> deployableEntryMap = new HashMap<>();
3841

3942
static {
40-
DUMMY_ARMOR_STAND = new ArmorStand(EntityType.ARMOR_STAND, Minecraft.getInstance().level);
43+
DUMMY_ARMOR_STAND = new ArmorStand(EntityType.ARMOR_STAND, MC.level);
4144
DUMMY_ARMOR_STAND.setItemSlot(EquipmentSlot.HEAD, ItemUtils.getTexturedHead("SOS_FLARE"));
4245
DUMMY_ARMOR_STAND.setInvisible(true);
4346
DUMMY_DEPLOYABLE_ENTRY = new DeployableEntry(Deployable.SOS_FLARE, 90, DUMMY_ARMOR_STAND.getUUID());
@@ -70,48 +73,65 @@ public DeployableEntry getActiveDeployable() {
7073
* @param entityArmorStand The entity to detect whether it is a deployable or not.
7174
*/
7275
public void detectDeployables(ArmorStand entityArmorStand) {
73-
if (entityArmorStand.getCustomName() != null) {
74-
Minecraft mc = Minecraft.getInstance();
75-
76-
String customNameTag;
77-
if (entityArmorStand.getCustomName() != null) {
78-
customNameTag = entityArmorStand.getCustomName().getString();
79-
} else {
80-
return;
81-
}
82-
83-
Deployable orb = Deployable.getByDisplayName(customNameTag);
84-
85-
if (orb != null && orb.isInRadius(entityArmorStand.distanceToSqr(mc.player))) {
86-
Matcher matcher = POWER_ORB_PATTERN.matcher(customNameTag);
76+
Component customName = entityArmorStand.getCustomName();
8777

88-
if (matcher.matches()) {
89-
int seconds;
90-
try {
91-
// Apparently they don't have a second count for moment after spawning, that's what this try-catch is for
92-
seconds = Integer.parseInt(matcher.group("seconds"));
93-
} catch (NumberFormatException ex) {
94-
// It's okay, just don't add the deployable I guess...
95-
return;
96-
}
78+
if (customName != null) {
79+
String customNameString = customName.getString();
80+
Deployable orb = Deployable.getByDisplayName(customNameString);
9781

98-
if (mc.level == null) return;
99-
List<ArmorStand> surroundingArmorStands = mc.level.getEntitiesOfClass(
82+
if (orb != null && orb.isInRadius(entityArmorStand.distanceToSqr(MC.player))) {
83+
if (orb == Deployable.TOTEM_OF_CORRUPTION) {
84+
List<ArmorStand> surroundingArmorStands = MC.level.getEntitiesOfClass(
10085
ArmorStand.class,
10186
new AABB(
10287
entityArmorStand.getX() - 0.1,
10388
entityArmorStand.getY() - 1,
10489
entityArmorStand.getZ() - 0.1,
10590
entityArmorStand.getX() + 0.1,
106-
entityArmorStand.getY() + 1,
91+
entityArmorStand.getY(),
10792
entityArmorStand.getZ() + 0.1
108-
),
109-
armorStandEntity -> armorStandEntity.getItemBySlot(EquipmentSlot.HEAD) != ItemStack.EMPTY
93+
)
11094
);
111-
if (!surroundingArmorStands.isEmpty()) {
112-
ArmorStand orbArmorStand = surroundingArmorStands.getFirst();
113-
114-
put(orb, seconds, orbArmorStand == null ? null : orbArmorStand.getUUID());
95+
for (ArmorStand entry : surroundingArmorStands) {
96+
Component entryCustomName = entry.getCustomName();
97+
if (entryCustomName == null) continue;
98+
99+
Matcher matcher = TOTEM_PATTERN.matcher(entryCustomName.getString());
100+
if (matcher.matches()) {
101+
put(orb, getSeconds(matcher), entry.getUUID());
102+
break;
103+
}
104+
}
105+
} else {
106+
Matcher matcher = POWER_ORB_PATTERN.matcher(customNameString);
107+
108+
if (matcher.matches()) {
109+
int seconds;
110+
try {
111+
// Apparently they don't have a second count for moment after spawning, that's what this try-catch is for
112+
seconds = Integer.parseInt(matcher.group("seconds"));
113+
} catch (NumberFormatException ex) {
114+
// It's okay, just don't add the deployable I guess...
115+
return;
116+
}
117+
118+
List<ArmorStand> surroundingArmorStands = MC.level.getEntitiesOfClass(
119+
ArmorStand.class,
120+
new AABB(
121+
entityArmorStand.getX() - 0.1,
122+
entityArmorStand.getY() - 1,
123+
entityArmorStand.getZ() - 0.1,
124+
entityArmorStand.getX() + 0.1,
125+
entityArmorStand.getY() + 1,
126+
entityArmorStand.getZ() + 0.1
127+
),
128+
armorStandEntity -> armorStandEntity.getItemBySlot(EquipmentSlot.HEAD) != ItemStack.EMPTY
129+
);
130+
if (!surroundingArmorStands.isEmpty()) {
131+
ArmorStand orbArmorStand = surroundingArmorStands.getFirst();
132+
133+
put(orb, seconds, orbArmorStand == null ? null : orbArmorStand.getUUID());
134+
}
115135
}
116136
}
117137
}
@@ -128,7 +148,7 @@ public void detectDeployables(ArmorStand entityArmorStand) {
128148
if (decodedTextureUrl == null) return;
129149

130150
Deployable flare = Deployable.getByTextureId(decodedTextureUrl);
131-
if (flare != null && flare.isInRadius(entityArmorStand.distanceToSqr(Minecraft.getInstance().player))) {
151+
if (flare != null && flare.isInRadius(entityArmorStand.distanceToSqr(MC.player))) {
132152
// Default exist time of flares
133153
int seconds = 180;
134154
// 1 tick = 50ms
@@ -140,6 +160,21 @@ public void detectDeployables(ArmorStand entityArmorStand) {
140160
}
141161
}
142162

163+
private static int getSeconds(Matcher matcher) {
164+
String secondsStr = matcher.group("seconds");
165+
int seconds = 0;
166+
if (secondsStr != null && !secondsStr.isEmpty()) {
167+
seconds = Integer.parseInt(secondsStr);
168+
}
169+
170+
String minutesStr = matcher.group("minutes");
171+
if (minutesStr != null && !minutesStr.isEmpty()) {
172+
seconds += Integer.parseInt(minutesStr) * 60;
173+
}
174+
175+
return seconds;
176+
}
177+
143178
@Getter @AllArgsConstructor
144179
public static class DeployableEntry {
145180
/** The Deployable type. */

src/main/java/com/fix3dll/skyblockaddons/listeners/RenderListener.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ private void drawCompactDeployableStatus(GuiGraphics graphics, float scale, Butt
24412441
entity = DeployableManager.DUMMY_ARMOR_STAND;
24422442
}
24432443

2444-
if (entity instanceof ArmorStand armorStand) {
2444+
if (entity instanceof ArmorStand armorStand && !isUnarmored(armorStand)) {
24452445
drawDeployableArmorStand(graphics, armorStand, x, y, scale);
24462446
} else {
24472447
graphics.blit(RenderPipelines.GUI_TEXTURED, deployable.getResourceLocation(), (int) x, (int) y, 0, 0, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE);
@@ -2540,8 +2540,8 @@ private void drawDetailedDeployableStatus(GuiGraphics graphics, float scale, But
25402540
int iconAndSecondsHeight = DEPLOYABLE_GUI_SIZE + MC.font.lineHeight;
25412541

25422542
int effectsHeight = (MC.font.lineHeight + spacingBetweenLines) * display.size();
2543-
int width = DEPLOYABLE_GUI_SIZE + 2 + longestLine.map(MC.font::width).orElseGet(() ->
2544-
MC.font.width(display.getFirst())
2543+
int width = DEPLOYABLE_GUI_SIZE + 2 + longestLine.map(MC.font::width).orElseGet(
2544+
() -> display.isEmpty() ? 0 : MC.font.width(display.getFirst())
25452545
);
25462546
int height = Math.max(effectsHeight, iconAndSecondsHeight);
25472547

@@ -2571,7 +2571,7 @@ private void drawDetailedDeployableStatus(GuiGraphics graphics, float scale, But
25712571
entity = DeployableManager.DUMMY_ARMOR_STAND;
25722572
}
25732573

2574-
if (entity instanceof ArmorStand armorStand) {
2574+
if (entity instanceof ArmorStand armorStand && !isUnarmored(armorStand)) {
25752575
drawDeployableArmorStand(graphics, armorStand, x, y, scale);
25762576
} else {
25772577
graphics.blit(RenderPipelines.GUI_TEXTURED, deployable.getResourceLocation(), (int) x, (int) y, 0, 0, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE, DEPLOYABLE_GUI_SIZE);
@@ -2598,6 +2598,19 @@ private void drawDetailedDeployableStatus(GuiGraphics graphics, float scale, But
25982598
}
25992599
}
26002600

2601+
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
2602+
private boolean isUnarmored(LivingEntity livingEntity) {
2603+
for (EquipmentSlot slot : EquipmentSlot.values()) {
2604+
if (!slot.isArmor()) continue;
2605+
ItemStack slotItem = livingEntity.getItemBySlot(slot);
2606+
2607+
if (slotItem != ItemStack.EMPTY) {
2608+
return false;
2609+
}
2610+
}
2611+
return true;
2612+
}
2613+
26012614
public void setGui() {
26022615
if (this.guiToOpen == GUIType.MAIN) {
26032616
MC.setScreen(new SkyblockAddonsGui(this.guiPageToOpen, this.guiTabToOpen));
11.1 KB
Loading

0 commit comments

Comments
 (0)