Add always more features.

This commit is contained in:
LambdAurora
2020-02-16 23:20:21 +01:00
parent 8efddb24b0
commit 8e082404f9
15 changed files with 214 additions and 84 deletions

View File

@@ -38,7 +38,7 @@ import org.lwjgl.glfw.GLFW;
* Represents the LambdaControls client mod.
*
* @author LambdAurora
* @version 1.1.1
* @version 1.2.0
* @since 1.1.0
*/
public class LambdaControlsClient extends LambdaControls implements ClientModInitializer

View File

@@ -40,10 +40,11 @@ public class LambdaControlsConfig
private static final boolean DEFAULT_HUD_ENABLE = true;
private static final HudSide DEFAULT_HUD_SIDE = HudSide.LEFT;
// Gameplay
private static final boolean DEFAULT_FRONT_BLOCK_PLACING = false;
private static final boolean DEFAULT_FAST_BLOCK_INTERACTION = true;
private static final boolean DEFAULT_FLY_DRIFTING = false;
private static final boolean DEFAULT_FLY_VERTICAL_DRIFTING = true;
private static final boolean DEFAULT_FRONT_BLOCK_PLACING = false;
private static final boolean DEFAULT_FRONT_BLOCK_OUTLINE = true;
// Controller
private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT;
private static final double DEFAULT_DEAD_ZONE = 0.25;
@@ -57,14 +58,17 @@ public class LambdaControlsConfig
private final LambdaControlsClient mod;
private ControlsMode controlsMode;
private ControllerType controllerType;
// HUD settings.
private boolean hudEnable;
private HudSide hudSide;
// Gameplay.
private boolean shouldRenderFrontBlockOutline;
private int[] frontBlockOutlineColor;
// Controller settings
private double deadZone;
private double rotationSpeed;
private double mouseSpeed;
private boolean unfocusedInput;
// HUD settings.
private boolean hudEnable;
private HudSide hudSide;
public LambdaControlsConfig(@NotNull LambdaControlsClient mod)
{
@@ -84,8 +88,10 @@ public class LambdaControlsConfig
this.hudEnable = this.config.getOrElse("hud.enable", DEFAULT_HUD_ENABLE);
this.hudSide = HudSide.byId(this.config.getOrElse("hud.side", DEFAULT_HUD_SIDE.getName())).orElse(DEFAULT_HUD_SIDE);
// Gameplay
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.front_block_placing", DEFAULT_FRONT_BLOCK_PLACING));
LambdaControlsFeature.FAST_BLOCK_INTERACTION.setEnabled(this.config.getOrElse("gameplay.fast_block_interaction", DEFAULT_FAST_BLOCK_INTERACTION));
LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.fast_block_placing", DEFAULT_FAST_BLOCK_INTERACTION));
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.front_block_placing.enabled", DEFAULT_FRONT_BLOCK_PLACING));
this.shouldRenderFrontBlockOutline = this.config.getOrElse("gameplay.front_block_placing.outline", DEFAULT_FRONT_BLOCK_OUTLINE);
this.frontBlockOutlineColor = this.config.getOptional("gameplay.front_block_placing.outline_color").map(hex -> parseColor((String) hex)).orElse(new int[]{255, 255, 255, 102});
// Controller settings.
this.controllerType = ControllerType.byId(this.config.getOrElse("controller.type", DEFAULT_CONTROLLER_TYPE.getName())).orElse(DEFAULT_CONTROLLER_TYPE);
this.deadZone = this.config.getOrElse("controller.dead_zone", DEFAULT_DEAD_ZONE);
@@ -119,6 +125,12 @@ public class LambdaControlsConfig
this.config.set(path, String.valueOf(raw));
}
});
// This shouldn't happen if the configuration is new.
if (!this.config.contains("gameplay.front_block_placing.enabled") && this.config.contains("gameplay.front_block_placing")) {
this.config.remove("gameplay.front_block_placing");
this.config.set("gameplay.front_block_placing.enabled", DEFAULT_FRONT_BLOCK_PLACING);
}
}
/**
@@ -134,7 +146,7 @@ public class LambdaControlsConfig
this.setHudSide(DEFAULT_HUD_SIDE);
// Gameplay
this.setFrontBlockPlacing(DEFAULT_FRONT_BLOCK_PLACING);
this.setFastBlockInteraction(DEFAULT_FAST_BLOCK_INTERACTION);
this.setFastBlockPlacing(DEFAULT_FAST_BLOCK_INTERACTION);
this.setFlyDrifting(DEFAULT_FLY_DRIFTING);
this.setFlyVerticalDrifting(DEFAULT_FLY_VERTICAL_DRIFTING);
// Controller
@@ -240,45 +252,24 @@ public class LambdaControlsConfig
*/
/**
* Gets whether fast block interaction is enabled or not.
* Gets whether fast block placing is enabled or not.
*
* @return True if fast block interaction is enabled, else false.
* @return True if fast block placing is enabled, else false.
*/
public boolean hasFastBlockInteraction()
public boolean hasFastBlockPlacing()
{
return LambdaControlsFeature.FAST_BLOCK_INTERACTION.isEnabled();
return LambdaControlsFeature.FAST_BLOCK_PLACING.isEnabled();
}
/**
* Sets whether fast block interaction is enabled or not.
* Sets whether fast block placing is enabled or not.
*
* @param enable True if fast block interaction is enabled, else false.
* @param enable True if fast block placing is enabled, else false.
*/
public void setFastBlockInteraction(boolean enable)
public void setFastBlockPlacing(boolean enable)
{
LambdaControlsFeature.FAST_BLOCK_INTERACTION.setEnabled(enable);
this.config.set("gameplay.fast_block_interaction", enable);
}
/**
* Returns whether front block placing is enabled or not.
*
* @return True if front block placing is enabled, else false.
*/
public boolean hasFrontBlockPlacing()
{
return LambdaControlsFeature.FRONT_BLOCK_PLACING.isEnabled();
}
/**
* Sets whether front block placing is enabled or not.
*
* @param enable True if front block placing is enabled, else false.
*/
public void setFrontBlockPlacing(boolean enable)
{
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(enable);
this.config.set("gameplay.front_block_placing", enable);
LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(enable);
this.config.set("gameplay.fast_block_placing", enable);
}
/**
@@ -321,6 +312,59 @@ public class LambdaControlsConfig
this.config.set("gameplay.fly.vertical_drifting", flyDrifting);
}
/**
* Returns whether front block placing is enabled or not.
*
* @return True if front block placing is enabled, else false.
*/
public boolean hasFrontBlockPlacing()
{
return LambdaControlsFeature.FRONT_BLOCK_PLACING.isEnabled();
}
/**
* Sets whether front block placing is enabled or not.
*
* @param enable True if front block placing is enabled, else false.
*/
public void setFrontBlockPlacing(boolean enable)
{
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(enable);
this.config.set("gameplay.front_block_placing.enabled", enable);
}
/**
* Returns whether front block placing outline is enabled or not.
*
* @return True if front block placing outline is enabled, else false.
*/
public boolean shouldRenderFrontBlockOutline()
{
return this.shouldRenderFrontBlockOutline;
}
/**
* Sets whether front block placing outline is enabled or not.
*
* @param render True if front block placing outline is enabled, else false.
*/
public void setRenderFrontBlockOutline(boolean render)
{
this.config.set("gameplay.front_block_placing.outline", this.shouldRenderFrontBlockOutline = render);
}
/**
* Returns the front block placing outline color as an integer array.
* <p>
* The integer array has 4 elements: red, green, blue and alpha.
*
* @return The color as a RGBA integer array.
*/
public int[] getFrontBlockOutlineColor()
{
return this.frontBlockOutlineColor;
}
/*
Controller settings
*/
@@ -636,4 +680,32 @@ public class LambdaControlsConfig
{
return axis == GLFW_GAMEPAD_AXIS_LEFT_Y || axis == GLFW_GAMEPAD_AXIS_LEFT_X;
}
/**
* Parses a color from a hexadecimal color string.
*
* @param hex The hexadecimal color.
* @return The color instance, null if invalid.
*/
private static int[] parseColor(String hex)
{
hex = hex.replace("#", "");
switch (hex.length()) {
case 6:
return new int[]{
Integer.valueOf(hex.substring(0, 2), 16),
Integer.valueOf(hex.substring(2, 4), 16),
Integer.valueOf(hex.substring(4, 6), 16),
255
};
case 8:
return new int[]{
Integer.valueOf(hex.substring(0, 2), 16),
Integer.valueOf(hex.substring(2, 4), 16),
Integer.valueOf(hex.substring(4, 6), 16),
Integer.valueOf(hex.substring(6, 8), 16)
};
}
return null;
}
}

View File

@@ -18,7 +18,7 @@ import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
* Represents the API implementation of ModMenu for LambdaControls.
*
* @author LambdAurora
* @version 1.1.1
* @version 1.2.0
* @since 1.1.0
*/
public class LambdaControlsModMenu implements ModMenuApi

View File

@@ -68,7 +68,7 @@ import static org.lwjgl.glfw.GLFW.*;
* Represents the LambdaControls' input handler.
*
* @author LambdAurora
* @version 1.1.1
* @version 1.2.0
* @since 1.0.0
*/
public class LambdaInput
@@ -688,6 +688,9 @@ public class LambdaInput
Direction direction = client.player.getHorizontalFacing();
BlockState state = client.world.getBlockState(blockPos);
if (!state.isAir())
return null;
BlockState adjacentBlockState = client.world.getBlockState(blockPos.offset(direction.getOpposite()));
if (adjacentBlockState.isAir() || adjacentBlockState.getBlock() instanceof FluidBlock || (vector.getX() == 0 && vector.getZ() == 0)) {
return null;

View File

@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
* Represents some input handlers.
*
* @author LambdAurora
* @version 1.1.1
* @version 1.2.0
* @since 1.1.0
*/
public class InputHandlers

View File

@@ -34,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
* Represents the LambdaControls HUD.
*
* @author LambdAurora
* @version 1.1.1
* @version 1.2.0
* @since 1.0.0
*/
public class LambdaControlsHud extends Hud

View File

@@ -25,8 +25,8 @@ import org.lwjgl.glfw.GLFW;
* Represents the LambdaControls renderer.
*
* @author LambdAurora
* @version 1.1.1
* @since 1.1.1
* @version 1.2.0
* @since 1.2.0
*/
public class LambdaControlsRenderer
{

View File

@@ -46,6 +46,7 @@ public class LambdaControlsSettingsScreen extends Screen
private final Option resetOption;
// Gameplay options
private final Option autoJumpOption;
private final Option fastBlockPlacingOption;
private final Option frontBlockPlacingOption;
private final Option flyDriftingOption;
private final Option flyVerticalDriftingOption;
@@ -94,6 +95,8 @@ public class LambdaControlsSettingsScreen extends Screen
});
// Gameplay options
this.autoJumpOption = SpruceBooleanOption.fromVanilla("options.autoJump", Option.AUTO_JUMP, null, true);
this.fastBlockPlacingOption = new SpruceBooleanOption("lambdacontrols.menu.fast_block_placing", this.mod.config::hasFastBlockPlacing,
this.mod.config::setFastBlockPlacing, new TranslatableText("lambdacontrols.tooltip.fast_block_placing"), true);
this.frontBlockPlacingOption = new SpruceBooleanOption("lambdacontrols.menu.front_block_placing", this.mod.config::hasFrontBlockPlacing,
this.mod.config::setFrontBlockPlacing, new TranslatableText("lambdacontrols.tooltip.front_block_placing"), true);
this.flyDriftingOption = new SpruceBooleanOption("lambdacontrols.menu.fly_drifting", this.mod.config::hasFlyDrifting,
@@ -224,7 +227,7 @@ public class LambdaControlsSettingsScreen extends Screen
// Gameplay options
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.gameplay", true, null));
this.list.addSingleOptionEntry(this.autoJumpOption);
this.list.addSingleOptionEntry(this.frontBlockPlacingOption);
this.list.addOptionEntry(this.fastBlockPlacingOption, this.frontBlockPlacingOption);
this.list.addSingleOptionEntry(this.flyDriftingOption);
this.list.addSingleOptionEntry(this.flyVerticalDriftingOption);
// Controller options

View File

@@ -12,6 +12,7 @@ package me.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.LambdaControlsFeature;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaInput;
import me.lambdaurora.lambdacontrols.client.util.FrontBlockPlaceResultAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayerEntity;
@@ -36,7 +37,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin
public abstract class MinecraftClientMixin implements FrontBlockPlaceResultAccessor
{
@Shadow
@Nullable
@@ -61,10 +62,18 @@ public abstract class MinecraftClientMixin
@Shadow
private int itemUseCooldown;
private BlockHitResult lambdacontrols_frontBlockPlaceResult = null;
private BlockPos lambdacontrols_lastTargetPos;
private Direction lambdacontrols_lockedSide;
private int lambdacontrols_lockedSideCooldown;
@Override
public @Nullable BlockHitResult lambdacontrols_getFrontBlockPlaceResult()
{
return this.lambdacontrols_frontBlockPlaceResult;
}
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci)
{
@@ -74,34 +83,35 @@ public abstract class MinecraftClientMixin
@Inject(method = "tick", at = @At("HEAD"))
private void onStartTick(CallbackInfo ci)
{
if (!LambdaControlsFeature.FAST_BLOCK_INTERACTION.isAvailable())
if (this.player == null)
return;
if (this.player != null) {
int cooldown = this.itemUseCooldown;
BlockHitResult hitResult;
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.BLOCK && this.player.abilities.flying) {
hitResult = (BlockHitResult) this.crosshairTarget;
BlockPos targetPos = hitResult.getBlockPos();
Direction side = hitResult.getSide();
this.lambdacontrols_frontBlockPlaceResult = LambdaInput.tryFrontPlace(((MinecraftClient) (Object) this));
if (!LambdaControlsFeature.FAST_BLOCK_PLACING.isAvailable())
return;
int cooldown = this.itemUseCooldown;
BlockHitResult hitResult;
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.BLOCK && this.player.abilities.flying) {
hitResult = (BlockHitResult) this.crosshairTarget;
BlockPos targetPos = hitResult.getBlockPos();
Direction side = hitResult.getSide();
if (cooldown > 1 && !targetPos.equals(this.lambdacontrols_lastTargetPos) && (side.equals(this.lambdacontrols_lockedSide) || this.lambdacontrols_lockedSide == null)) {
this.itemUseCooldown = 1;
this.lambdacontrols_lockedSide = side;
this.lambdacontrols_lockedSideCooldown = 10;
} else {
if (this.lambdacontrols_lockedSideCooldown == 0)
this.lambdacontrols_lockedSide = null;
else if (this.lambdacontrols_lockedSideCooldown > 0)
this.lambdacontrols_lockedSideCooldown--;
}
if (cooldown > 1 && !targetPos.equals(this.lambdacontrols_lastTargetPos) && (side.equals(this.lambdacontrols_lockedSide) || this.lambdacontrols_lockedSide == null)) {
this.itemUseCooldown = 1;
this.lambdacontrols_lockedSide = side;
this.lambdacontrols_lockedSideCooldown = 10;
} else {
if (this.lambdacontrols_lockedSideCooldown == 0)
this.lambdacontrols_lockedSide = null;
else if (this.lambdacontrols_lockedSideCooldown > 0)
this.lambdacontrols_lockedSideCooldown--;
}
this.lambdacontrols_lastTargetPos = targetPos.toImmutable();
} else if (this.player.isSprinting()) {
hitResult = LambdaInput.tryFrontPlace(((MinecraftClient) (Object) this));
if (hitResult != null) {
if (cooldown > 0)
this.itemUseCooldown = 0;
}
this.lambdacontrols_lastTargetPos = targetPos.toImmutable();
} else if (this.player.isSprinting()) {
hitResult = this.lambdacontrols_frontBlockPlaceResult;
if (hitResult != null) {
if (cooldown > 0)
this.itemUseCooldown = 0;
}
}
}

View File

@@ -9,7 +9,9 @@
package me.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaInput;
import me.lambdaurora.lambdacontrols.client.util.FrontBlockPlaceResultAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
@@ -72,9 +74,9 @@ public abstract class WorldRendererMixin
Profiler profiler, Vec3d cameraPos, double x, double y, double z, Matrix4f modelMatrix, boolean bl, Frustum frustum2, boolean bl3,
VertexConsumerProvider.Immediate immediate)
{
if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS)
if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS || !LambdaControlsClient.get().config.shouldRenderFrontBlockOutline())
return;
BlockHitResult result = LambdaInput.tryFrontPlace(client);
BlockHitResult result = ((FrontBlockPlaceResultAccessor) client).lambdacontrols_getFrontBlockPlaceResult();
if (result == null)
return;
BlockPos blockPos = result.getBlockPos();
@@ -90,7 +92,8 @@ public abstract class WorldRendererMixin
if (placementState == null)
return;
VoxelShape outlineShape = placementState.getOutlineShape(this.client.world, blockPos, EntityContext.of(camera.getFocusedEntity()));
drawShapeOutline(matrices, vertexConsumer, outlineShape, (double) blockPos.getX() - x, (double) blockPos.getY() - y, (double) blockPos.getZ() - z, 1.0F, 1.0F, 1.0F, 0.4F);
int[] color = LambdaControlsClient.get().config.getFrontBlockOutlineColor();
drawShapeOutline(matrices, vertexConsumer, outlineShape, (double) blockPos.getX() - x, (double) blockPos.getY() - y, (double) blockPos.getZ() - z, color[0] / 255.f, color[1] / 255.f, color[2] / 255.f, color[3] / 255.f);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.util;
import net.minecraft.util.hit.BlockHitResult;
import org.jetbrains.annotations.Nullable;
/**
* Represents an accessor of the BlockHitResult for the front block placing feature.
* <p>
* It is implemented by {@link net.minecraft.client.MinecraftClient}.
*
* @author LambdAurora
* @version 1.2.0
* @since 1.2.0
*/
public interface FrontBlockPlaceResultAccessor
{
/**
* Returns the {@link BlockHitResult} if a block can be placed with the front block placing feature.
*
* @return If possible a {@link BlockHitResult}, else a null value.
*/
@Nullable BlockHitResult lambdacontrols_getFrontBlockPlaceResult();
}

View File

@@ -80,6 +80,7 @@
"lambdacontrols.menu.controller_type": "Controller Type",
"lambdacontrols.menu.controls_mode": "Mode",
"lambdacontrols.menu.dead_zone": "Dead Zone",
"lambdacontrols.menu.fast_block_placing": "Fast Block Placing",
"lambdacontrols.menu.fly_drifting": "Fly Drifting",
"lambdacontrols.menu.fly_drifting_vertical": "Vertical Fly Drifting",
"lambdacontrols.menu.front_block_placing": "Front Block Placing",
@@ -106,6 +107,7 @@
"lambdacontrols.tooltip.controller_type": "The controller type to display the correct buttons.",
"lambdacontrols.tooltip.controls_mode": "The controls mode.",
"lambdacontrols.tooltip.dead_zone": "The dead zone for the controller's analogue sticks.",
"lambdacontrols.tooltip.fast_block_placing": "While flying in creative mode, enables fast block placing depending on your speed. §cOn some servers this might be considered as cheating.",
"lambdacontrols.tooltip.fly_drifting": "While flying, enables Vanilla drifting/inertia.",
"lambdacontrols.tooltip.fly_drifting_vertical": "While flying, enables Vanilla vertical drifting/intertia.",
"lambdacontrols.tooltip.front_block_placing": "Enables front block placing, §cmight be considered cheating on some servers§r.",

View File

@@ -13,16 +13,21 @@ auto_switch_mode = false
# Gameplay settings
[gameplay]
# Enables fast block interaction like in Bedrock Edition.
fast_block_interaction = true
# Enables front block placing like in Bedrock Edition.
front_block_placing = false
# Enables fast block placing like in Bedrock Edition.
fast_block_placing = true
# Fly behaviors
[gameplay.fly]
# Enables fly drifting.
drifting = false
# Enables vertical fly drifting.
vertical_drifting = true
[gameplay.front_block_placing]
# Enables front block placing like in Bedrock Edition.
enabled = false
# Enables front block placing outline.
outline = true
# The color in a hexadecimal format of the outline.
outline_color = "#ffffff66"
# Controller settings
[controller]