Skip to content

Commit d5492d6

Browse files
committed
Mining ghost block fix
1 parent 0f6d751 commit d5492d6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main/java/net/earthcomputer/clientcommands/TempRules.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class TempRules {
3030
Boolean.FALSE);
3131
public static final Rule<Boolean> MOCKING_TIME = registerRule("mockingTime", DataType.BOOLEAN, Boolean.FALSE)
3232
.setReadOnly();
33+
public static final Rule<Boolean> GHOST_BLOCK_FIX = registerRule("ghostBlockFix", DataType.BOOLEAN, Boolean.TRUE);
3334

3435
public static boolean hasRule(String name) {
3536
return rules.containsKey(name);

src/main/java/net/earthcomputer/clientcommands/TempRulesImpl.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package net.earthcomputer.clientcommands;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.concurrent.atomic.AtomicInteger;
46

7+
import net.minecraft.block.material.Material;
8+
import net.minecraft.block.state.IBlockState;
59
import net.minecraft.client.Minecraft;
10+
import net.minecraft.client.multiplayer.PlayerControllerMP;
611
import net.minecraft.client.resources.I18n;
712
import net.minecraft.enchantment.EnchantmentHelper;
813
import net.minecraft.entity.player.EntityPlayer;
914
import net.minecraft.init.Enchantments;
1015
import net.minecraft.inventory.ClickType;
16+
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
17+
import net.minecraft.util.EnumFacing;
18+
import net.minecraft.util.EnumHand;
19+
import net.minecraft.util.math.BlockPos;
1120

1221
public class TempRulesImpl {
1322

@@ -17,6 +26,7 @@ private TempRulesImpl() {
1726
public static void registerEvents() {
1827
initBlockReachDistance();
1928
initToolBreakProtection();
29+
initGhostBlockFix();
2030
}
2131

2232
private static void initBlockReachDistance() {
@@ -61,4 +71,31 @@ private static void initToolBreakProtection() {
6171
});
6272
}
6373

74+
private static List<BlockPos> blocksToUpdate = new ArrayList<>();
75+
76+
private static void initGhostBlockFix() {
77+
EventManager.addAttackBlockListener(e -> {
78+
if (TempRules.GHOST_BLOCK_FIX.getValue()) {
79+
// Test conditions for instant-mining
80+
PlayerControllerMP controller = Minecraft.getMinecraft().playerController;
81+
IBlockState state = e.getWorld().getBlockState(e.getPos());
82+
boolean slowMine = state.getMaterial() != Material.AIR
83+
&& state.getPlayerRelativeBlockHardness(e.getEntityPlayer(), e.getWorld(), e.getPos()) >= 1;
84+
if (controller.isNotCreative() && !slowMine) {
85+
blocksToUpdate.add(e.getPos());
86+
}
87+
}
88+
});
89+
EventManager.addPlayerTickListener(e -> {
90+
if (!blocksToUpdate.isEmpty()) {
91+
for (BlockPos pos : blocksToUpdate) {
92+
// Update block by right clicking
93+
Minecraft.getMinecraft().getConnection().sendPacket(
94+
new CPacketPlayerTryUseItemOnBlock(pos, EnumFacing.DOWN, EnumHand.MAIN_HAND, 0, 0, 0));
95+
}
96+
blocksToUpdate.clear();
97+
}
98+
});
99+
}
100+
64101
}

0 commit comments

Comments
 (0)