Skip to content

Commit 64fcdfd

Browse files
committed
Added a main toggle
1 parent 5273081 commit 64fcdfd

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/main/java/io/github/andrew6rant/autoslabs/PlacementHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.andrew6rant.autoslabs;
22

3+
import io.github.andrew6rant.autoslabs.config.CommonConfig;
34
import io.github.andrew6rant.autoslabs.util.PlacementUtil;
45
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
56
import net.minecraft.block.BlockState;
@@ -33,9 +34,10 @@ private static ActionResult onUseBlock(PlayerEntity player, World world, Hand ha
3334
return ActionResult.PASS; // Let vanilla handle non-slab items
3435
}
3536

36-
// Check if player is using autoslabs mode
37-
if (AutoSlabs.slabLockPosition.getOrDefault(player, SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
38-
return ActionResult.PASS; // Let vanilla handle vanilla placement mode
37+
// Check if autoslabs is enabled and player is not using vanilla placement mode
38+
if (!CommonConfig.enableSlabLock ||
39+
AutoSlabs.slabLockPosition.getOrDefault(player, SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
40+
return ActionResult.PASS; // Let vanilla handle when disabled or in vanilla placement mode
3941
}
4042

4143
// Create placement context to check if this is actually a valid slab placement
@@ -46,7 +48,6 @@ private static ActionResult onUseBlock(PlayerEntity player, World world, Hand ha
4648
// Only handle if we're placing on a slab or empty space (not on other blocks)
4749
boolean shouldHandle = currentState.getBlock() instanceof SlabBlock || currentState.isAir();
4850

49-
// If we shouldn't handle this placement, let vanilla handle it
5051
if (!shouldHandle) {
5152
return ActionResult.PASS;
5253
}
@@ -87,7 +88,6 @@ private static ActionResult handleServerPlacement(ServerPlayerEntity player, Ser
8788
BlockState placementState = PlacementUtil.calcPlacementState(context, blockItem.getBlock().getDefaultState());
8889

8990
if (placementState == null) {
90-
// Placement not valid
9191
return ActionResult.FAIL;
9292
}
9393

src/main/java/io/github/andrew6rant/autoslabs/config/CommonConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import eu.midnightdust.lib.config.MidnightConfig;
44

55
public class CommonConfig extends MidnightConfig {
6-
@Entry public static boolean dumpResources = false;
7-
@Entry public static boolean showEnhancedSlabLines = true;
6+
@Entry public static boolean enableSlabLock = true;
87
@Entry public static ShowCrosshairIcon showCrosshairIcon = ShowCrosshairIcon.ON_CHANGE;
98
public enum ShowCrosshairIcon {
109
ALWAYS,
1110
ON_CHANGE,
1211
NEVER
1312
}
13+
@Entry public static boolean showEnhancedSlabLines = true;
14+
@Entry public static boolean dumpResources = false;
1415
}

src/main/java/io/github/andrew6rant/autoslabs/mixin/SlabBlockMixin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.github.andrew6rant.autoslabs.AutoSlabs;
44
import io.github.andrew6rant.autoslabs.SlabLockEnum;
55
import io.github.andrew6rant.autoslabs.VerticalType;
6+
import io.github.andrew6rant.autoslabs.config.CommonConfig;
67
import io.github.andrew6rant.autoslabs.util.PlacementUtil;
78
import io.github.andrew6rant.autoslabs.util.Util;
89
import net.minecraft.block.*;
@@ -44,15 +45,17 @@ private SlabBlockMixin(Settings settings) {
4445
@Inject(at = @At("HEAD"), method = "canReplace(Lnet/minecraft/block/BlockState;Lnet/minecraft/item/ItemPlacementContext;)Z", cancellable = true)
4546
private void autoslabs$canSlabReplace(BlockState state, ItemPlacementContext ctx, CallbackInfoReturnable<Boolean> cir) {
4647
if (ctx.getPlayer() == null) return;
47-
if (!AutoSlabs.slabLockPosition.getOrDefault(ctx.getPlayer(), SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
48+
if (CommonConfig.enableSlabLock &&
49+
!AutoSlabs.slabLockPosition.getOrDefault(ctx.getPlayer(), SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
4850
cir.setReturnValue(PlacementUtil.canReplace(state, ctx));
4951
}
5052
}
5153

5254
@Inject(at = @At("HEAD"), method = "getPlacementState(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/block/BlockState;", cancellable = true)
5355
private void autoslabs$getSlabPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable<BlockState> cir) {
5456
if (ctx.getPlayer() == null) return;
55-
if (!AutoSlabs.slabLockPosition.getOrDefault(ctx.getPlayer(), SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
57+
if (CommonConfig.enableSlabLock &&
58+
!AutoSlabs.slabLockPosition.getOrDefault(ctx.getPlayer(), SlabLockEnum.DEFAULT_AUTOSLABS).equals(SlabLockEnum.VANILLA_PLACEMENT)) {
5659
// Return the calculated state for prediction (both client and server)
5760
// The UseBlockCallback will handle actual placement
5861
cir.setReturnValue(PlacementUtil.calcPlacementState(ctx, this.getDefaultState()));

src/main/java/io/github/andrew6rant/autoslabs/mixin/WorldRendererMixin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package io.github.andrew6rant.autoslabs.mixin;
22

3-
import io.github.andrew6rant.autoslabs.util.RenderUtil;
43
import io.github.andrew6rant.autoslabs.SlabLockEnum;
4+
import io.github.andrew6rant.autoslabs.util.RenderUtil;
55
import net.minecraft.block.BlockState;
66
import net.minecraft.client.MinecraftClient;
7-
import net.minecraft.client.render.*;
7+
import net.minecraft.client.render.VertexConsumer;
8+
import net.minecraft.client.render.WorldRenderer;
89
import net.minecraft.client.util.math.MatrixStack;
910
import net.minecraft.entity.Entity;
1011
import net.minecraft.util.hit.HitResult;
@@ -20,6 +21,7 @@
2021
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2122

2223
import static io.github.andrew6rant.autoslabs.AutoSlabsClient.clientSlabLockPosition;
24+
import static io.github.andrew6rant.autoslabs.config.CommonConfig.enableSlabLock;
2325
import static io.github.andrew6rant.autoslabs.config.CommonConfig.showEnhancedSlabLines;
2426

2527
@Mixin(WorldRenderer.class)
@@ -38,7 +40,7 @@ public class WorldRendererMixin {
3840

3941
@Inject(method = "drawCuboidShapeOutline(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/util/shape/VoxelShape;DDDFFFF)V", at = @At("HEAD"))
4042
private static void autoslabs$drawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, VoxelShape shape, double offsetX, double offsetY, double offsetZ, float red, float green, float blue, float alpha, CallbackInfo ci) {
41-
if (!showEnhancedSlabLines) return;
43+
if (!enableSlabLock || !showEnhancedSlabLines) return;
4244
if (clientSlabLockPosition.equals(SlabLockEnum.VANILLA_PLACEMENT)) return;
4345
Vec3d camDif = new Vec3d(offsetX, offsetY, offsetZ);
4446
if (autoslabs$captureCrosshairTarget != null && autoslabs$captureBlockState != null) {

src/main/resources/assets/autoslabs/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"auto_slabs.midnightconfig.title": "AutoSlabs",
3-
"auto_slabs.midnightconfig.suppressStatementAPILogger": "Suppress Statement API's Logger?",
43
"auto_slabs.midnightconfig.dumpResources": "Dump generated resources on boot?",
54
"auto_slabs.midnightconfig.showEnhancedSlabLines": "Show enhanced slab lines?",
5+
"auto_slabs.midnightconfig.enableSlabLock": "Placement Master Toggle",
66
"auto_slabs.midnightconfig.showCrosshairIcon": "Crosshair Icon Visibility",
77
"auto_slabs.midnightconfig.enum.ShowCrosshairIcon.ALWAYS": "Always",
88
"auto_slabs.midnightconfig.enum.ShowCrosshairIcon.ON_CHANGE": "On Change",

0 commit comments

Comments
 (0)