Skip to content

Commit 1009e89

Browse files
authored
Fix #1074: Rate limit barrel left clicking in survival mode (#1079)
1 parent 81ec378 commit 1009e89

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/client/java/aztech/modern_industrialization/proxy/ClientProxy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public boolean shouldSteamDrillForceBreakReset() {
8686
return false;
8787
}
8888

89+
@Override
90+
public void delayNextBlockAttack(Player player) {
91+
if (player == Minecraft.getInstance().player) {
92+
// Add a 5 tick delay like vanilla.
93+
Minecraft.getInstance().gameMode.destroyDelay = 5;
94+
}
95+
}
96+
8997
@Override
9098
public boolean hasShiftDown() {
9199
return Screen.hasShiftDown();

src/main/java/aztech/modern_industrialization/blocks/storage/barrel/BarrelBlock.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import aztech.modern_industrialization.blocks.storage.AbstractStorageBlock;
2727
import aztech.modern_industrialization.blocks.storage.StorageBehaviour;
28+
import aztech.modern_industrialization.proxy.CommonProxy;
2829
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant;
2930
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.transaction.Transaction;
3031
import aztech.modern_industrialization.util.MobSpawning;
@@ -152,6 +153,9 @@ public static void setupBarrelEvents() {
152153
}
153154

154155
if (attackBlock(event.getPos(), event.getFace(), event.getHand(), event.getEntity(), event.getLevel())) {
156+
// NeoForge injects in such a way that the attack will be delayed in creative already,
157+
// but we want to delay the attack in survival too to prevent the player from ending up with 5 stacks after 0.25s.
158+
CommonProxy.INSTANCE.delayNextBlockAttack(event.getEntity());
155159
event.setCanceled(true);
156160
}
157161
});

src/main/java/aztech/modern_industrialization/proxy/CommonProxy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public boolean shouldSteamDrillForceBreakReset() {
9797
return false;
9898
}
9999

100+
public void delayNextBlockAttack(Player player) {
101+
}
102+
100103
public boolean hasShiftDown() {
101104
return false;
102105
}

src/main/resources/META-INF/accesstransformer.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ public net.minecraft.world.entity.npc.VillagerTrades$ItemsForEmeralds
2929

3030
# Used for jetpack
3131
public net.minecraft.server.network.ServerGamePacketListenerImpl aboveGroundTickCount
32+
33+
# Used to delay attacks after a barrel interaction
34+
public net.minecraft.client.multiplayer.MultiPlayerGameMode destroyDelay

0 commit comments

Comments
 (0)