Skip to content

Commit 69a101b

Browse files
committed
non unit GUI
1 parent 339b4ed commit 69a101b

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

TODO.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ HEROES (in order of priority)
2222
Controlling non-RoN mobs
2323
------------------------
2424

25-
[🟡] Attack move (just make it a move action but don't cancel NearestAttackableTargetGoal)
26-
- Still only attacks whatever is naturally aggroed with these goals...
27-
28-
[❌] Render GUI for selecting multiple non-units
25+
[✔] All vanilla and modded mobs now have basic movement and attack controls
26+
- Enabled in Sandbox or by using the cheatcode 'wouldyoukindly'
27+
- Attack-move only works against mobs that the controlled mob is naturally aggressive to
28+
- Disclaimer: sometimes the inherent AI of mobs interferes with what you commanded
29+
- For example, iron golems constantly try to go back to the nearest village
2930

3031
Bugfixes
3132
--------

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void render(GuiGraphics guiGraphics, int x, int y, int mouseX, int mouseY
191191
String hotkeyStr = hotkey.buttonLabel;
192192
hotkeyStr = hotkeyStr.substring(0,Math.min(3, hotkeyStr.length()));
193193
guiGraphics.pose().translate(0,0,1);
194-
guiGraphics.drawCenteredString( MC.font,
194+
guiGraphics.drawCenteredString(MC.font,
195195
hotkeyStr,
196196
x + iconSize + 8 - (hotkeyStr.length() * 4),
197197
y + iconSize - 1,

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

+24-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import com.solegendary.reignofnether.minimap.MinimapClientEvents;
2323
import com.solegendary.reignofnether.orthoview.OrthoviewClientEvents;
2424
import com.solegendary.reignofnether.player.PlayerClientEvents;
25-
import com.solegendary.reignofnether.research.ResearchClient;
26-
import com.solegendary.reignofnether.resources.*;
25+
import com.solegendary.reignofnether.resources.ResourceName;
26+
import com.solegendary.reignofnether.resources.ResourceSources;
27+
import com.solegendary.reignofnether.resources.Resources;
28+
import com.solegendary.reignofnether.resources.ResourcesClientEvents;
2729
import com.solegendary.reignofnether.sandbox.SandboxActionButtons;
2830
import com.solegendary.reignofnether.sandbox.SandboxClientEvents;
2931
import com.solegendary.reignofnether.sandbox.SandboxMenuType;
@@ -48,11 +50,11 @@
4850
import com.solegendary.reignofnether.util.MiscUtil;
4951
import com.solegendary.reignofnether.util.MyRenderer;
5052
import net.minecraft.client.Minecraft;
53+
import net.minecraft.client.gui.GuiGraphics;
5154
import net.minecraft.client.gui.screens.ChatScreen;
5255
import net.minecraft.client.model.Model;
5356
import net.minecraft.client.resources.language.I18n;
5457
import net.minecraft.core.BlockPos;
55-
import net.minecraft.network.chat.Component;
5658
import net.minecraft.network.chat.Style;
5759
import net.minecraft.resources.ResourceLocation;
5860
import net.minecraft.util.FormattedCharSequence;
@@ -172,13 +174,16 @@ public static String getSimpleEntityName(Entity entity) {
172174
}
173175

174176
// not to be used for resource paths
175-
public static String getModifiedEntityName(Entity entity) {
177+
public static String getModifiedEntityName(LivingEntity entity) {
176178
String name = getSimpleEntityName(entity);
177179

180+
if (entity.isBaby())
181+
name = I18n.get("units.neutral.reignofnether.baby") + " " + name;
182+
178183
if (!(entity instanceof Unit))
179184
return name.toLowerCase();
180185

181-
ItemStack itemStack = ((LivingEntity) entity).getItemBySlot(EquipmentSlot.HEAD);
186+
ItemStack itemStack = entity.getItemBySlot(EquipmentSlot.HEAD);
182187

183188
if (itemStack.getItem() instanceof BannerItem) {
184189
name += " " + I18n.get("units.villagers.reignofnether.captain");
@@ -676,7 +681,7 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
676681

677682
Button button = new Button(unitName,
678683
iconSize,
679-
new ResourceLocation(ReignOfNether.MOD_ID, buttonImagePath),
684+
unit instanceof Unit ? new ResourceLocation(ReignOfNether.MOD_ID, buttonImagePath) : null,
680685
unit,
681686
() -> hudSelectedEntity == null || getModifiedEntityName(hudSelectedEntity).equals(
682687
getModifiedEntityName(unit)),
@@ -694,7 +699,7 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
694699
null,
695700
List.of(fcs(capitaliseAndSpace(getModifiedEntityName(unit))))
696701
);
697-
if (unit.isVehicle()) {
702+
if (unit.isVehicle() && unit instanceof Unit) {
698703
String passengerName = getSimpleEntityName(unit.getFirstPassenger());
699704
button.bgIconResource = new ResourceLocation(ReignOfNether.MOD_ID,
700705
"textures/mobheads/" + passengerName + ".png"
@@ -763,6 +768,18 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
763768
} else {
764769
unitButton.render(evt.getGuiGraphics(), blitX, blitY, mouseX, mouseY);
765770
renderedButtons.add(unitButton);
771+
if (unitButton.iconResource == null) {
772+
String str = unitButton.name.substring(0,1).toUpperCase();
773+
if (unitButton.name.length() > 1) {
774+
str += unitButton.name.substring(1, 2);
775+
}
776+
evt.getGuiGraphics().drawCenteredString(MC.font,
777+
fcs(str, true),
778+
blitX + (unitButton.iconSize / 2) + 4,
779+
blitY + (unitButton.iconSize / 2),
780+
0xFFFFFF
781+
);
782+
}
766783
unitButton.renderHealthBar(evt.getGuiGraphics().pose());
767784
blitX += iconFrameSize;
768785
if (buttonsRendered == buttonsPerRow - 1) {

src/main/java/com/solegendary/reignofnether/unit/UnitActionItem.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.solegendary.reignofnether.unit.interfaces.ConvertableUnit;
1717
import com.solegendary.reignofnether.unit.interfaces.Unit;
1818
import com.solegendary.reignofnether.unit.interfaces.WorkerUnit;
19+
import com.solegendary.reignofnether.unit.units.villagers.IronGolemUnit;
1920
import com.solegendary.reignofnether.util.MiscUtil;
2021
import net.minecraft.client.resources.language.I18n;
2122
import net.minecraft.core.BlockPos;
@@ -394,15 +395,18 @@ public void action(Level level) {
394395

395396
mob.getNavigation().stop();
396397
mob.setTarget(null);
398+
if (!level.isClientSide()) {
399+
synchronized (NonUnitServerEvents.nonUnitMoveTargets) {
400+
NonUnitServerEvents.nonUnitMoveTargets.removeIf(p -> p.getFirst() == mob);
401+
}
402+
}
397403

398404
if (List.of(UnitAction.MOVE, UnitAction.FOLLOW, UnitAction.ATTACK_MOVE).contains(action)) {
399-
mob.getNavigation().stop();
400405
BlockPos bp = preselectedBlockPos;
401406
Path path = mob.getNavigation().createPath(bp.getX(), bp.getY(), bp.getZ(), 0);
402407
mob.getNavigation().moveTo(path, 1);
403408
if (!level.isClientSide()) {
404409
synchronized (NonUnitServerEvents.nonUnitMoveTargets) {
405-
NonUnitServerEvents.nonUnitMoveTargets.removeIf(p -> p.getFirst() == mob);
406410
NonUnitServerEvents.nonUnitMoveTargets.add(new Pair<>(mob, preselectedBlockPos));
407411
}
408412
}
@@ -414,10 +418,10 @@ public void action(Level level) {
414418
if (!level.isClientSide()) {
415419
if (action != UnitAction.ATTACK_MOVE) {
416420
NonUnitServerEvents.attackSuppressedNonUnits.add(mob);
417-
} else {
418-
NonUnitClientEvents.isMoveCheckpointGreen = false;
419421
}
420422
NonUnitServerEvents.moveSuppressedNonUnits.add(mob);
423+
} else {
424+
NonUnitClientEvents.isMoveCheckpointGreen = action != UnitAction.ATTACK_MOVE;
421425
}
422426
}
423427
}

src/main/java/com/solegendary/reignofnether/unit/UnitClientEvents.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ else if (preselectedUnits.size() == 1 && !isLeftClickAttack()) {
595595
deselected = selectedUnits.removeIf(id -> id.equals(preselectedUnits.get(0)));
596596

597597
if (Keybindings.shiftMod.isDown() && !deselected &&
598-
preselectedUnits.get(0) instanceof Unit &&
599-
getPlayerToEntityRelationship(preselectedUnits.get(0)) == Relationship.OWNED) {
598+
((preselectedUnits.get(0) instanceof Unit && getPlayerToEntityRelationship(preselectedUnits.get(0)) == Relationship.OWNED) ||
599+
(NonUnitClientEvents.canControlNonUnits()))) {
600600
addSelectedUnit(preselectedUnits.get(0));
601601
}
602602
else if (!deselected) { // select a single unit - this should be the only code path that allows you to select a non-owned unit
@@ -641,6 +641,7 @@ else if (preSelBuilding instanceof GarrisonableBuilding garr &&
641641
// right click -> attack unfriendly unit
642642
else if (preselectedUnits.size() == 1 &&
643643
!targetingSelf() &&
644+
(hudSelectedEntity instanceof Unit || NonUnitClientEvents.canAttack(hudSelectedEntity)) &&
644645
((GameruleClient.neutralAggro && getPlayerToEntityRelationship(preselectedUnits.get(0)) == Relationship.NEUTRAL) ||
645646
getPlayerToEntityRelationship(preselectedUnits.get(0)) == Relationship.HOSTILE ||
646647
ResourceSources.isHuntableAnimal(preselectedUnits.get(0)))) {

src/main/resources/assets/reignofnether/lang/en_us.json

+1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@
938938
"units.monsters.reignofnether.spider_jockey": "Spider Jockey",
939939
"units.monsters.reignofnether.poison_spider_jockey": "Poison Spider Jockey",
940940
"units.piglins.reignofnether.hoglin_rider": "Hoglin Rider",
941+
"units.neutral.reignofnether.baby": "Baby",
941942

942943
"units.reignofnether.farmer": "Farmer",
943944
"units.reignofnether.lumberjack": "Lumberjack",

0 commit comments

Comments
 (0)