Skip to content

Commit

Permalink
feat: MixedSlabs (WIP)
Browse files Browse the repository at this point in the history
Working on block breaking
  • Loading branch information
xYundy committed May 1, 2024
1 parent db5d919 commit fca2207
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.xyundy.squaredadditions.mixin.client;

import pl.xyundy.squaredadditions.block.MixedSlabBlock;
import pl.xyundy.squaredadditions.slabs.PlacementUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.SlabBlock;
Expand All @@ -20,7 +21,9 @@
// https://github.com/Oliver-makes-code/autoslab/blob/1.19/src/main/java/olivermakesco/de/autoslab/mixin/Mixin_ClientPlayerInteractionManager.java
@Mixin(ClientPlayerInteractionManager.class)
public class ClientPlayerInteractionManagerMixin {
@Shadow @Final private MinecraftClient client;
@Shadow
@Final
private MinecraftClient client;

@Redirect(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean squaredadditions$tryBreakSlab(World instance, BlockPos pos, BlockState state, int flags) {
Expand All @@ -32,9 +35,28 @@ public class ClientPlayerInteractionManagerMixin {
assert clientPlayer != null;
if (clientPlayer.isSneaking()) return instance.setBlockState(pos, state, flags);

SlabType breakType = PlacementUtil.calcKleeSlab(breakState, PlacementUtil.calcRaycast(clientPlayer));
return instance.setBlockState(pos, breakState.with(SlabBlock.TYPE, breakType), flags);
SlabType remainingSlabType = PlacementUtil.calcKleeSlab(breakState, PlacementUtil.calcRaycast(clientPlayer));
return instance.setBlockState(pos, breakState.with(SlabBlock.TYPE, remainingSlabType), flags);
}

if (breakState.getBlock() instanceof MixedSlabBlock mixedSlabBlock) {
ClientPlayerEntity clientPlayer = client.player;
assert clientPlayer != null;
if (clientPlayer.isSneaking()) return instance.setBlockState(pos, state, flags);

SlabType remainingSlabType = PlacementUtil.calcKleeSlab(breakState, PlacementUtil.calcRaycast(clientPlayer));

System.out.println("client remainingSlabType: " + remainingSlabType);

return switch (remainingSlabType) {
case TOP ->
instance.setBlockState(pos, mixedSlabBlock.getTopSlabState().with(SlabBlock.TYPE, remainingSlabType), flags);
case BOTTOM ->
instance.setBlockState(pos, mixedSlabBlock.getBottomSlabState().with(SlabBlock.TYPE, remainingSlabType), flags);
case DOUBLE -> instance.setBlockState(pos, state, flags);
};
}

return instance.setBlockState(pos, state, flags);
}
}
17 changes: 9 additions & 8 deletions src/client/resources/squaredadditions.client.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"required": true,
"package": "pl.xyundy.squaredadditions.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"WorldRendererMixin"
],
"injectors": {
"defaultRequire": 1
"required": true,
"package": "pl.xyundy.squaredadditions.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"ClientPlayerInteractionManagerMixin",
"WorldRendererMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.xyundy.squaredadditions.mixin;

import pl.xyundy.squaredadditions.block.MixedSlabBlock;
import pl.xyundy.squaredadditions.slabs.PlacementUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.SlabBlock;
Expand Down Expand Up @@ -37,6 +38,25 @@ public class ServerPlayerInteractionManagerMixin {
world.setBlockState(pos, breakState.with(SlabBlock.TYPE, breakType));
return isRemoved;
}

if (breakState.getBlock() instanceof MixedSlabBlock mixedSlabBlock) {
ServerPlayerEntity serverPlayer = player;
assert serverPlayer != null;
if (serverPlayer.isSneaking()) return instance.removeBlock(pos, b);

SlabType remainingSlabType = PlacementUtil.calcKleeSlab(breakState, PlacementUtil.calcRaycast(serverPlayer));
boolean isRemoved = instance.removeBlock(pos, b);

System.out.println("server remainingSlabType: " + remainingSlabType);

switch (remainingSlabType) {
case TOP -> world.setBlockState(pos, mixedSlabBlock.getTopSlabState().with(SlabBlock.TYPE, remainingSlabType));
case BOTTOM -> world.setBlockState(pos, mixedSlabBlock.getBottomSlabState().with(SlabBlock.TYPE, remainingSlabType));
}

return isRemoved;
}

return instance.removeBlock(pos, b);
}
}

0 comments on commit fca2207

Please sign in to comment.