Skip to content

Commit

Permalink
Mostly works
Browse files Browse the repository at this point in the history
  • Loading branch information
freneticfeline committed Jun 11, 2019
1 parent cf6d323 commit 4c392c6
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 229 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = "1.13-1.7"
version = "1.13-1.7b"
group= "net.unladenswallow.minecraft.autofish" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "mod_autofish_forge"

Expand Down Expand Up @@ -69,7 +69,7 @@ dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.13.2-25.0.191'
minecraft 'net.minecraftforge:forge:1.13.2-25.0.219'

// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
Expand Down
136 changes: 68 additions & 68 deletions src/main/java/net/unladenswallow/minecraft/autofish/AutoFish.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
//import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
Expand All @@ -10,24 +11,13 @@
import net.unladenswallow.minecraft.autofish.config.AutoFishModConfig;
import net.unladenswallow.minecraft.autofish.events.EventListener;
import net.unladenswallow.minecraft.autofish.events.KeyInputHandler;
//import net.unladenswallow.minecraft.autofish.gui.ConfigGui;
import net.unladenswallow.minecraft.autofish.util.Logger;

@Mod(ModAutoFish.MODID)
//@Mod.EventBusSubscriber(modid = ModAutoFish.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModAutoFish {
public static final String MODID = "mod_autofish";

// private static final List<String> propertyOrder = new ArrayList<String>(Arrays.asList(new String[] {
// "Enable AutoFish",
// "Enable MultiRod",
// "Enable Break Protection",
// "Re-Cast Delay",
// "Enable Entity Clear Protection",
// "Enable Aggressive Bite Detection",
// "Handle Problems",
// "Enable Fast Fishing"
// }));

public static AutoFish autoFish = new AutoFish();
public static EventListener eventListener = new EventListener(autoFish);

Expand All @@ -40,6 +30,7 @@ public ModAutoFish() {
FMLJavaModLoadingContext.get().getModEventBus().register(AutoFishModConfig.class);
MinecraftForge.EVENT_BUS.register(this);
AutoFishModConfig.register(ModLoadingContext.get());
// ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (mc, screen) -> new ConfigGui(screen));
}

@SubscribeEvent
Expand All @@ -53,19 +44,4 @@ public void clientInit (final FMLClientSetupEvent event) {
MinecraftForge.EVENT_BUS.register(new KeyInputHandler());
}

// 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. If set to false, all other AutoFish functionality is disabled.");
// 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 just before the current rod breaks. Useful if you want to repair your enchanted fishing rods.");
// config_autofish_entityClearProtect = configFile.getBoolean("Enable Entity Clear Protection", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_ENTITYCLEARPROTECT, "When playing on a server, re-cast after the server clears entities. Useful if you are playing on a server that periodically deletes all entities (including fishing hooks) from the world, which causes you to stop fishing.");
// config_autofish_recastDelay = configFile.getInt("Re-Cast Delay", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_RECASTDELAY, 1, 10, "Time (in seconds) to wait before automatically re-casting. Increase this value if server lag causes re-casting to fail.");
// config_autofish_fastFishing = configFile.getBoolean("Enable Fast Fishing", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_FASTFISHING, "[SINGLE PLAYER ONLY] Fish will bite right after casting.");
// config_autofish_aggressiveBiteDetection = configFile.getBoolean("Enable Aggressive Bite Detection", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_AGGRESSIVEBITEDETECTION, "When playing on a server, be more aggressive about detecting fish bites. Improves multiplayer bite detection from ~85% to ~95%, but false positives will be more likely, especially if other players are fishing very close by.");
// config_autofish_handleProblems = configFile.getBoolean("Handle Problems", Configuration.CATEGORY_GENERAL, CONFIG_DEFAULT_AUTOFISH_HANDLEPROBLEMS, "[HAS SIDE EFFECTS] Re-cast when problems detected (e.g. if not in water or if a MOB has been hooked). If enabled, non-fishing use of the fishing rod (e.g. intentionally hooking MOBs) will be affected.");
//
// if (configFile.hasChanged()) {
// configFile.save();
// }
// }

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
package net.unladenswallow.minecraft.autofish.config;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.google.common.base.Joiner;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.config.ModConfig;
import net.unladenswallow.minecraft.autofish.config.ConfigOption.ValueType;
import net.unladenswallow.minecraft.autofish.util.Logger;
import net.minecraftforge.fml.ModLoadingContext;

public class AutoFishModConfig {
/*
* This is probably an overly-complicated way of handling configs, but I can't for the
* life of me figure out how to write changes to the config file any other way.
*/

private static final boolean CONFIG_DEFAULT_AUTOFISH_ENABLE = true;
private static final boolean CONFIG_DEFAULT_AUTOFISH_MULTIROD = false;
private static final boolean CONFIG_DEFAULT_AUTOFISH_PREVENTBREAK = false;
private static final boolean CONFIG_DEFAULT_AUTOFISH_ENTITYCLEARPROTECT = false;
private static final int CONFIG_DEFAULT_AUTOFISH_RECASTDELAY = 2;
private static final boolean CONFIG_DEFAULT_AUTOFISH_FASTFISHING = false;
private static final boolean CONFIG_DEFAULT_AUTOFISH_AGGRESSIVEBITEDETECTION = false;
private static final boolean CONFIG_DEFAULT_AUTOFISH_HANDLEPROBLEMS = false;

private static final Joiner DotJoiner = Joiner.on(".");
private static final ForgeConfigSpec clientSpec;
public static final ClientConfig CLIENT;
private static final ClientConfig CLIENT;
private static String ConfigFilePath;
private static List<ConfigOption> configOptions;

static {
final Pair<ClientConfig, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new);
Expand All @@ -21,28 +44,20 @@ public class AutoFishModConfig {
}

public static class ClientConfig {
public static BooleanValue config_autofish_enable;
private static final boolean CONFIG_DEFAULT_AUTOFISH_ENABLE = true;
public static BooleanValue config_autofish_multirod;
private static final boolean CONFIG_DEFAULT_AUTOFISH_MULTIROD = false;
public static BooleanValue config_autofish_preventBreak;
private static final boolean CONFIG_DEFAULT_AUTOFISH_PREVENTBREAK = false;
public static BooleanValue config_autofish_entityClearProtect;
private static final boolean CONFIG_DEFAULT_AUTOFISH_ENTITYCLEARPROTECT = false;
public static IntValue config_autofish_recastDelay;
private static final int CONFIG_DEFAULT_AUTOFISH_RECASTDELAY = 2;
public static BooleanValue config_autofish_fastFishing;
private static final boolean CONFIG_DEFAULT_AUTOFISH_FASTFISHING = false;
public static BooleanValue config_autofish_aggressiveBiteDetection;
private static final boolean CONFIG_DEFAULT_AUTOFISH_AGGRESSIVEBITEDETECTION = false;
public static BooleanValue config_autofish_handleProblems;
private static final boolean CONFIG_DEFAULT_AUTOFISH_HANDLEPROBLEMS = false;
public BooleanValue config_autofish_enable;
public BooleanValue config_autofish_multirod;
public BooleanValue config_autofish_preventBreak;
public BooleanValue config_autofish_entityClearProtect;
public IntValue config_autofish_recastDelay;
public BooleanValue config_autofish_fastFishing;
public BooleanValue config_autofish_aggressiveBiteDetection;
public BooleanValue config_autofish_handleProblems;

ClientConfig(final ForgeConfigSpec.Builder builder) {
builder.comment("Client config settings")
.push("client");
config_autofish_enable = builder
.comment("Enable AutoFish")
.comment("Enable AutoFish", "Automatically reel in and re-cast when a fish nibbles the hook. If set to false, all other AutoFish functionality is disabled.")
.define("config_autofish_enable", CONFIG_DEFAULT_AUTOFISH_ENABLE);
config_autofish_multirod = builder
.comment("Enable MultiRod")
Expand Down Expand Up @@ -74,15 +89,117 @@ public static void register(final ModLoadingContext context) {
context.registerConfig(ModConfig.Type.CLIENT, clientSpec);
}



@SubscribeEvent
public static void onLoad(final ModConfig.Loading configEvent) {
Logger.debug("Loaded AutoFishMod config file {}", configEvent.getConfig().getFileName());
Logger.info("Loaded AutoFishMod config file {}", configEvent.getConfig().getFileName());
ConfigFilePath = configEvent.getConfig().getFullPath().toString();
configOptions = new ArrayList<ConfigOption>();
configOptions.add(new ConfigOption(CLIENT.config_autofish_enable.getPath(), CLIENT.config_autofish_enable.get(), "AutoFish"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_multirod.getPath(), CLIENT.config_autofish_multirod.get(), "MultiRod"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_preventBreak.getPath(), CLIENT.config_autofish_preventBreak.get(), "Break Protection"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_recastDelay.getPath(), CLIENT.config_autofish_recastDelay.get(), "Re-Cast Delay"));
// configOptions.add(new ConfigOption(CLIENT.config_autofish_entityClearProtect.getPath(), CLIENT.config_autofish_entityClearProtect.get(), "Entity Clear Protection"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_aggressiveBiteDetection.getPath(),CLIENT.config_autofish_aggressiveBiteDetection.get(), "Aggressive Bite Detection"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_handleProblems.getPath(), CLIENT.config_autofish_handleProblems.get(), "Handle Problems"));
configOptions.add(new ConfigOption(CLIENT.config_autofish_fastFishing.getPath(), CLIENT.config_autofish_fastFishing.get(), "Fast Fishing"));
}

@SubscribeEvent
public static void onFileChange(final ModConfig.ConfigReloading configEvent) {
Logger.fatal("AutoFishMod config just got changed on the file system!");
public static List<ConfigOption> getOrderedConfigValues() {
return configOptions;
}



public static void toggleConfigValue(List<String> configPath) {
ConfigOption option = findConfigOption(configPath);
if (option == null) {
Logger.warning("Unknown config option path: %s", configPath);
}
if (option.valueType == ValueType.BOOL) {
option.boolValue = !option.boolValue;
saveConfigChange(option.configPath, option.boolValue);
} else if (option.valueType == ValueType.INT) {
int minVal, maxVal;
if (DotJoiner.join(option.configPath).equals(DotJoiner.join(CLIENT.config_autofish_recastDelay.getPath()))) {
minVal = 1;
maxVal = 10;
} else {
minVal = 0;
maxVal = 0;
}
option.intValue++;
if (option.intValue > maxVal) {
option.intValue = minVal;
}
saveConfigChange(option.configPath, option.intValue);
}
}


private static void saveConfigChange(List<String> configPath, boolean newValue) {
CommentedFileConfig commentedFileConfig = CommentedFileConfig.of(AutoFishModConfig.ConfigFilePath);
commentedFileConfig.load();
commentedFileConfig.set(configPath, newValue);
AutoFishModConfig.clientSpec.setConfig(commentedFileConfig);
commentedFileConfig.save();
commentedFileConfig.close();
}

private static void saveConfigChange(List<String> configPath, int newValue) {
CommentedFileConfig commentedFileConfig = CommentedFileConfig.of(AutoFishModConfig.ConfigFilePath);
commentedFileConfig.load();
commentedFileConfig.set(configPath, newValue);
AutoFishModConfig.clientSpec.setConfig(commentedFileConfig);
commentedFileConfig.save();
commentedFileConfig.close();
}

private static ConfigOption findConfigOption(List<String> configPath) {
if (configPath == null) return null;

for (ConfigOption option : configOptions) {
if (option.configPath.equals(configPath)) {
return option;
}
}

return null;
}

public static boolean autofishEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_enable.getPath());
return option == null ? false : option.boolValue;
}
public static boolean multiRodEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_multirod.getPath());
return option == null ? false : option.boolValue;
}
public static boolean breakPreventEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_preventBreak.getPath());
return option == null ? false : option.boolValue;
}
public static boolean entityClearProtectEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_entityClearProtect.getPath());
return option == null ? false : option.boolValue;
}
public static boolean fashFishingEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_fastFishing.getPath());
return option == null ? false : option.boolValue;
}
public static boolean aggressiveBiteDetectionEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_aggressiveBiteDetection.getPath());
return option == null ? false : option.boolValue;
}
public static boolean handleProblemsEnabled() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_handleProblems.getPath());
return option == null ? false : option.boolValue;
}
public static int recastDelay() {
ConfigOption option = findConfigOption(CLIENT.config_autofish_recastDelay.getPath());
return option == null ? CONFIG_DEFAULT_AUTOFISH_RECASTDELAY : option.intValue;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.unladenswallow.minecraft.autofish.config;

import java.util.List;

public class ConfigOption {
public ConfigOption(List<String> path, boolean value, String label) {
valueType = ValueType.BOOL;
configPath = path;
boolValue = value;
configLabel = label;
}

public ConfigOption(List<String> path, int value, String label) {
valueType = ValueType.INT;
configPath = path;
intValue = value;
configLabel = label;
}

public enum ValueType {
BOOL,
INT
}

public ValueType valueType;
public List<String> configPath;
public boolean boolValue;
public int intValue;
public String configLabel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.unladenswallow.minecraft.autofish.AutoFish;
import net.unladenswallow.minecraft.autofish.ModAutoFish;
import net.unladenswallow.minecraft.autofish.config.AutoFishModConfig;
import net.unladenswallow.minecraft.autofish.util.Logger;

public class EventListener implements IWorldEventListener {

Expand All @@ -47,7 +46,7 @@ public EventListener(AutoFish autoFish) {
*/
@SubscribeEvent
public void onClientTickEvent(ClientTickEvent event) {
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && event.phase == Phase.END) {
if (event.phase == Phase.END) {
_autoFish.onClientTick();
}
}
Expand All @@ -64,7 +63,7 @@ public void onServerTickEvent(ServerTickEvent event) {
* all players, so that it will also affect all players that join a single player game that has
* been opened to LAN play.
*/
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && AutoFishModConfig.CLIENT.config_autofish_fastFishing.get() && event.phase == Phase.END) {
if (AutoFishModConfig.autofishEnabled() && AutoFishModConfig.fashFishingEnabled() && event.phase == Phase.END) {
_autoFish.triggerBites();
}
}
Expand All @@ -76,7 +75,7 @@ public void onServerTickEvent(ServerTickEvent event) {
*/
@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && SoundEvents.ENTITY_FISHING_BOBBER_SPLASH.getName() == event.getSound().getSoundLocation()) {
if (AutoFishModConfig.autofishEnabled() && SoundEvents.ENTITY_FISHING_BOBBER_SPLASH.getName() == event.getSound().getSoundLocation()) {
_autoFish.onBobberSplashDetected(event.getSound().getX(), event.getSound().getY(), event.getSound().getZ());
}
}
Expand All @@ -102,8 +101,8 @@ public void onWorldEvent_Load(WorldEvent.Load event) {
@SubscribeEvent
public void onPlayerUseItem(PlayerInteractEvent.RightClickItem event) {
// Only do this on the client side
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && event.getWorld().isRemote) {
_autoFish.onPlayerUseItem();
if (AutoFishModConfig.autofishEnabled() && event.getWorld().isRemote) {
_autoFish.onPlayerUseItem(event.getHand());
}
}

Expand Down Expand Up @@ -137,14 +136,14 @@ public void addParticle(IParticleData particleData, boolean alwaysRender, double
@Override
public void addParticle(IParticleData particleData, boolean ignoreRange, boolean minimizeLevel, double x, double y,
double z, double xSpeed, double ySpeed, double zSpeed) {
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && particleData.getType() == Particles.FISHING) {
if (AutoFishModConfig.autofishEnabled() && particleData.getType() == Particles.FISHING) {
_autoFish.onWaterWakeDetected(x, y, z);
}
}

@Override
public void onEntityAdded(Entity entityIn) {
if (AutoFishModConfig.CLIENT.config_autofish_enable.get() && entityIn instanceof EntityXPOrb) {
if (AutoFishModConfig.autofishEnabled() && entityIn instanceof EntityXPOrb) {
_autoFish.onXpOrbAdded(entityIn.posX, entityIn.posY, entityIn.posZ);
}
}
Expand Down
Loading

0 comments on commit 4c392c6

Please sign in to comment.