Break individual slabs when sneaking (closes #218)

This commit is contained in:
BillyGalbreath
2021-03-23 21:15:38 -05:00
parent c3de3ac665
commit 26a009422e

View File

@@ -0,0 +1,74 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Tue, 23 Mar 2021 19:38:53 -0500
Subject: [PATCH] Break individual slabs when sneaking
diff --git a/src/main/java/net/minecraft/server/level/PlayerInteractManager.java b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
index e47a743fd3adc62aa47beec722f49eeaded246bc..5fa689a799f0016fb92fdb5134e13d512d3c63ff 100644
--- a/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
@@ -409,6 +409,8 @@ public class PlayerInteractManager {
}
return false;
}
+
+ if (this.player.world.purpurConfig.slabHalfBreak && iblockdata.getBlock() instanceof net.minecraft.world.level.block.BlockStepAbstract && ((net.minecraft.world.level.block.BlockStepAbstract) iblockdata.getBlock()).halfBreak(iblockdata, blockposition, this.player)) return true; // Purpur
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/block/BlockStepAbstract.java b/src/main/java/net/minecraft/world/level/block/BlockStepAbstract.java
index 12c0fa5072755fd2a4f575b0cc5e4222617490ce..94965b216d50b29b95f09fa9019c177b9c099e14 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockStepAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockStepAbstract.java
@@ -27,7 +27,7 @@ import net.minecraft.world.phys.shapes.VoxelShapes;
public class BlockStepAbstract extends Block implements IBlockWaterlogged {
- public static final BlockStateEnum<BlockPropertySlabType> a = BlockProperties.aK;
+ public static final BlockStateEnum<BlockPropertySlabType> a = BlockProperties.aK; public static BlockStateEnum<BlockPropertySlabType> slabType() { return a; } // Purpur - OBFHELPER
public static final BlockStateBoolean b = BlockProperties.C;
protected static final VoxelShape c = Block.a(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D);
protected static final VoxelShape d = Block.a(0.0D, 8.0D, 0.0D, 16.0D, 16.0D, 16.0D);
@@ -134,4 +134,25 @@ public class BlockStepAbstract extends Block implements IBlockWaterlogged {
return false;
}
}
+
+ // Purpur start
+ public boolean halfBreak(IBlockData iblockdata, BlockPosition pos, net.minecraft.server.level.EntityPlayer player) {
+ if (iblockdata.get(BlockStepAbstract.slabType()) != BlockPropertySlabType.DOUBLE) {
+ return false;
+ }
+ net.minecraft.world.phys.MovingObjectPosition result = player.getRayTrace(16);
+ if (result == null) {
+ return false;
+ }
+ double hitY = result.getPos().getY();
+ int blockY = org.bukkit.util.NumberConversions.floor(hitY);
+ player.world.setTypeAndData(pos, iblockdata.set(BlockStepAbstract.slabType(), (hitY - blockY > 0.5 || blockY - pos.getY() == 1) ? BlockPropertySlabType.BOTTOM : BlockPropertySlabType.TOP), 3);
+ if (!player.abilities.canInstantlyBuild) {
+ net.minecraft.world.entity.item.EntityItem item = new net.minecraft.world.entity.item.EntityItem(player.world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(getItem()));
+ item.defaultPickupDelay();
+ player.world.addEntity(item);
+ }
+ return true;
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index b0f6d5dae50f5689ef41b766a590ca5a26834fc2..62f52be341a0ddec165bb9b24e2f4ed97e145104 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -517,6 +517,11 @@ public class PurpurWorldConfig {
signRightClickEdit = getBoolean("blocks.sign.right-click-edit", signRightClickEdit);
}
+ public boolean slabHalfBreak = false;
+ private void slabSettings() {
+ slabHalfBreak = getBoolean("blocks.slab.break-individual-slabs-when-sneaking", slabHalfBreak);
+ }
+
public boolean spawnerDeactivateByRedstone = false;
private void spawnerSettings() {
spawnerDeactivateByRedstone = getBoolean("blocks.spawner.deactivate-by-redstone", spawnerDeactivateByRedstone);