Merge pull request #1128 from skyboy/patch-fishingapi
Add API for fishing results, I'm tired of this, If shit breaks, Blame Skyboy and King_Lemming.
This commit is contained in:
commit
224987aa83
2 changed files with 129 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
||||||
|
--- ../src-base/minecraft/net/minecraft/entity/projectile/EntityFishHook.java
|
||||||
|
+++ ../src-work/minecraft/net/minecraft/entity/projectile/EntityFishHook.java
|
||||||
|
@@ -551,6 +551,12 @@ public class EntityFishHook extends Entity
|
||||||
|
float f = this.field_70170_p.field_73012_v.nextFloat();
|
||||||
|
int i = EnchantmentHelper.func_151386_g(this.field_146042_b);
|
||||||
|
int j = EnchantmentHelper.func_151387_h(this.field_146042_b);
|
||||||
|
+ if (true)
|
||||||
|
+ {
|
||||||
|
+ this.field_146042_b.func_71064_a(net.minecraftforge.common.FishingHooks.getFishableCategory(f, i, j).stat, 1);
|
||||||
|
+ return net.minecraftforge.common.FishingHooks.getRandomFishable(this.field_70146_Z, f, i, j);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;
|
||||||
|
float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;
|
||||||
|
f1 = MathHelper.func_76131_a(f1, 0.0F, 1.0F);
|
114
src/main/java/net/minecraftforge/common/FishingHooks.java
Normal file
114
src/main/java/net/minecraftforge/common/FishingHooks.java
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
package net.minecraftforge.common;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.entity.projectile.EntityFishHook;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.stats.StatBase;
|
||||||
|
import net.minecraft.stats.StatList;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
import net.minecraft.util.WeightedRandom;
|
||||||
|
import net.minecraft.util.WeightedRandomFishable;
|
||||||
|
|
||||||
|
public class FishingHooks
|
||||||
|
{
|
||||||
|
private static ArrayList<WeightedRandomFishable> fish = new ArrayList<WeightedRandomFishable>();
|
||||||
|
private static ArrayList<WeightedRandomFishable> junk = new ArrayList<WeightedRandomFishable>();
|
||||||
|
private static ArrayList<WeightedRandomFishable> treasure = new ArrayList<WeightedRandomFishable>();
|
||||||
|
|
||||||
|
public static void addFish(WeightedRandomFishable item) { fish.add(item); }
|
||||||
|
public static void addJunk(WeightedRandomFishable item) { junk.add(item); }
|
||||||
|
public static void addTreasure(WeightedRandomFishable item) { treasure.add(item); }
|
||||||
|
|
||||||
|
public static void removeFish(Predicate<WeightedRandomFishable> test) { remove(fish.iterator(), test); }
|
||||||
|
public static void removeJunk(Predicate<WeightedRandomFishable> test) { remove(junk.iterator(), test); }
|
||||||
|
public static void removeTreasure(Predicate<WeightedRandomFishable> test) { remove(treasure.iterator(), test); }
|
||||||
|
|
||||||
|
public static ItemStack getRandomFishable(Random rand, float chance)
|
||||||
|
{
|
||||||
|
return getRandomFishable(rand, chance, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getRandomFishable(Random rand, float chance, int luck, int speed)
|
||||||
|
{
|
||||||
|
float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
|
||||||
|
float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
|
||||||
|
junkChance = MathHelper.clamp_float(junkChance, 0.0F, 1.0F);
|
||||||
|
treasureChance = MathHelper.clamp_float(treasureChance, 0.0F, 1.0F);
|
||||||
|
|
||||||
|
if (chance < junkChance)
|
||||||
|
{
|
||||||
|
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, junk)).func_150708_a(rand);
|
||||||
|
}
|
||||||
|
|
||||||
|
chance -= junkChance;
|
||||||
|
if (chance < treasureChance)
|
||||||
|
{
|
||||||
|
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, treasure)).func_150708_a(rand);
|
||||||
|
}
|
||||||
|
|
||||||
|
chance -= treasureChance;
|
||||||
|
// this is done in EntityFishHook.func_146033_f. more loot types expected?
|
||||||
|
{
|
||||||
|
return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, fish)).func_150708_a(rand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FishableCategory getFishableCategory(float chance, int luck, int speed)
|
||||||
|
{
|
||||||
|
float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
|
||||||
|
float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
|
||||||
|
junkChance = MathHelper.clamp_float(junkChance, 0.0F, 1.0F);
|
||||||
|
treasureChance = MathHelper.clamp_float(treasureChance, 0.0F, 1.0F);
|
||||||
|
|
||||||
|
if (chance < junkChance)
|
||||||
|
{
|
||||||
|
return FishableCategory.JUNK;
|
||||||
|
}
|
||||||
|
|
||||||
|
chance -= junkChance;
|
||||||
|
if (chance < treasureChance)
|
||||||
|
{
|
||||||
|
return FishableCategory.TREASURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
chance -= treasureChance;
|
||||||
|
// this is done in EntityFishHook.func_146033_f. more loot types expected?
|
||||||
|
{
|
||||||
|
return FishableCategory.FISH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void remove(Iterator<WeightedRandomFishable> iter, Predicate<WeightedRandomFishable> test)
|
||||||
|
{
|
||||||
|
while (iter.hasNext())
|
||||||
|
if (!test.apply(iter.next()))
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
fish.addAll(EntityFishHook.field_146036_f);
|
||||||
|
junk.addAll(EntityFishHook.field_146039_d);
|
||||||
|
treasure.addAll(EntityFishHook.field_146041_e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum FishableCategory
|
||||||
|
{
|
||||||
|
JUNK(StatList.field_151183_A),
|
||||||
|
TREASURE(StatList.field_151184_B),
|
||||||
|
FISH(StatList.fishCaughtStat);
|
||||||
|
|
||||||
|
public final StatBase stat;
|
||||||
|
|
||||||
|
FishableCategory(StatBase stat)
|
||||||
|
{
|
||||||
|
this.stat = stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue