Allow fishing success rate to be adjustable. Adds BUKKIT-3837

This commit is contained in:
Andre LeBlanc 2013-03-20 11:48:35 -04:00 committed by GJ
parent 96ba65d506
commit 18d7bc7ca3
2 changed files with 22 additions and 7 deletions

View File

@ -234,13 +234,7 @@ public class EntityFishingHook extends Entity {
if (this.au > 0) { if (this.au > 0) {
--this.au; --this.au;
} else { } else {
short short1 = 500; if (random.nextDouble() < ((org.bukkit.entity.Fish) this.getBukkitEntity()).getBiteChance()) { // CraftBukkit - moved logic to CraftFish
if (this.world.F(MathHelper.floor(this.locX), MathHelper.floor(this.locY) + 1, MathHelper.floor(this.locZ))) {
short1 = 300;
}
if (this.random.nextInt(short1) == 0) {
this.au = this.random.nextInt(30) + 10; this.au = this.random.nextInt(30) + 10;
this.motY -= 0.20000000298023224D; this.motY -= 0.20000000298023224D;
this.makeSound("random.splash", 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F); this.makeSound("random.splash", 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);

View File

@ -2,13 +2,17 @@ package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityFishingHook; import net.minecraft.server.EntityFishingHook;
import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityHuman;
import net.minecraft.server.MathHelper;
import org.apache.commons.lang.Validate;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish; import org.bukkit.entity.Fish;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public class CraftFish extends AbstractProjectile implements Fish { public class CraftFish extends AbstractProjectile implements Fish {
private double biteChance = -1;
public CraftFish(CraftServer server, EntityFishingHook entity) { public CraftFish(CraftServer server, EntityFishingHook entity) {
super(server, entity); super(server, entity);
} }
@ -40,4 +44,21 @@ public class CraftFish extends AbstractProjectile implements Fish {
public EntityType getType() { public EntityType getType() {
return EntityType.FISHING_HOOK; return EntityType.FISHING_HOOK;
} }
public double getBiteChance() {
EntityFishingHook hook = getHandle();
if (this.biteChance == -1) {
if (hook.world.F(MathHelper.floor(hook.locX), MathHelper.floor(hook.locY) + 1, MathHelper.floor(hook.locZ))) {
return 1/300.0;
}
return 1/500.0;
}
return this.biteChance;
}
public void setBiteChance(double chance) {
Validate.isTrue(chance >= 0 && chance <= 1, "The bite chance must be between 0 and 1.");
this.biteChance = chance;
}
} }