Skip to content

Commit

Permalink
Update to 1.12
Browse files Browse the repository at this point in the history
Add Entity Clear protection feature
  • Loading branch information
freneticfeline committed Jun 30, 2017
1 parent fe64506 commit 261dd93
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.12-1.3
========
Update to work on Minecraft/Forge 1.12
Added experimental Entity Clear protection

1.11-1.2
========
Update to work on Minecraft/Forge 1.11.2
Expand Down
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}

apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.

version = "1.11-1.2"
version = "1.12-1.3"
group= "net.unladenswallow.minecraft.autofish" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "mod_autofish_forge"

minecraft {
version = "1.11.2-13.20.0.2228"
version = "1.12-14.21.1.2387"
runDir = "eclipse"

// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not allways work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20161220"
mappings = "snapshot_20170624"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
Expand All @@ -20,9 +21,25 @@ public class AutoFishEventHandler {
private EntityPlayer player;
private long castScheduledAt = 0L;
private long startedReelDelayAt = 0L;
private long startedCastDelayAt = 0L;
private boolean isFishing = false;

/** How long to wait after reeling in a catch before casting again */
private static final int CAST_QUEUE_TICK_DELAY = 30;

/** How long to suppress checking for a bite after starting to reel in. If we check for a bite while reeling
in, we may think we have a bite and try to reel in again, which will actually cause a re-cast and lose the fish */
private static final int REEL_TICK_DELAY = 5;

/** How long to wait after casting to check for Entity Clear. If we check too soon, the hook entity
isn't in the world yet, and will trigger a false alarm and cause infinite recasting. */
private static final int CAST_TICK_DELAY = 5;

/** When Break Prevention is enabled, how low to let the durability get before stopping or switching rods */
private static final int AUTOFISH_BREAKPREVENT_THRESHOLD = 2;

/** The threshold for vertical movement of the fish hook that determines when a fish is biting, if using
the movement method of detection. */
private static final double MOTION_Y_THRESHOLD = -0.05d;

@SubscribeEvent
Expand All @@ -31,25 +48,57 @@ public void onClientTickEvent(ClientTickEvent event) {
if (ModAutoFish.config_autofish_enable && !this.minecraft.isGamePaused() && this.minecraft.player != null) {
this.player = this.minecraft.player;

if (playerHookInWater() && !isDuringReelDelay() && isFishBiting()) {
startReelDelay();
playerUseRod();
scheduleNextCast();
} else if (isTimeToCast()) {
if (needToSwitchRods()) {
tryToSwitchRods();
if (playerIsHoldingRod()) {
if (playerHookInWater() && !isDuringReelDelay() && isFishBiting()) {
startReelDelay();
reelIn();
scheduleNextCast();
} else if (isTimeToCast()) {
if (needToSwitchRods()) {
tryToSwitchRods();
}
if (playerCanCast()) {
startFishing();
}
// Resetting these values is not strictly necessary, but will improve the performance
// of the check that potentially occurs every tick.
resetReelDelay();
resetCastSchedule();
}
if (playerCanCast()) {
playerUseRod();

if (ModAutoFish.config_autofish_entityClearProtect && this.isFishing && !isDuringCastDelay() && this.player.fishEntity == null) {
AutoFishLogger.info("Entity Clear detected. Re-casting.");
this.isFishing = false;
startFishing();
}
// Resetting these values is not strictly necessary, but will improve the performance
// of the check that potentially occurs every tick.
resetReelDelay();
resetCastSchedule();

} else {
this.isFishing = false;
}
}
}

@SubscribeEvent
public void onPlayerUseItem(PlayerInteractEvent.RightClickItem event) {
// Only do this on the client side
if (event.getWorld().isRemote && playerIsHoldingRod()) {
this.isFishing = !this.isFishing;
// AutoFishLogger.info("Player %s fishing", this.isFishing ? "started" : "stopped");
if (this.isFishing) {
startCastDelay();
}
}
}

private void reelIn() {
playerUseRod();
}

private void startFishing() {
playerUseRod();
startCastDelay();
}

private void resetCastSchedule() {
this.castScheduledAt = 0;
}
Expand All @@ -70,6 +119,13 @@ private void startReelDelay() {
this.startedReelDelayAt = this.minecraft.world.getTotalWorldTime();
}

/*
* Trigger a delay so that entity clear protection doesn't kick in during cast.
*/
private void startCastDelay() {
this.startedCastDelayAt = this.minecraft.world.getTotalWorldTime();
}

private void resetReelDelay() {
startedReelDelayAt = 0;
}
Expand All @@ -78,6 +134,10 @@ private boolean isDuringReelDelay() {
return (this.startedReelDelayAt != 0 && this.minecraft.world.getTotalWorldTime() < this.startedReelDelayAt + REEL_TICK_DELAY);
}

private boolean isDuringCastDelay() {
return (this.startedCastDelayAt != 0 && this.minecraft.world.getTotalWorldTime() < this.startedCastDelayAt + CAST_TICK_DELAY);
}

private boolean playerHookInWater() {
return this.player.fishEntity != null
&& this.player.fishEntity.isInWater();
Expand Down Expand Up @@ -111,6 +171,7 @@ private boolean isFishBiting() {
private boolean isFishBiting_fromMovement() {
EntityFishHook fishEntity = this.player.fishEntity;
if (fishEntity != null
// Checking for no X and Z motion prevents a false alarm when the hook is moving through the air
&& fishEntity.motionX == 0
&& fishEntity.motionZ == 0
&& fishEntity.motionY < MOTION_Y_THRESHOLD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ public class AutoFishGuiFactory implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) {
// TODO Auto-generated method stub

}

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
// TODO Auto-generated method stub
return AutoFishConfigGui.class;
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}

@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
// TODO Auto-generated method stub
return null;
public boolean hasConfigGui() {
return true;
}

@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
// TODO Auto-generated method stub
return null;
public GuiScreen createConfigGui(GuiScreen parentScreen) {
return new AutoFishConfigGui(parentScreen);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = ModAutoFish.MODID, useMetadata = true, acceptedMinecraftVersions="[1.11,1.12)", acceptableRemoteVersions="[1.11,1.12)",
@Mod(modid = ModAutoFish.MODID, useMetadata = true, acceptedMinecraftVersions="[1.12,1.13)", acceptableRemoteVersions="[1.12,1.13)",
guiFactory = "net.unladenswallow.minecraft.autofish.AutoFishGuiFactory")
public class ModAutoFish {
public static final String MODID = "mod_autofish";
Expand All @@ -19,6 +19,8 @@ public class ModAutoFish {
public static final boolean CONFIG_DEFAULT_AUTOFISH_MULTIROD = false;
public static boolean config_autofish_preventBreak;
public static final boolean CONFIG_DEFAULT_AUTOFISH_PREVENTBREAK = false;
public static boolean config_autofish_entityClearProtect;
public static final boolean CONFIG_DEFAULT_AUTOFISH_ENTITYCLEARPROTECT = false;

@SidedProxy(clientSide="net.unladenswallow.minecraft.autofish.ClientProxy", serverSide="net.unladenswallow.minecraft.autofish.ServerProxy")
public static CommonProxy proxy;
Expand All @@ -44,6 +46,7 @@ public static void syncConfig() {
config_autofish_enable = configFile.getBoolean("Enable AutoFish", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_ENABLE, "Automatically reel in and re-cast when a fish nibbles the hook.");
config_autofish_multirod = configFile.getBoolean("Enable MultiRod", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_MULTIROD, "Automatically switch to a new fishing rod when the current rod breaks, if one is available in the hotbar.");
config_autofish_preventBreak = configFile.getBoolean("Enable Break Protection", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_PREVENTBREAK, "Stop fishing or switch to a new rod before the current rod breaks.");
config_autofish_entityClearProtect = configFile.getBoolean("Enable Enity Clear Protection", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_ENTITYCLEARPROTECT, "Re-cast after the server clears entities. EXPERIMENTAL");

if (configFile.hasChanged()) {
configFile.save();
Expand Down

0 comments on commit 261dd93

Please sign in to comment.