Skip to content

Commit

Permalink
- Added new 'Interaction Mode' setting
Browse files Browse the repository at this point in the history
- Fixed tripods getting stuck if the player leaves the dimension
- Version bump
  • Loading branch information
hashalite committed Jul 20, 2022
1 parent f83428a commit 666dfb2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The freecam bind can also be used in conjunction with any of the hotbar keys (`F
|Name|Description|Default Value|
|-|-|-|
|Flight Mode|The type of flight used by freecam.<br /><br />**Options:**<br />- `DEFAULT` Static velocity with no drifting<br />- `CREATIVE` Vanilla creative flight|`DEFAULT`|
|Interaction Mode|The source of block/entity interactions.<br /><br />**Options:**<br />- `FREECAM` Interactions come from the freecamera<br />- `PLAYER` Interactions come from the player|`FREECAM`|
|Horizontal Speed|The horizontal speed of freecam.|`1.0`|
|Vertical Speed|The vertical speed of freecam.|`1.0`|
|No Clip|Whether you can travel through blocks in freecam.|`true`|
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.8
# Mod Properties
mod_version=1.1.2
mod_version=1.1.3
maven_group=net.xolt
archives_base_name=freecam
# Dependencies
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/net/xolt/freecam/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public static void init() {
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public FlightMode flightMode = FlightMode.DEFAULT;

@Comment("The source of block/entity interactions.")
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public InteractionMode interactionMode = InteractionMode.FREECAM;

@Comment("The horizontal speed of freecam.")
public double horizontalSpeed = 1.0;

Expand All @@ -35,7 +39,7 @@ public static void init() {
@Comment("Prevents player movement while freecam is active.\nWARNING: Multiplayer usage not advised.")
public boolean freezePlayer = false;

@Comment("Whether you can interact with blocks/entities in freecam.\nWARNING: Multiplayer usage not advised.")
@Comment("Whether the freecamera can interact with blocks/entities.\nWARNING: Multiplayer usage not advised.")
public boolean allowInteract = false;

@Comment("Disables freecam when damage is received.")
Expand Down Expand Up @@ -67,4 +71,19 @@ public String getKey() {
return name;
}
}

public enum InteractionMode implements SelectionListEntry.Translatable {
FREECAM("Freecam"),
PLAYER("Player");

private final String name;

InteractionMode(String name) {
this.name = name;
}

public String getKey() {
return name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {

// Disables freecam when the player respawns.
// Disables freecam when the player respawns/switches dimensions.
@Inject(method = "onPlayerRespawn", at = @At("HEAD"))
private void onPlayerRespawn(CallbackInfo ci) {
if (Freecam.isEnabled()) {
Freecam.toggle();
}
Freecam.clearPersistentCameras();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ public class ClientPlayerInteractionManagerMixin {
// Prevents interacting with blocks when allowInteract is disabled.
@Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true)
private void onInteractBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract) {
cir.setReturnValue(ActionResult.PASS);
}
}

// Prevents interacting with entities when allowInteract is disabled, and prevents interacting with self.
@Inject(method = "interactEntity", at = @At("HEAD"), cancellable = true)
private void onInteractEntity(PlayerEntity player, Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (entity.equals(MC.player) || (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract)) {
if (entity.equals(MC.player) || (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract)) {
cir.setReturnValue(ActionResult.PASS);
}
}

// Prevents interacting with entities when allowInteract is disabled, and prevents interacting with self.
@Inject(method = "interactEntityAtLocation", at = @At("HEAD"), cancellable = true)
private void onInteractEntityAtLocation(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (entity.equals(MC.player) || (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract)) {
if (entity.equals(MC.player) || (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract)) {
cir.setReturnValue(ActionResult.PASS);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class GameRendererMixin {
// Disables block outlines when allowInteract is disabled.
@Inject(method = "shouldRenderBlockOutline", at = @At("HEAD"), cancellable = true)
private void onShouldRenderBlockOutline(CallbackInfoReturnable<Boolean> cir) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract) {
cir.setReturnValue(false);
}
}

// Makes mouse clicks come from the player rather than the freecam entity when player control is enabled.
// Makes mouse clicks come from the player rather than the freecam entity when player control is enabled or if interaction mode is set to player.
@ModifyVariable(method = "updateTargetedEntity", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/MinecraftClient;getCameraEntity()Lnet/minecraft/entity/Entity;"))
private Entity onUpdateTargetedEntity(Entity entity) {
if (Freecam.isEnabled() && Freecam.isPlayerControlEnabled()) {
if (Freecam.isEnabled() && (Freecam.isPlayerControlEnabled() || ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER))) {
return MC.player;
}
return entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ private void onTick(CallbackInfo ci) {
// Prevents attacks when allowInteract is disabled.
@Inject(method = "doAttack", at = @At("HEAD"), cancellable = true)
private void onDoAttack(CallbackInfoReturnable<Boolean> cir) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract) {
cir.cancel();
}
}

// Prevents item pick when allowInteract is disabled.
@Inject(method = "doItemPick", at = @At("HEAD"), cancellable = true)
private void onDoItemPick(CallbackInfo ci) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract) {
ci.cancel();
}
}

// Prevents block breaking when allowInteract is disabled.
@Inject(method = "handleBlockBreaking", at = @At("HEAD"), cancellable = true)
private void onHandleBlockBreaking(CallbackInfo ci) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.allowInteract) {
if (Freecam.isEnabled() && !Freecam.isPlayerControlEnabled() && !ModConfig.INSTANCE.interactionMode.equals(ModConfig.InteractionMode.PLAYER) && !ModConfig.INSTANCE.allowInteract) {
ci.cancel();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/freecam/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"msg.freecam.disablePersistent": "Closing camera #",
"text.autoconfig.freecam.title": "Freecam Options",
"text.autoconfig.freecam.option.flightMode": "Flight Mode",
"text.autoconfig.freecam.option.interactionMode": "Interaction Mode",
"text.autoconfig.freecam.option.horizontalSpeed": "Horizontal Speed",
"text.autoconfig.freecam.option.verticalSpeed": "Vertical Speed",
"text.autoconfig.freecam.option.noclip": "No Clip",
Expand Down

0 comments on commit 666dfb2

Please sign in to comment.