Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/src/main/java/com/xtracr/realcamera/KeyMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public final class KeyMappings {
});
createKeyMapping("toggleAdjustMode", client -> ConfigFile.config().cycleAdjustMode());
createKeyMapping("toggleCameraMode", client -> ConfigFile.config().setClassic(!ConfigFile.config().isClassic()));
createKeyMapping("adjustFRONT", client -> ConfigFile.config().adjustOffsetX(1));
createKeyMapping("adjustBACK", client -> ConfigFile.config().adjustOffsetX(-1));
createKeyMapping("adjustUP", client -> ConfigFile.config().adjustOffsetY(1));
createKeyMapping("adjustDOWN", client -> ConfigFile.config().adjustOffsetY(-1));
createKeyMapping("adjustLEFT", client -> ConfigFile.config().adjustOffsetZ(1));
createKeyMapping("adjustRIGHT", client -> ConfigFile.config().adjustOffsetZ(-1));
createKeyMapping("adjustFRONT", client -> ConfigFile.config().adjustOffsetX(1));
createKeyMapping("adjustBACK", client -> ConfigFile.config().adjustOffsetX(-1));
createKeyMapping("activeConfigIndexNEXT", client -> ConfigFile.config().binding.activeConfigIndex += 1);
createKeyMapping("activeConfigIndexPREV", client -> ConfigFile.config().binding.activeConfigIndex -= 1);
createKeyMapping("activeConfigIndexRESET", client -> ConfigFile.config().binding.activeConfigIndex = 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.Function;

public class CompatibilityHelper {
public static boolean isRenderInScreen;
private static PlatformHelper platformHelper;
private static Method NEA_playerTransformer_setDeltaTick;
private static Field NEA_NEAnimationsLoader_INSTANCE;
Expand Down Expand Up @@ -65,6 +67,18 @@ public static void initialize(PlatformHelper platformHelper) {
} catch (Exception e) {
RealCamera.LOGGER.warn("Compatibility with TACZ is outdated: [{}] {}", e.getClass().getName(), e.getMessage());
}
if (isModLoaded("entity_model_features")) try {
Class<?> emfAnimationApi = Class.forName("traben.entity_model_features.EMFAnimationApi");
if ((int) emfAnimationApi.getMethod("getApiVersion").invoke(null) >= 9) {
Function<Object, Boolean> pauseCondition = ignored -> isRenderInScreen;
Method registerPauseCondition = emfAnimationApi.getMethod("registerPauseCondition", Function.class);
registerPauseCondition.invoke(null, pauseCondition);
} else {
throw new IllegalStateException("EntityModelFeatures API is outdated; model-view animations may flicker");
}
} catch (Exception e) {
RealCamera.LOGGER.warn("Compatibility with EntityModelFeatures is outdated: [{}] {}", e.getClass().getName(), e.getMessage());
}
}

private static boolean SBW_gunsIsZooming() {
Expand Down Expand Up @@ -115,4 +129,4 @@ public static void forceSetCameraPos(Camera camera) {
public static boolean isModLoaded(String modId) {
return platformHelper.isModLoaded(modId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public class DisableHelper {
static {
MAIN_FEATURE.registerOrInBinding(player -> ConfigFile.config().bindingDisableWhenSneaking() && player.isCrouching());
MAIN_FEATURE.registerOrInClassic(player -> ConfigFile.config().classicDisableWhenSneaking() && player.isCrouching());
MAIN_FEATURE.registerOrInBinding(player -> ConfigFile.config().bindingDisableWhenSwimming() && checkCondition(player, player.isSwimming(), ConfigFile.config().getBindingOutTick()));
MAIN_FEATURE.registerOrInClassic(player -> ConfigFile.config().classicDisableWhenSwimming() && checkCondition(player, player.isSwimming(), ConfigFile.config().getClassicOutTick()));
MAIN_FEATURE.registerOrInBinding(player -> ConfigFile.config().bindingDisableWhenCrawling() && checkCondition(player, player.isVisuallyCrawling(), ConfigFile.config().getBindingOutTick()));
MAIN_FEATURE.registerOrInBinding(player -> ConfigFile.config().bindingDisableWhenSwimming()
&& checkCondition(player, player.isVisuallySwimming(), ConfigFile.config().getBindingExitTick()));
MAIN_FEATURE.registerOrInClassic(player -> ConfigFile.config().classicDisableWhenSwimming()
&& checkCondition(player, player.isVisuallySwimming(), ConfigFile.config().getClassicExitTick()));
MAIN_FEATURE.registerOrInBinding(player -> ConfigFile.config().bindingDisableWhenFlying() && player.isFallFlying());
MAIN_FEATURE.registerOrInBinding(player -> {
Item mainHand = player.getMainHandItem().getItem();
Item offHand = player.getOffhandItem().getItem();
Expand All @@ -48,16 +50,14 @@ public class DisableHelper {
});
}

private static boolean checkCondition(Player player, boolean condition, int outTick) {
private static boolean checkCondition(Player player, boolean condition, int exitDelayTicks) {
if (condition) {
exitTick = player.tickCount;
return true;
}
if (exitTick > 0) {
int elapsedTicks = player.tickCount - exitTick;
if (elapsedTicks <= outTick) {
return true;
}
if (elapsedTicks <= exitDelayTicks) return true;
exitTick = 0;
}
return false;
Expand Down
20 changes: 10 additions & 10 deletions common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public static Screen create(Screen parent) {
.setDefaultValue(false)
.setSaveConsumer(b -> config.classic.disableWhenSwimming = b)
.build());
classic.addEntry(entryBuilder.startIntField(LocUtil.CONFIG_OPTION("outTick"), config.classic.outTick)
classic.addEntry(entryBuilder.startIntField(LocUtil.CONFIG_OPTION("exitTick"), config.classic.exitTick)
.setDefaultValue(13)
.setMin(0)
.setMax(40)
.setTooltip(LocUtil.CONFIG_TOOLTIP("outTick"))
.setSaveConsumer(i -> config.classic.outTick = i)
.setTooltip(LocUtil.CONFIG_TOOLTIP("exitTick"))
.setSaveConsumer(i -> config.classic.exitTick = i)
.build());
classic.addEntry(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("scale"), config.classic.scale)
.setDefaultValue(8.0)
Expand Down Expand Up @@ -196,20 +196,20 @@ public static Screen create(Screen parent) {
.setDefaultValue(false)
.setSaveConsumer(b -> config.binding.disableWhenSneaking = b)
.build());
disableConfig.add(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("disableWhenCrawling"), config.binding.disableWhenCrawling)
.setDefaultValue(false)
.setSaveConsumer(b -> config.binding.disableWhenCrawling = b)
.build());
disableConfig.add(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("disableWhenSwimming"), config.binding.disableWhenSwimming)
.setDefaultValue(false)
.setSaveConsumer(b -> config.binding.disableWhenSwimming = b)
.build());
disableConfig.add(entryBuilder.startIntField(LocUtil.CONFIG_OPTION("outTick"), config.binding.outTick)
disableConfig.add(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("disableWhenFlying"), config.binding.disableWhenFlying)
.setDefaultValue(false)
.setSaveConsumer(b -> config.binding.disableWhenFlying = b)
.build());
disableConfig.add(entryBuilder.startIntField(LocUtil.CONFIG_OPTION("exitTick"), config.binding.exitTick)
.setDefaultValue(13)
.setMin(0)
.setMax(40)
.setTooltip(LocUtil.CONFIG_TOOLTIP("outTick"))
.setSaveConsumer(i -> config.binding.outTick = i)
.setTooltip(LocUtil.CONFIG_TOOLTIP("exitTick"))
.setSaveConsumer(i -> config.binding.exitTick = i)
.build());
disableConfig.add(entryBuilder.startStrList(LocUtil.CONFIG_OPTION("disableMainFeatureItems"), config.binding.disableMainFeatureItems)
.setDefaultValue(List.of())
Expand Down
59 changes: 43 additions & 16 deletions common/src/main/java/com/xtracr/realcamera/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ public boolean classicDisableWhenSwimming() {
return classic.disableWhenSwimming;
}

public int getClassicExitTick() {
return classic.exitTick;
}

@Deprecated
public int getClassicOutTick() {
return classic.outTick;
return getClassicExitTick();
}

@Deprecated
public int getClassicSwimOutTick() {
return getClassicOutTick();
return getClassicExitTick();
}

public double getClassicX() {
Expand Down Expand Up @@ -184,8 +189,9 @@ public boolean hideBindingFailureMessage() {
return binding.hideFailureMessage;
}

@Deprecated
public boolean bindingDisableWhenCrawling() {
return binding.disableWhenCrawling;
return bindingDisableWhenSwimming();
}

public boolean bindingDisableWhenSneaking() {
Expand All @@ -196,13 +202,22 @@ public boolean bindingDisableWhenSwimming() {
return binding.disableWhenSwimming;
}

public boolean bindingDisableWhenFlying() {
return binding.disableWhenFlying;
}

public int getBindingExitTick() {
return binding.exitTick;
}

@Deprecated
public int getBindingOutTick() {
return binding.outTick;
return getBindingExitTick();
}

@Deprecated
public int getBindingSwimOutTick() {
return getBindingOutTick();
return getBindingExitTick();
}

public int getBindResultRetentionFrames() {
Expand Down Expand Up @@ -263,7 +278,9 @@ public static class Classic {
public AdjustMode adjustMode = AdjustMode.CAMERA;
public boolean disableWhenSneaking = false;
public boolean disableWhenSwimming = false;
public int outTick = 13;
public int exitTick = 13;
@Deprecated
public Integer outTick = null;
@Deprecated
public Integer swimOutTick = null;
public double scale = 8.0;
Expand All @@ -279,11 +296,13 @@ public static class Classic {

private void clamp() {
if (adjustMode == null) adjustMode = AdjustMode.CAMERA;
if (swimOutTick != null) {
if (outTick == 13) outTick = swimOutTick;
swimOutTick = null;
if (exitTick == 13) {
if (outTick != null) exitTick = outTick;
else if (swimOutTick != null) exitTick = swimOutTick;
}
outTick = Mth.clamp(outTick, 0, 40);
outTick = null;
swimOutTick = null;
exitTick = Mth.clamp(exitTick, 0, 40);
scale = Mth.clamp(scale, 0.0, 64.0);
cameraX = Mth.clamp(cameraX, MIN_OFFSET_D, MAX_OFFSET_D);
cameraY = Mth.clamp(cameraY, MIN_OFFSET_D, MAX_OFFSET_D);
Expand Down Expand Up @@ -316,10 +335,14 @@ public static class Binding {
public boolean adjustOffset = true;
public boolean hideFailureMessage = false;
public boolean renderStuckObjects = true;
public boolean disableWhenCrawling = false;
@Deprecated
public Boolean disableWhenCrawling = null;
public boolean disableWhenSneaking = false;
public boolean disableWhenSwimming = false;
public int outTick = 13;
public boolean disableWhenFlying = false;
public int exitTick = 13;
@Deprecated
public Integer outTick = null;
@Deprecated
public Integer swimOutTick = null;
public int bindResultRetentionFrames = 2;
Expand All @@ -337,15 +360,19 @@ private void clamp() {
} catch (Exception e) {
screenModifierKey = InputConstants.Type.KEYSYM.getOrCreate(InputConstants.KEY_LALT).getName();
}
if (swimOutTick != null) {
if (outTick == 13) outTick = swimOutTick;
swimOutTick = null;
if (Boolean.TRUE.equals(disableWhenCrawling)) disableWhenSwimming = true;
disableWhenCrawling = null;
if (exitTick == 13) {
if (outTick != null) exitTick = outTick;
else if (swimOutTick != null) exitTick = swimOutTick;
}
outTick = null;
swimOutTick = null;
exitTick = Mth.clamp(exitTick, 0, 40);
if (legacyBindingMode != null) {
legacyMode = legacyBindingMode;
legacyBindingMode = null;
}
outTick = Mth.clamp(outTick, 0, 40);
bindResultRetentionFrames = Math.max(bindResultRetentionFrames, 0);
activeConfigIndex = Math.max(activeConfigIndex, 0);
displacementSmoothFactor = Mth.clamp(displacementSmoothFactor, 0.0, 1.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ else if (index > 0 && index <= rectWidgets.size()) {
BindTarget bindTarget = genBindTarget();
ConfigFile.config().putBindTarget(bindTarget);
ConfigFile.save();
if (toggleCategoryButton.getValue() != Category.DISABLE) loadBindTarget(bindTarget);
initWidgets(page);
}));
rows.addChild(priorityField = NumberField.ofInt(font, widgetWidth - 2, widgetHeight - 2, 0, priorityField), smallSettings).setTooltip(createTooltip("priority"));
Expand Down Expand Up @@ -561,6 +562,8 @@ protected void renderModelViewArea(GuiGraphics graphics, LivingEntity entity) {
float entityPitch = entity.getXRot();
float entityPrevHeadYaw = entity.yHeadRotO;
float entityHeadYaw = entity.yHeadRot;
boolean previousRenderInScreen = CompatibilityHelper.isRenderInScreen;
CompatibilityHelper.isRenderInScreen = true;
try {
entity.yBodyRot = 180.0f;
entity.setYRot(180.0f + (float) entityYawSlider.getNumber());
Expand All @@ -570,6 +573,7 @@ protected void renderModelViewArea(GuiGraphics graphics, LivingEntity entity) {
Vector3f offset = new Vector3f((float) modelX, (float) modelY, 0);
renderEntityWithAnalyser(graphics, x1, y1, x2, y2, modelScale, offset, quaternionf, entity);
} finally {
CompatibilityHelper.isRenderInScreen = previousRenderInScreen;
entity.yBodyRot = entityBodyYaw;
entity.setYRot(entityYaw);
entity.setXRot(entityPitch);
Expand Down Expand Up @@ -653,6 +657,12 @@ protected void loadBindTarget(BindTarget target) {

protected BindTarget genBindTarget() {
initOffsetPairs();
DisableConfig currentDisableConfig = new DisableConfig(disabledNameField.getValue(), disabledIdField.getValue(), disableModeButton.getValue() == 0, rectWidgets.stream().map(UVRectangleWidget::toUVRectangle).toList());
List<DisableConfig> newDisableConfigs = new ArrayList<>(disableConfigs);
for (int i = 0; i < newDisableConfigs.size(); i++) {
if (newDisableConfigs.get(i).name().equals(currentDisableConfig.name()))
newDisableConfigs.set(i, currentDisableConfig);
}
TargetConfig targetConfig = new TargetConfig( forwardUField.getNumber(), forwardVField.getNumber(), upwardUField.getNumber(), upwardVField.getNumber(), posUField.getNumber(), posVField.getNumber());
BindConfig bindConfig = new BindConfig( bindXButton.getValue() == 0, bindYButton.getValue() == 0, bindZButton.getValue() == 0, bindRotButton.getValue() == 0);
OffsetConfig offsets = new OffsetConfig()
Expand All @@ -663,7 +673,7 @@ protected BindTarget genBindTarget() {
.setPitch(offsetPitchPair.getNumber())
.setYaw(offsetYawPair.getNumber())
.setRoll(offsetRollPair.getNumber());
return new BindTarget(nameField.getValue(), textureIdField.getValue(), priorityField.getNumber(), depthField.getNumber(), targetConfig, bindConfig, offsets, new ArrayList<>(disableConfigs));
return new BindTarget(nameField.getValue(), textureIdField.getValue(), priorityField.getNumber(), depthField.getNumber(), targetConfig, bindConfig, offsets, newDisableConfigs);
}

private void clearDisableDraft() {
Expand Down
Loading
Loading