Moved OreDrop
With a small bit of work we could make an api to get the config values, then this could go in the api
This commit is contained in:
parent
2ef2ff997f
commit
a94085229d
3 changed files with 4 additions and 5 deletions
|
@ -2,9 +2,7 @@ package techreborn.blocks;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.pahimar.ee3.item.ItemGem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
|
@ -17,12 +15,13 @@ import net.minecraft.util.MathHelper;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import techreborn.client.TechRebornCreativeTabMisc;
|
||||
import techreborn.init.ModItems;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.items.ItemDusts;
|
||||
import techreborn.items.ItemGems;
|
||||
import techreborn.util.OreDrop;
|
||||
import techreborn.util.OreDropSet;
|
||||
|
||||
public class BlockOre extends Block {
|
||||
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
package techreborn.blocks;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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, double baseChance)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.count = drop.stackSize;
|
||||
this.baseChance = (int)(baseChance * 100);
|
||||
}
|
||||
|
||||
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 count * ((roll / chanceOfEachBonus) + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
//Each fortune level increases probability by 50% (configurable) of base, up to a limit of 100%, obviously.
|
||||
//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;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package techreborn.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class OreDropSet
|
||||
{
|
||||
public OreDropSet(OreDrop... oreDrops)
|
||||
{
|
||||
this.dropSet = oreDrops;
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> drop(int fortune, Random random)
|
||||
{
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
|
||||
for (OreDrop drop : dropSet)
|
||||
{
|
||||
drops.add(drop.getDrops(fortune, random));
|
||||
}
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
public OreDrop[] dropSet;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue