diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 5c50688348..245e4a085f 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -92,6 +92,7 @@ client.attemwarn = [scarlet]Attem placed by {0}[scarlet] at ({1}, {2}) client.nojava = It seems that you don't have java installed, please click the button below then click the "latest LTS release" button on the website.\nClosing this dialog will close the game. client.installjava = Install Java client.autotransfer = Auto Transfer +client.preferredcore = Set preferred respawn core to {0} # CLaJ related client.claj.join = Join via CLaJ diff --git a/core/src/mindustry/entities/comp/PlayerComp.java b/core/src/mindustry/entities/comp/PlayerComp.java index 575b2c96c9..e0a7f8f6b3 100644 --- a/core/src/mindustry/entities/comp/PlayerComp.java +++ b/core/src/mindustry/entities/comp/PlayerComp.java @@ -80,7 +80,14 @@ public boolean isBuilder(){ /** @return largest/closest core, with largest cores getting priority */ @Nullable public CoreBuild bestCore(){ - return team.cores().min(Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y)))); + if(self() != Vars.player){ + return team.cores().min(Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y)))); + } else { + return team.cores().min(Structs.comps( + Structs.comparingBool(c -> (CoreBlock)c.block != ((CoreBlock)c.block).preferredCoreType), + Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y))) + )); + } } public TextureRegion icon(){ diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 8577a9e994..98d1be298b 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -646,7 +646,21 @@ else if (selectPlans.isEmpty()){ // SHIFT + Z to view lastSentPos, double tap to if(Core.input.keyTap(Binding.respawn) && !scene.hasDialog()){ controlledType = null; recentRespawnTimer = 1f; - Call.unitClear(player); + var u = player.unit(); + var closest = player.bestCore(); + if(CoreBlock.preferredCoreType == null || + (!u.spawnedByCore && + ((u.dockedType != null && u.dockedType.coreUnitDock) || + (closest != null && ((CoreBlock)closest.block).unitType != null && + ((CoreBlock)closest.block).unitType.coreUnitDock)) + ) + ){ + // Use original spawning mechanism for docking units + Call.unitClear(player); + } else { + // Send a packet that supports respawning at a specific block + Call.buildingControlSelect(player, closest); + } } } diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index 01dde64d1d..a40357b065 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -29,6 +29,8 @@ import static mindustry.Vars.*; import static mindustry.client.ClientVars.coreItemsDisplay; +import org.jetbrains.annotations.Nullable; + public class CoreBlock extends StorageBlock{ //hacky way to pass item modules between methods private static ItemModule nextItems; @@ -46,6 +48,8 @@ public class CoreBlock extends StorageBlock{ public float captureInvicibility = 60f * 15f; + public static @Nullable CoreBlock preferredCoreType = null; + public CoreBlock(String name){ super(name); @@ -654,13 +658,23 @@ public void handleItem(Building source, Item item){ if(team == player.team() && items.get(item) < storageCapacity) coreItemsDisplay.addItem(item, 1); } + @Override + public boolean onConfigureBuildTapped(Building other){ + deselect(); + return false; + } + @Override public void buildConfiguration(Table table){ - if(!state.isCampaign() || net.client()){ + // Client: Always have configuration to set preferred core + table.button(Icon.commandRally, Styles.clearTogglei, () -> { + preferredCoreType = preferredCoreType == this.block ? null : (CoreBlock)this.block; deselect(); - return; - } + }).size(40f) + .checked(b -> this.block == preferredCoreType) + .tooltip(Core.bundle.format("client.preferredcore", this.block.localizedName)); + if(state.isCampaign() && !net.client()){ table.button(Icon.downOpen, Styles.cleari, () -> { ui.planet.showSelect(state.rules.sector, other -> { if(state.isCampaign()){ @@ -669,6 +683,7 @@ public void buildConfiguration(Table table){ }); deselect(); }).size(40f); + } // Else deselect } } }