Skip to content

Commit

Permalink
Backport v1.7 to MC 1.8.9
Browse files Browse the repository at this point in the history
  • Loading branch information
freneticfeline committed Jan 7, 2018
1 parent cecee98 commit ccaebe9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 47 deletions.
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-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.9-1.7"
version = "1.8-1.7"
group= "net.unladenswallow.minecraft.autofish" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "mod_autofish_forge"

minecraft {
version = "12.16.1.1887"
version = "1.8.9-11.15.1.1722"
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_20160312"
mappings = "stable_20"
}

dependencies {
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/net/unladenswallow/minecraft/autofish/AutoFish.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
import net.minecraft.item.ItemFishingRod;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.WorldServer;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.unladenswallow.minecraft.autofish.util.Logger;
Expand Down Expand Up @@ -116,6 +115,7 @@ public void onBobberSplashDetected(float x, float y, float z) {
// double yDifference = Math.abs(hook.posY - y);
// Ignore Y component when calculating distance from hook
double xzDistanceFromHook = hook.getDistanceSq(x, hook.posY, z);
// Logger.info("[%d] BOBBER_SPLASH at distance %f", this.minecraftClient.theWorld.getTotalWorldTime(), xzDistanceFromHook);
if (xzDistanceFromHook <= CLOSE_BOBBER_SPLASH_THRESHOLD) {
// AutoFishLogger.info("[%d] Close bobber splash at %f / %f", this.minecraft.theWorld.getTotalWorldTime(), xzDistanceFromHook, yDifference);
this.closeBobberSplashDetectedAt = this.minecraftClient.theWorld.getTotalWorldTime();
Expand Down Expand Up @@ -428,7 +428,7 @@ private boolean hookHasBeenInWaterLongEnough() {
}

private boolean playerIsHoldingRod() {
ItemStack heldItem = this.player.getHeldItemMainhand();
ItemStack heldItem = this.player.getHeldItem();

return (heldItem != null
&& heldItem.getItem() instanceof ItemFishingRod
Expand Down Expand Up @@ -491,8 +491,10 @@ private boolean rodIsCast() {
if (!playerIsHoldingRod()) {
return false;
}
ItemStack heldItemStack = this.player.getHeldItemMainhand();
return this.player.getHeldItemMainhand().getItem().getPropertyGetter(new ResourceLocation("cast")).apply(heldItemStack, this.minecraftClient.theWorld, this.player) > 0F;
return (this.player.fishEntity != null);
// ItemStack heldItemStack = this.player.getHeldItem();
// Logger.info("fising_rod is %s", heldItemStack.getItem().get);
// return heldItemStack.getItem().getMetadata(heldItemStack) == 1;
}

private boolean needToSwitchRods() {
Expand All @@ -511,7 +513,7 @@ private boolean playerCanCast() {
if (!playerIsHoldingRod()) {
return false;
} else {
ItemStack heldItem = this.player.getHeldItemMainhand();
ItemStack heldItem = this.player.getHeldItem();

return (!ModAutoFish.config_autofish_preventBreak
|| (heldItem.getMaxDamage() - heldItem.getItemDamage() > AUTOFISH_BREAKPREVENT_THRESHOLD)
Expand All @@ -524,7 +526,7 @@ private boolean playerCanCast() {


private void showNotificationToPlayer() {
this.player.addChatMessage(new TextComponentString(NOTIFICATION_TEXT_AUTOFISH_ENABLED));
this.player.addChatMessage(new ChatComponentText(NOTIFICATION_TEXT_AUTOFISH_ENABLED));
this.notificationShownToPlayer = true;
}

Expand Down Expand Up @@ -585,10 +587,12 @@ private void resetReelDelay() {
public void triggerBites() {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server != null) {
for (EntityPlayer player : server.getPlayerList().getPlayerList()) {
if (playerHookInWater(player)) {
int ticks = FAST_FISH_CATCHABLE_DELAY_TICKS + MathHelper.getRandomIntegerInRange(this.rand, 0, FAST_FISH_DELAY_VARIANCE);
setTicksCatchableDelay(player.fishEntity, ticks);
for (WorldServer worldServer : server.worldServers) {
for (EntityPlayer player : worldServer.playerEntities) {
if (playerHookInWater(player)) {
int ticks = FAST_FISH_CATCHABLE_DELAY_TICKS + MathHelper.getRandomIntegerInRange(this.rand, 0, FAST_FISH_DELAY_VARIANCE);
setTicksCatchableDelay(player.fishEntity, ticks);
}
}
}
}
Expand Down Expand Up @@ -634,12 +638,13 @@ private EntityPlayer getServerPlayerEntity() {
}
}

private EnumActionResult playerUseRod() {
return this.minecraftClient.playerController.processRightClick(
private void playerUseRod() {
this.minecraftClient.playerController.sendUseItem(
this.player,
this.minecraftClient.theWorld,
this.player.getHeldItemMainhand(),
EnumHand.MAIN_HAND);
this.player.getHeldItem());
// in 1.8, this does not trigger a PlayerInteractEvent, so we need to call our handler manually
onPlayerUseItem();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.unladenswallow.minecraft.autofish.proxy.CommonProxy;
import net.unladenswallow.minecraft.autofish.util.Logger;

@Mod(modid = ModAutoFish.MODID, useMetadata = true, acceptedMinecraftVersions="[1.9,1.10)", acceptableRemoteVersions="[1.9,1.10)",
@Mod(modid = ModAutoFish.MODID, useMetadata = true, acceptedMinecraftVersions="[1.8.9,1.9)", acceptableRemoteVersions="[1.8.9,1.9)",
guiFactory = "net.unladenswallow.minecraft.autofish.gui.GuiFactory")
public class ModAutoFish {
public static final String MODID = "mod_autofish";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldEventListener;
import net.minecraft.world.IWorldAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -23,11 +21,13 @@
import net.unladenswallow.minecraft.autofish.ModAutoFish;
import net.unladenswallow.minecraft.autofish.util.Logger;

public class EventListener implements IWorldEventListener {
public class EventListener implements IWorldAccess {

// The core AutoFish logic that we will use to respond to events
private AutoFish _autoFish;

private static final String BOBBER_SPLASH_SOUND_NAME = "random.splash";

public EventListener(AutoFish autoFish) {
_autoFish = autoFish;
}
Expand Down Expand Up @@ -74,8 +74,8 @@ public void onServerTickEvent(ServerTickEvent event) {
*/
@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
if (ModAutoFish.config_autofish_enable && SoundEvents.entity_bobber_splash.getSoundName() == event.getSound().getSoundLocation()) {
_autoFish.onBobberSplashDetected(event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF());
if (ModAutoFish.config_autofish_enable && BOBBER_SPLASH_SOUND_NAME == event.name) {
_autoFish.onBobberSplashDetected(event.sound.getXPosF(), event.sound.getYPosF(), event.sound.getZPosF());
}
}

Expand All @@ -86,9 +86,9 @@ public void onPlaySoundEvent(PlaySoundEvent event) {
*/
@SubscribeEvent
public void onWorldEvent_Load(WorldEvent.Load event) {
if (event.getWorld() != null && event.getWorld().isRemote) {
if (event.world != null && event.world.isRemote) {
Logger.info("Attaching WorldEventListener");
event.getWorld().addEventListener(this);
event.world.addWorldAccess(this);
}
}

Expand All @@ -99,9 +99,9 @@ public void onWorldEvent_Load(WorldEvent.Load event) {
* @param event
*/
@SubscribeEvent
public void onPlayerUseItem(PlayerInteractEvent.RightClickItem event) {
public void onPlayerUseItem(PlayerInteractEvent event) {
// Only do this on the client side
if (ModAutoFish.config_autofish_enable && event.getWorld().isRemote) {
if (ModAutoFish.config_autofish_enable && event.action == Action.RIGHT_CLICK_AIR && event.world.isRemote) {
_autoFish.onPlayerUseItem();
}
}
Expand All @@ -114,7 +114,7 @@ public void onPlayerUseItem(PlayerInteractEvent.RightClickItem event) {
*/
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
if (event.getModID().equals(ModAutoFish.MODID)) {
if (event.modID.equals(ModAutoFish.MODID)) {
ModAutoFish.syncConfig();
}
}
Expand Down Expand Up @@ -145,31 +145,40 @@ public void onEntityAdded(Entity entityIn) {
/******** Ignored World Events *********/

@Override
public void notifyBlockUpdate(World worldIn, BlockPos pos, IBlockState oldState, IBlockState newState, int flags) {}
public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {}

@Override
public void notifyLightSet(BlockPos pos) {}
public void onEntityRemoved(Entity entityIn) {}

@Override
public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {}
public void markBlockForUpdate(BlockPos pos) {}


@Override
public void playSoundToAllNearExcept(EntityPlayer player, SoundEvent soundIn, SoundCategory category, double x,
double y, double z, float volume, float pitch) {}
public void notifyLightSet(BlockPos pos) {}


@Override
public void playRecord(SoundEvent soundIn, BlockPos pos) {}
public void playSound(String soundName, double x, double y, double z, float volume, float pitch) {}


@Override
public void onEntityRemoved(Entity entityIn) {}
public void playSoundToNearExcept(EntityPlayer except, String soundName, double x, double y, double z, float volume,
float pitch) {}


@Override
public void broadcastSound(int soundID, BlockPos pos, int data) {}
public void playRecord(String recordName, BlockPos blockPosIn) {}


@Override
public void broadcastSound(int p_180440_1_, BlockPos p_180440_2_, int p_180440_3_) {}


@Override
public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) {}


@Override
public void playAuxSFX(EntityPlayer player, int sfxType, BlockPos blockPosIn, int data) {}
public void playAuxSFX(EntityPlayer player, int sfxType, BlockPos blockPosIn, int p_180439_4_) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
private boolean playerIsHoldingFishingRod(EntityPlayer player) {
return (!Minecraft.getMinecraft().isGamePaused()
&& player != null
&& player.getHeldItemMainhand() != null
&& player.getHeldItemMainhand().getItem() instanceof ItemFishingRod);
&& player.getHeldItem() != null
&& player.getHeldItem().getItem() instanceof ItemFishingRod);
}

}

0 comments on commit ccaebe9

Please sign in to comment.