Skip to content

Commit 2ee76c8

Browse files
authored
Optimize interoperability with SuperbWarfare (#160)
1 parent b601ce9 commit 2ee76c8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

common/src/main/java/com/xtracr/realcamera/compat/CompatibilityHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.xtracr.realcamera.config.ConfigFile;
66
import com.xtracr.realcamera.mixin.accessor.CameraAccessor;
77
import net.minecraft.client.Camera;
8+
import net.minecraft.world.entity.player.Player;
89

910
import java.lang.reflect.Field;
1011
import java.lang.reflect.Method;
@@ -16,6 +17,7 @@ public class CompatibilityHelper {
1617
private static Field NEA_NEAnimationsLoader_playerTransformer;
1718
private static Class<?> SW_ClientEventHandler;
1819
private static Field SW_ClientEventHandler_zoomTime;
20+
private static Class<?> SBW_VehicleEntity;
1921

2022
public static void initialize(PlatformHelper platformHelper) {
2123
CompatibilityHelper.platformHelper = platformHelper;
@@ -46,7 +48,9 @@ public static void initialize(PlatformHelper platformHelper) {
4648
if(isModLoaded("superbwarfare")) try{
4749
SW_ClientEventHandler = Class.forName("com.atsuishio.superbwarfare.event.ClientEventHandler");
4850
SW_ClientEventHandler_zoomTime = SW_ClientEventHandler.getDeclaredField("zoomTime");
51+
SBW_VehicleEntity = Class.forName("com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity");
4952
DisableHelper.MAIN_FEATURE.registerOrInBinding(player -> CompatibilityHelper.SW_gunsIsZooming());
53+
DisableHelper.MAIN_FEATURE.registerOrInBinding(CompatibilityHelper::SBW_isDrivingVehicle);
5054
} catch (Exception e) {
5155
RealCamera.LOGGER.warn("SuperbWarfare is not loaded correctly: [{}] {}", e.getClass().getName(), e.getMessage());
5256
}
@@ -62,6 +66,16 @@ private static boolean SW_gunsIsZooming(){
6266
}
6367
}
6468

69+
private static boolean SBW_isDrivingVehicle(Player player) {
70+
try{
71+
if (SBW_VehicleEntity.isAssignableFrom(player.getVehicle().getClass())) return true;
72+
return false;
73+
} catch (Exception e) {
74+
RealCamera.LOGGER.error("Failed to access SuperbWarfare's isAssignableFrom method", e);
75+
return false;
76+
}
77+
}
78+
6579
public static void NEA_setDeltaTick(float deltaTick) {
6680
if (NEA_playerTransformer_setDeltaTick != null) try {
6781
Object INSTANCE = NEA_NEAnimationsLoader_INSTANCE.get(null);

0 commit comments

Comments
 (0)