Skip to content

Commit 339b4ed

Browse files
committed
non unit GUI
1 parent 3a1c125 commit 339b4ed

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

TODO.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ Controlling non-RoN mobs
2525
[🟡] Attack move (just make it a move action but don't cancel NearestAttackableTargetGoal)
2626
- Still only attacks whatever is naturally aggroed with these goals...
2727

28+
[❌] Render GUI for selecting multiple non-units
2829

2930
Bugfixes
3031
--------
3132
[🟡] Can no longer send resources to a non-RTS ally
32-
33+
[🟡] Misc language fixes and additions
3334

3435
Quality of Life
3536
---------------
3637
[🟡] Updated /rts-help list
37-
38+
[🟡] Huntable animals now show their food value next to their portrait
3839

3940

4041
Balancing

src/main/java/com/solegendary/reignofnether/hud/HudClientEvents.java

+19-17
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import com.solegendary.reignofnether.orthoview.OrthoviewClientEvents;
2424
import com.solegendary.reignofnether.player.PlayerClientEvents;
2525
import com.solegendary.reignofnether.research.ResearchClient;
26-
import com.solegendary.reignofnether.resources.ResourceName;
27-
import com.solegendary.reignofnether.resources.ResourceSources;
28-
import com.solegendary.reignofnether.resources.Resources;
29-
import com.solegendary.reignofnether.resources.ResourcesClientEvents;
26+
import com.solegendary.reignofnether.resources.*;
3027
import com.solegendary.reignofnether.sandbox.SandboxActionButtons;
3128
import com.solegendary.reignofnether.sandbox.SandboxClientEvents;
3229
import com.solegendary.reignofnether.sandbox.SandboxMenuType;
@@ -55,13 +52,15 @@
5552
import net.minecraft.client.model.Model;
5653
import net.minecraft.client.resources.language.I18n;
5754
import net.minecraft.core.BlockPos;
55+
import net.minecraft.network.chat.Component;
5856
import net.minecraft.network.chat.Style;
5957
import net.minecraft.resources.ResourceLocation;
6058
import net.minecraft.util.FormattedCharSequence;
6159
import net.minecraft.world.entity.Entity;
6260
import net.minecraft.world.entity.EquipmentSlot;
6361
import net.minecraft.world.entity.LivingEntity;
6462
import net.minecraft.world.entity.Mob;
63+
import net.minecraft.world.entity.animal.Animal;
6564
import net.minecraft.world.item.BannerItem;
6665
import net.minecraft.world.item.ItemStack;
6766
import net.minecraftforge.client.event.RenderLivingEvent;
@@ -76,6 +75,7 @@
7675
import static com.solegendary.reignofnether.hud.buttons.HelperButtons.*;
7776
import static com.solegendary.reignofnether.tutorial.TutorialClientEvents.helpButton;
7877
import static com.solegendary.reignofnether.unit.UnitClientEvents.*;
78+
import static com.solegendary.reignofnether.util.MiscUtil.capitaliseAndSpace;
7979
import static com.solegendary.reignofnether.util.MiscUtil.fcs;
8080

8181
public class HudClientEvents {
@@ -167,14 +167,17 @@ public static String getSimpleEntityName(Entity entity) {
167167
.replace(".none", "");
168168
}
169169
} else {
170-
return entity.getName().getString();
170+
return entity.getName().getString().toLowerCase();
171171
}
172172
}
173173

174174
// not to be used for resource paths
175175
public static String getModifiedEntityName(Entity entity) {
176176
String name = getSimpleEntityName(entity);
177177

178+
if (!(entity instanceof Unit))
179+
return name.toLowerCase();
180+
178181
ItemStack itemStack = ((LivingEntity) entity).getItemBySlot(EquipmentSlot.HEAD);
179182

180183
if (itemStack.getItem() instanceof BannerItem) {
@@ -619,12 +622,7 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
619622
int totalRes = Resources.getTotalResourcesFromItems(unit.getItems()).getTotalValue();
620623

621624
if (hudSelectedEntity instanceof Mob mob && mob.canPickUpLoot() && totalRes > 0) {
622-
hudZones.add(portraitRendererUnit.renderResourcesHeld(evt.getGuiGraphics(),
623-
nameCap,
624-
blitX,
625-
blitY,
626-
unit
627-
));
625+
hudZones.add(portraitRendererUnit.renderResourcesHeld(evt.getGuiGraphics(), blitX, blitY, unit));
628626

629627
// return button
630628
if (getPlayerToEntityRelationship(hudSelectedEntity) == Relationship.OWNED) {
@@ -645,7 +643,11 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
645643
renderedButtons.add(returnButton);
646644
}
647645
}
646+
} else if (ResourceSources.isHuntableAnimal(hudSelectedEntity)) {
647+
hudZones.add(portraitRendererUnit.renderResourcesHeld(evt.getGuiGraphics(), blitX, blitY, (Animal) hudSelectedEntity));
648+
blitX += portraitRendererUnit.statsWidth;
648649
}
650+
649651
if (hudSelectedEntity instanceof Unit unit
650652
&& Resources.getTotalResourcesFromItems(unit.getItems()).getTotalValue() > 0) {
651653
blitX += portraitRendererUnit.statsWidth + 5;
@@ -661,7 +663,7 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
661663
blitY = screenHeight - iconFrameSize * 2 - 10;
662664

663665
for (LivingEntity unit : selUnits) {
664-
if (getPlayerToEntityRelationship(unit) == Relationship.OWNED && unitButtons.size() < (buttonsPerRow * 2)) {
666+
if ((getPlayerToEntityRelationship(unit) == Relationship.OWNED || NonUnitClientEvents.canControlNonUnits()) && unitButtons.size() < (buttonsPerRow * 2)) {
665667
// mob head icon
666668
String unitName = getSimpleEntityName(unit);
667669
String buttonImagePath;
@@ -690,7 +692,7 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
690692
}
691693
},
692694
null,
693-
null
695+
List.of(fcs(capitaliseAndSpace(getModifiedEntityName(unit))))
694696
);
695697
if (unit.isVehicle()) {
696698
String passengerName = getSimpleEntityName(unit.getFirstPassenger());
@@ -739,17 +741,17 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
739741
for (int i = selUnits.size() - numExtraUnits; i < selUnits.size(); i++) {
740742

741743
LivingEntity unit = selUnits.get(i);
742-
LivingEntity nextUnit = null;
743-
String unitName = HudClientEvents.getSimpleEntityName(unit);
744+
LivingEntity nextUnit;
745+
String unitName = HudClientEvents.getModifiedEntityName(unit);
744746
String nextUnitName = null;
745747
numUnits += 1;
746748

747749
if (i < selUnits.size() - 1) {
748750
nextUnit = selUnits.get(i + 1);
749-
nextUnitName = HudClientEvents.getSimpleEntityName(nextUnit);
751+
nextUnitName = HudClientEvents.getModifiedEntityName(nextUnit);
750752
}
751753
if (!unitName.equals(nextUnitName)) {
752-
tooltipLines.add(FormattedCharSequence.forward("x" + numUnits + " " + I18n.get(unitName),
754+
tooltipLines.add(FormattedCharSequence.forward("x" + numUnits + " " + capitaliseAndSpace(unitName),
753755
Style.EMPTY
754756
));
755757
numUnits = 0;

src/main/java/com/solegendary/reignofnether/hud/PortraitRendererUnit.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import com.mojang.datafixers.util.Pair;
99
import com.mojang.math.Axis;
1010
import com.solegendary.reignofnether.ReignOfNether;
11+
import com.solegendary.reignofnether.resources.ResourceSource;
12+
import com.solegendary.reignofnether.resources.ResourceSources;
1113
import com.solegendary.reignofnether.unit.interfaces.HeroUnit;
1214
import net.minecraft.client.gui.GuiGraphics;
1315
import net.minecraft.client.resources.language.I18n;
16+
import net.minecraft.world.entity.animal.Animal;
1417
import org.joml.Quaternionf;
1518
import org.joml.Vector3f;
1619
import com.solegendary.reignofnether.ability.abilities.EnchantMaiming;
@@ -346,10 +349,23 @@ public RectZone renderHeroLevelAndExp(GuiGraphics guiGraphics, int x, int y, int
346349
return RectZone.getZoneByLW(x, y-2, width, height+4);
347350
}
348351

349-
public RectZone renderResourcesHeld(GuiGraphics guiGraphics, String name, int x, int y, Unit unit) {
350352

351-
int totalRes = Resources.getTotalResourcesFromItems(unit.getItems()).getTotalValue();
353+
public RectZone renderResourcesHeld(GuiGraphics guiGraphics, int x, int y, Unit unit) {
354+
Resources resources = Resources.getTotalResourcesFromItems(unit.getItems());
355+
return renderResourcesHeld(guiGraphics, x, y, resources, Unit.atMaxResources(unit));
356+
}
357+
358+
public RectZone renderResourcesHeld(GuiGraphics guiGraphics, int x, int y, Animal animal) {
359+
Resources resources = new Resources("",0,0,0);
360+
for (ItemStack itemStack : ResourceSources.getFoodItemsFromAnimal(animal)) {
361+
ResourceSource res = ResourceSources.getFromItem(itemStack.getItem());
362+
if (res != null)
363+
resources.food += res.resourceValue * itemStack.getCount();
364+
}
365+
return renderResourcesHeld(guiGraphics, x, y, resources, false);
366+
}
352367

368+
public RectZone renderResourcesHeld(GuiGraphics guiGraphics, int x, int y, Resources resources, boolean redText) {
353369
MyRenderer.renderFrameWithBg(guiGraphics, x, y, statsWidth, statsHeight, 0xA0000000);
354370

355371
int blitXIcon = x + 6;
@@ -362,7 +378,6 @@ public RectZone renderResourcesHeld(GuiGraphics guiGraphics, String name, int x,
362378
new ResourceLocation("reignofnether", "textures/icons/items/wood.png"),
363379
new ResourceLocation("reignofnether", "textures/icons/items/iron_ore.png")
364380
);
365-
Resources resources = Resources.getTotalResourcesFromItems(unit.getItems());
366381

367382
List<String> statStrings = List.of(String.valueOf(resources.food),
368383
String.valueOf(resources.wood),
@@ -379,18 +394,15 @@ public RectZone renderResourcesHeld(GuiGraphics guiGraphics, String name, int x,
379394
statStrings.get(i),
380395
blitXIcon + 12,
381396
blitYIcon,
382-
Unit.atMaxResources(unit) ? 0xFF2525 : 0xFFFFFF
397+
redText ? 0xFF2525 : 0xFFFFFF
383398
);
384399
blitYIcon += 10;
385400
}
386401
}
387-
388-
389402
return RectZone.getZoneByLW(x, y, statsWidth, statsHeight);
390403
}
391404

392405
private void drawEntityOnScreen(PoseStack poseStack, LivingEntity entity, int x, int y, int size) {
393-
394406
float f = (float) Math.atan(-lookX / 40F);
395407
float g = (float) Math.atan(-lookY / 40F);
396408
PoseStack poseStackModel = RenderSystem.getModelViewStack();

src/main/java/com/solegendary/reignofnether/util/MiscUtil.java

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.mojang.datafixers.util.Pair;
66
import net.minecraft.client.gui.GuiGraphics;
77
import net.minecraft.tags.BlockTags;
8+
import org.apache.commons.lang3.text.WordUtils;
89
import org.joml.Vector3d;
910
import com.solegendary.reignofnether.alliance.AlliancesClient;
1011
import com.solegendary.reignofnether.blocks.RTSStartBlock;
@@ -603,4 +604,11 @@ public static boolean isSolidBlocking(Level level, BlockPos bp) {
603604
BlockState bs = level.getBlockState(bp);
604605
return !bs.getCollisionShape(level, bp).isEmpty() && bs.isSolid();
605606
}
607+
608+
public static String capitaliseAndSpace(String str) {
609+
String spacedStr = str.replace('_', ' ');
610+
spacedStr = spacedStr.replace('-', ' ');
611+
spacedStr = spacedStr.replace('.', ' ');
612+
return WordUtils.capitalize(spacedStr);
613+
}
606614
}

0 commit comments

Comments
 (0)