Added OreDrop API

This commit is contained in:
joflashstudios 2015-06-07 23:55:58 -04:00
parent c01ae43435
commit 601812a10c
4 changed files with 126 additions and 0 deletions

View file

@ -0,0 +1,75 @@
package techreborn.blocks;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import techreborn.init.ModBlocks;
import techreborn.config.ConfigTechReborn;
public class OreDrop
{
public OreDrop(ItemStack drop)
{
this.drop = drop;
this.count = drop.stackSize;
this.baseChance = 100;
}
public OreDrop(ItemStack drop, Integer baseChance)
{
this.drop = drop;
this.count = drop.stackSize;
this.baseChance = baseChance;
}
public ItemStack getDrops(int fortuneLevel, Random random)
{
int count;
if (baseChance == 100) //This always drops. Use vanilla fortune rules.
{
count = calculateFortuneMulti(fortuneLevel, random);
} else if (calculateFortuneSingle(fortuneLevel, random)) //This has a chance to drop. Increase that chance with fortune.
{
count = this.count;
}
else
{
count = 0;
}
return new ItemStack(drop.getItem(), count, drop.getItemDamage());
}
//Refer to http://minecraft.gamepedia.com/Enchanting#Fortune
private int calculateFortuneMulti(int level, Random random)
{
int chanceOfEachBonus = 100 / (level + 2);
int roll = random.nextInt(100);
if (roll <= chanceOfEachBonus * level) //If level = 0, this is always false
{
return (roll / chanceOfEachBonus) + 2;
}
else
{
return 1;
}
}
//Each fortune level increases probability by 50% of base, up to a limit of 100%.
//So, if base is 5% and we have Fortune III, chance is 5% + (3 * 2.5%) = 12.5%
private boolean calculateFortuneSingle(int level, Random random)
{
double modifier = ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel * level;
double total = baseChance + (baseChance * modifier);
int roll = random.nextInt(100);
return roll <= total;
}
public ItemStack drop;
public Integer baseChance;
public Integer count;
}

View file

@ -0,0 +1,37 @@
package techreborn.blocks;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import techreborn.init.ModBlocks;
import techreborn.config.ConfigTechReborn;
import net.minecraft.block.Block;
public class OreDropSet
{
public OreDropSet(OreDrop primary, OreDrop... secondaries)
{
this.primary = primary;
this.secondaries = secondaries;
}
public ArrayList<ItemStack> drop(int fortune, Random random)
{
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
for (OreDrop drop : secondaries)
{
drops.add(drop.getDrops(fortune, random));
}
drops.add(primary.getDrops(fortune, random));
return drops;
}
public OreDrop primary;
public OreDrop[] secondaries;
}

View file

@ -61,6 +61,8 @@ public class ConfigTechReborn {
public static boolean SodaliteOreTrue;
public static int SodaliteOreRare;
public static double FortuneSecondaryOreMultiplierPerLevel;
// Power
public static int ThermalGenertaorOutput;
public static int CentrifugeInputTick;
@ -438,6 +440,15 @@ public class ConfigTechReborn {
.translateToLocal("config.techreborn.silverOre.rare.tooltip"))
.getInt();
FortuneSecondaryOreMultiplierPerLevel = config
.get(CATEGORY_WORLD,
StatCollector
.translateToLocal("config.techreborn.fortuneSecondaryOreMultiplierPerLevel"),
0.5,
StatCollector
.translateToLocal("config.techreborn.fortuneSecondaryOreMultiplierPerLevel.tooltip"))
.getDouble();
// Power
ThermalGenertaorOutput = config
.get(CATEGORY_POWER,

View file

@ -710,6 +710,9 @@ config.techreborn.allow.olivineOre.tooltip=Decide whether Olivine Ore spawns or
config.techreborn.allow.sodaliteOre=Allow Sodalite Ore
config.techreborn.allow.sodaliteOre.tooltip=Decide whether Sodalite Ore spawns or not
config.techreborn.fortuneSecondaryOreMultiplierPerLevel=Fortune's Effect on Secondaries
config.techreborn.fortuneSecondaryOreMultiplierPerLevel.tooltip=How much of an increase should each level of fortune have on secondary ore drops?
config.techreborn.allowExpensiveMacerator=Allow Expensive Macerator
config.techreborn.allowExpensiveMacerator.tooltip=
config.techreborn.allowExpensiveDrill=Allow Expensive Drill