-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pawns selection to build mode, disalbed the ability to build for now
- Loading branch information
Showing
30 changed files
with
394 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
|
||
public enum FortressState { | ||
|
||
BUILD, | ||
BUILD_SELECTION, | ||
BUILD_EDITING, | ||
COMBAT, | ||
AREAS_SELECTION, | ||
|
||
|
8 changes: 8 additions & 0 deletions
8
src/core/java/net/remmintan/mods/minefortress/core/PawnsSelectionState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.remmintan.mods.minefortress.core; | ||
|
||
public enum PawnsSelectionState { | ||
|
||
SELECTING, | ||
BUILDING, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ava/net/remmintan/mods/minefortress/core/interfaces/client/ISelectedColonistProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.remmintan.mods.minefortress.core.interfaces.client; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
|
||
public interface ISelectedColonistProvider { | ||
|
||
boolean isSelectingColonist(); | ||
|
||
LivingEntity getSelectedPawn(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 4 additions & 10 deletions
14
.../combat/IClientFightSelectionManager.java → .../combat/IClientPawnsSelectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ava/net/remmintan/mods/minefortress/core/interfaces/combat/ITargetedSelectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.remmintan.mods.minefortress.core.interfaces.combat; | ||
|
||
import net.remmintan.mods.minefortress.core.interfaces.entities.pawns.ITargetedPawn; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public interface ITargetedSelectionManager { | ||
|
||
void forEachTargetedPawn(Consumer<ITargetedPawn> action); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/core/java/net/remmintan/mods/minefortress/core/utils/GlobalProjectionCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.remmintan.mods.minefortress.core.utils; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class GlobalProjectionCache { | ||
|
||
public static final int UPDATE_DELAY = 100; | ||
private static double cachedMouseX = Double.MIN_VALUE; | ||
private static double cachedMouseY = Double.MIN_VALUE; | ||
// head rotation and player position | ||
private static float cachedPlayerXRot = Float.MIN_VALUE; | ||
private static float cachedPlayerYRot = Float.MIN_VALUE; | ||
private static Vec3d cachedPlayerPos = Vec3d.ZERO; | ||
|
||
// time | ||
private static Map<String, Long> lastUpdateTimes = new ConcurrentHashMap<>(); | ||
|
||
public static boolean shouldUpdateValues(String timeKey) { | ||
final var minecraft = MinecraftClient.getInstance(); | ||
if(minecraft == null) return false; | ||
|
||
final var mouseX = minecraft.mouse.getX(); | ||
final var mouseY = minecraft.mouse.getY(); | ||
|
||
final var player = minecraft.player; | ||
if(player == null) return false; | ||
|
||
final var playerXRot = player.getPitch(); | ||
final var playerYRot = player.getYaw(); | ||
final var playerPos = player.getPos(); | ||
if(playerPos == null) return false; | ||
|
||
if(mouseX != cachedMouseX || | ||
mouseY != cachedMouseY || | ||
playerXRot != cachedPlayerXRot || | ||
playerYRot != cachedPlayerYRot || | ||
!playerPos.equals(cachedPlayerPos) || | ||
System.currentTimeMillis() - lastUpdateTimes.computeIfAbsent(timeKey, it -> 0L) > UPDATE_DELAY | ||
) { | ||
cachedMouseX = mouseX; | ||
cachedMouseY = mouseY; | ||
cachedPlayerXRot = playerXRot; | ||
cachedPlayerYRot = playerYRot; | ||
cachedPlayerPos = new Vec3d(playerPos.x, playerPos.y, playerPos.z); | ||
lastUpdateTimes.put(timeKey, System.currentTimeMillis()); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.minefortress.controls; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.remmintan.mods.minefortress.core.FortressState; | ||
import net.remmintan.mods.minefortress.core.utils.CoreModUtils; | ||
import org.minefortress.utils.ModUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MouseEvents { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MouseEvents.class); | ||
|
||
private static boolean mousePressedInpreviousTick = false; | ||
|
||
public static void checkMouseStateAndFireEvents() { | ||
final var mouse = MinecraftClient.getInstance().mouse; | ||
final var isMousePressed = mouse.wasLeftButtonClicked(); | ||
// mouse x and y coordinates | ||
final var mouseX = mouse.getX(); | ||
final var mouseY = mouse.getY(); | ||
if(isMousePressed) { | ||
if(!mousePressedInpreviousTick) { | ||
firePressEvent(mouseX, mouseY); | ||
} | ||
} else { | ||
if(mousePressedInpreviousTick) { | ||
fireReleaseEvent(mouseX, mouseY); | ||
} | ||
} | ||
mousePressedInpreviousTick = isMousePressed; | ||
} | ||
|
||
private static void firePressEvent(double mouseX, double mouseY) { | ||
final var fortressManager = ModUtils.getFortressClientManager(); | ||
final var state = fortressManager.getState(); | ||
final var correctState = state == FortressState.COMBAT || state == FortressState.BUILD_SELECTION; | ||
|
||
if(correctState) { | ||
final var provider = CoreModUtils.getMineFortressManagersProvider(); | ||
final var pawnsSelection = provider.get_PawnsSelectionManager(); | ||
pawnsSelection.startSelection(mouseX, mouseY); | ||
} | ||
} | ||
|
||
private static void fireReleaseEvent(double mouseX, double mouseY) { | ||
final var provider = CoreModUtils.getMineFortressManagersProvider(); | ||
final var pawnsSelection = provider.get_PawnsSelectionManager(); | ||
pawnsSelection.endSelection(mouseX, mouseY); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.