Skip to content

Commit 63e734d

Browse files
authored
Merge pull request #2 from AhmedMahmud/master
Fixed issues with player getting stuck at start of farm
2 parents 2b3f388 + b4d35c7 commit 63e734d

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/main/java/FarmHelper/FarmHelper.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.concurrent.Executors;
4343
import java.util.concurrent.ScheduledExecutorService;
4444
import java.util.concurrent.TimeUnit;
45-
4645
@Mod(modid = FarmHelper.MODID, name = FarmHelper.NAME, version = FarmHelper.VERSION)
4746
public class FarmHelper
4847
{
@@ -209,7 +208,7 @@ public void render(RenderGameOverlayEvent event)
209208
Utils.drawString("profit/h = " + moneyper10sec * 6 * 60, 6, 104, 0.8f, -1);
210209
}
211210

212-
mc.fontRendererObj.drawString( Utils.getFrontBlock()+ " " + Utils.getBackBlock().toString(), 4, new ScaledResolution(mc).getScaledHeight() - 20, -1);
211+
mc.fontRendererObj.drawString(Utils.getFrontBlock() + " " + Utils.getBackBlock().toString() + " " + Utils.getRightBlock().toString() + " " + Utils.getLeftBlock().toString(), 4, new ScaledResolution(mc).getScaledHeight() - 20, -1);
213212

214213

215214
}
@@ -300,15 +299,22 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player
300299
KeyBinding.setKeyBindState(keybindD, true);
301300
Thread.sleep(300);
302301
KeyBinding.setKeyBindState(keybindD, false);
302+
Thread.sleep(300);
303+
303304
if(Config.FarmType == FarmEnum.LAYERED){
304305
if(isWalkable(Utils.getFrontBlock())) {
305306
initialX = (int)mc.thePlayer.posX;
306307
initialZ = (int)mc.thePlayer.posZ;
307308
process3 = true;
308309
}
310+
Utils.debugLog(mc.thePlayer, "Checking if stuck at start");
311+
if (!isWalkable(Utils.getFrontBlock()) && !isWalkable(Utils.getBackBlock()) && !isWalkable(Utils.getRightBlock()) && isWalkable(Utils.getLeftBlock())) {
312+
Utils.debugLog(mc.thePlayer, "Stuck at start of farm, changing direction");
313+
ExecuteRunnable(changeMotion);
314+
Utils.debugLog(mc.thePlayer, "Changed direction");
315+
}
309316
}
310317
ExecuteRunnable(stopAntistuck);
311-
312318
//exec
313319
}catch(Exception e){
314320
e.printStackTrace();
@@ -509,6 +515,7 @@ public void run() {
509515
}
510516
};
511517

518+
512519
Runnable changeLayer = () -> {
513520
if(!notInIsland && !emergency) {
514521
try {
@@ -521,17 +528,27 @@ public void run() {
521528
Utils.smoothRotateClockwise(180);
522529
Thread.sleep(2000);
523530
rotating = false;
531+
532+
// After 180 you are at back of trench, hold W for some time to go to front
533+
KeyBinding.setKeyBindState(keybindW, true);
534+
Thread.sleep(500);
535+
KeyBinding.setKeyBindState(keybindW, false);
536+
524537
enabled = true;
525538
}catch(Exception e){
526539
e.printStackTrace();
527540
}
541+
528542
}
529543
};
530544

531545
Runnable changeMotion = () -> {
546+
Utils.debugLog(mc.thePlayer, "Trying to change motion");
532547
if(!notInIsland && !emergency) {
533548
process1 = !process1;
534549
process2 = !process2;
550+
Utils.debugLog(mc.thePlayer, "1:" + process1 + ", 2: " + process2 + ", 3: " + process3 + ", 4: " + process4);
551+
Utils.debugLog(mc.thePlayer, "Motion function: changed");
535552
set = false;
536553
}
537554
};
@@ -736,13 +753,17 @@ void clickWindow(int windowID, int slotID, int mouseButtonClicked, int mode) thr
736753
}
737754
}
738755
void initialize(){
756+
Utils.debugLog(mc.thePlayer, "Initializing");
739757
deltaX = 10000;
740758
deltaZ = 10000;
741759
deltaY = 0;
742760

743-
744761
process1 = true;
745762
process2 = false;
763+
if (!isWalkable(Utils.getFrontBlock()) && !isWalkable(Utils.getBackBlock()) && !isWalkable(Utils.getRightBlock()) && isWalkable(Utils.getLeftBlock())) {
764+
process1 = false;
765+
process2 = true;
766+
}
746767
process3 = false;
747768
process4 = false;
748769
if(Config.FarmType == FarmEnum.LAYERED){
@@ -751,7 +772,6 @@ void initialize(){
751772
}
752773
}
753774

754-
755775
setspawned = false;
756776
shdBePressingKey = true;
757777
notInIsland = false;

src/main/java/FarmHelper/utils/Utils.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import FarmHelper.config.Config;
44
import net.minecraft.block.Block;
55
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.entity.EntityPlayerSP;
67
import net.minecraft.client.gui.Gui;
78
import net.minecraft.client.renderer.GlStateManager;
89
import net.minecraft.inventory.Slot;
910
import net.minecraft.util.BlockPos;
11+
import net.minecraft.util.ChatComponentText;
12+
import net.minecraft.util.EnumChatFormatting;
1013

1114
import java.util.Random;
1215

@@ -203,6 +206,22 @@ public static Block getBackBlock(){
203206
new BlockPos(mc.thePlayer.getLookVec().xCoord * -1 + mc.thePlayer.posX, mc.thePlayer.posY,
204207
mc.thePlayer.getLookVec().zCoord * -1 + mc.thePlayer.posZ)).getBlock());
205208
}
206-
207-
209+
public static Block getRightBlock(){
210+
Minecraft mc = Minecraft.getMinecraft();
211+
return (mc.theWorld.getBlockState(
212+
new BlockPos(mc.thePlayer.getLookVec().zCoord * -1 + mc.thePlayer.posX, mc.thePlayer.posY,
213+
mc.thePlayer.getLookVec().xCoord + mc.thePlayer.posZ)).getBlock());
214+
}
215+
public static Block getLeftBlock(){
216+
Minecraft mc = Minecraft.getMinecraft();
217+
return (mc.theWorld.getBlockState(
218+
new BlockPos(mc.thePlayer.getLookVec().zCoord + mc.thePlayer.posX, mc.thePlayer.posY,
219+
mc.thePlayer.getLookVec().xCoord * -1 + mc.thePlayer.posZ)).getBlock());
220+
}
221+
public static void debugLog(EntityPlayerSP player, String message) {
222+
if (false) {
223+
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
224+
"[Debug]: " + EnumChatFormatting.DARK_GREEN + message));
225+
}
226+
}
208227
}

0 commit comments

Comments
 (0)