Skip to content

Commit

Permalink
Merge pull request #210 from CatalizCS/master
Browse files Browse the repository at this point in the history
Fastbreak - Add random chance, optimize logic
  • Loading branch information
onixiya1337 authored Mar 14, 2024
2 parents b5eeddd + ed3e8d2 commit 372b7f6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,19 @@ public enum SPRAYONATOR_ITEM {
)
public static boolean fastBreak = false;

@Switch(
name = "Enable Fast Break Randomization", category = EXPERIMENTAL, subcategory = "Fast Break",
description = "Randomizes the Fast Break chance"
)
public static boolean fastBreakRandomization = false;

@Slider(
name = "Fast Break Randomization Chance", category = EXPERIMENTAL, subcategory = "Fast Break",
description = "The chance to break the block",
min = 1, max = 100, step = 1
)
public static int fastBreakRandomizationChance = 5;

@Info(
text = "Fast Break will most likely ban you. Use at your own risk.",
type = InfoType.ERROR,
Expand Down Expand Up @@ -1956,6 +1969,8 @@ public FarmHelperConfig() {
this.addDependency("streamerModeInfo2", "debugMode");

this.addDependency("fastBreakSpeed", "fastBreak");
this.addDependency("fastBreakRandomization", "fastBreak");
this.addDependency("fastBreakRandomizationChance", "fastBreak");
this.addDependency("disableFastBreakDuringBanWave", "fastBreak");
this.addDependency("disableFastBreakDuringJacobsContest", "fastBreak");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockNetherWart;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
Expand Down Expand Up @@ -63,34 +62,52 @@ private void sendClickBlockToController(CallbackInfo ci) {
}

boolean shouldClick = this.currentScreen == null && this.gameSettings.keyBindAttack.isKeyDown() && this.inGameHasFocus;
if (this.objectMouseOver != null && shouldClick)
for (int i = 0; i < FarmHelperConfig.fastBreakSpeed + 1; i++) {
BlockPos clickedBlock = this.objectMouseOver.getBlockPos();
this.objectMouseOver = this.renderViewEntity.rayTrace(this.playerController.getBlockReachDistance(), 1.0F);

if (this.objectMouseOver == null || this.objectMouseOver.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
break;
}
if (this.objectMouseOver != null && shouldClick) {
boolean isCactus = false;

// checking first block
BlockPos newBlock = this.objectMouseOver.getBlockPos();
Block blockTryBreak = this.theWorld.getBlockState(newBlock).getBlock();

if (!newBlock.equals(clickedBlock)
&& (blockTryBreak instanceof BlockCrops ||
blockTryBreak instanceof BlockNetherWart ||
blockTryBreak == Blocks.reeds ||
blockTryBreak == Blocks.cactus ||
blockTryBreak == Blocks.brown_mushroom ||
blockTryBreak == Blocks.red_mushroom ||
blockTryBreak == Blocks.pumpkin ||
blockTryBreak == Blocks.melon_block ||
blockTryBreak == Blocks.cocoa)
) {
for (int i = 0; i < FarmHelperConfig.fastBreakSpeed + 1; i++) {
// try catch when player break block and the block is not exist(ghost block?) or some player in front of the block
try {
if (FarmHelperConfig.fastBreakRandomization && (Math.random() * 100 < (100 - FarmHelperConfig.fastBreakRandomizationChance))) {
break;
}

BlockPos clickedBlock = this.objectMouseOver.getBlockPos();
Block block = this.theWorld.getBlockState(clickedBlock).getBlock();
this.objectMouseOver = this.renderViewEntity.rayTrace(this.playerController.getBlockReachDistance(), 1.0F);

if (block == Blocks.cactus) {
isCactus = true;
} else {
isCactus = false;
}

if (this.objectMouseOver == null || this.objectMouseOver.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
break;
}

BlockPos newBlock = this.objectMouseOver.getBlockPos();
Block blockTryBreak = this.theWorld.getBlockState(newBlock).getBlock();

if (this.theWorld.getBlockState(newBlock).getBlock().getPlayerRelativeBlockHardness(this.thePlayer, this.theWorld, clickedBlock) < 1.0F) {
return;
}

if (isCactus) {
this.playerController.resetBlockRemoving();
}

if (newBlock == null || this.objectMouseOver.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK || newBlock.equals(clickedBlock) || blockTryBreak.getMaterial() == Material.air) {
break;
}

this.thePlayer.swingItem();
this.playerController.clickBlock(newBlock, this.objectMouseOver.sideHit);
}
} catch (Exception ignored) {

if (i % 3 == 0) this.thePlayer.swingItem();
}
}

}
}
}

0 comments on commit 372b7f6

Please sign in to comment.