Clean up hive drops API

This commit is contained in:
mezz committed 2016-03-04 03:09:57 -08:00
1 parent 2d4c180389
commit 6e3c28e07e
6 files changed
+82 -64

No files matched your search

@@ -9,7 +9,7 @@ import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
/**
* Bees can be seeded either as hive drops or as mutation results.
@@ -20,18 +20,25 @@ import net.minecraft.world.World;
*/
public interface IHiveDrop {
ItemStack getPrincess(World world, BlockPos pos, int fortune);
IBee getBeeType(IBlockAccess world, BlockPos pos);
Collection<ItemStack> getDrones(World world, BlockPos pos, int fortune);
Collection<ItemStack> getAdditional(World world, BlockPos pos, int fortune);
Collection<ItemStack> getExtraItems(IBlockAccess world, BlockPos pos, int fortune);
/**
* Chance to drop. Default drops have 80 (= 80 %).
* Chance to drop a bee or extra items. Default drops have 0.80 (= 80 %).
*
* @param world Minecraft world this is called for.
* @param pos Coordinates of the broken hive.
* @return Chance for drop as an integer of 0 - 100.
* @return Chance for drop as a float of 0.0 - 1.0.
*/
int getChance(World world, BlockPos pos);
double getChance(IBlockAccess world, BlockPos pos, int fortune);
/**
* Chance for the princess to be ignoble. Default is around 0.4 to 0.7 (40% - 70%).
*
* @param world Minecraft world this is called for.
* @param pos Coordinates of the broken hive.
* @return Chance for ignoble as a float of 0.0 - 1.0.
*/
double getIgnobleChance(IBlockAccess world, BlockPos pos, int fortune);
}
@@ -747,43 +747,43 @@ public class PluginApiculture extends BlankForestryPlugin {
private static void registerBeehiveDrops() {
ItemStack honeyComb = items.beeComb.get(EnumHoneyComb.HONEY, 1);
hiveRegistry.addDrops(HiveType.FOREST.getHiveName(),
new HiveDrop(80, BeeDefinition.FOREST, honeyComb).setIgnobleShare(0.7f),
new HiveDrop(8, BeeDefinition.FOREST.getRainResist(), honeyComb),
new HiveDrop(3, BeeDefinition.VALIANT, honeyComb)
new HiveDrop(0.80, BeeDefinition.FOREST, honeyComb).setIgnobleShare(0.7),
new HiveDrop(0.08, BeeDefinition.FOREST.getRainResist(), honeyComb),
new HiveDrop(0.03, BeeDefinition.VALIANT, honeyComb)
);
hiveRegistry.addDrops(HiveType.MEADOWS.getHiveName(),
new HiveDrop(80, BeeDefinition.MEADOWS, honeyComb).setIgnobleShare(0.7f),
new HiveDrop(3, BeeDefinition.VALIANT, honeyComb)
new HiveDrop(0.80, BeeDefinition.MEADOWS, honeyComb).setIgnobleShare(0.7),
new HiveDrop(0.03, BeeDefinition.VALIANT, honeyComb)
);
ItemStack parchedComb = items.beeComb.get(EnumHoneyComb.PARCHED, 1);
hiveRegistry.addDrops(HiveType.DESERT.getHiveName(),
new HiveDrop(80, BeeDefinition.MODEST, parchedComb).setIgnobleShare(0.7f),
new HiveDrop(3, BeeDefinition.VALIANT, parchedComb)
new HiveDrop(0.80, BeeDefinition.MODEST, parchedComb).setIgnobleShare(0.7),
new HiveDrop(0.03, BeeDefinition.VALIANT, parchedComb)
);
ItemStack silkyComb = items.beeComb.get(EnumHoneyComb.SILKY, 1);
hiveRegistry.addDrops(HiveType.JUNGLE.getHiveName(),
new HiveDrop(80, BeeDefinition.TROPICAL, silkyComb).setIgnobleShare(0.7f),
new HiveDrop(3, BeeDefinition.VALIANT, silkyComb)
new HiveDrop(0.80, BeeDefinition.TROPICAL, silkyComb).setIgnobleShare(0.7),
new HiveDrop(0.03, BeeDefinition.VALIANT, silkyComb)
);
ItemStack mysteriousComb = items.beeComb.get(EnumHoneyComb.MYSTERIOUS, 1);
hiveRegistry.addDrops(HiveType.END.getHiveName(),
new HiveDrop(90, BeeDefinition.ENDED, mysteriousComb)
new HiveDrop(0.90, BeeDefinition.ENDED, mysteriousComb)
);
ItemStack frozenComb = items.beeComb.get(EnumHoneyComb.FROZEN, 1);
hiveRegistry.addDrops(HiveType.SNOW.getHiveName(),
new HiveDrop(80, BeeDefinition.WINTRY, frozenComb).setIgnobleShare(0.5f),
new HiveDrop(3, BeeDefinition.VALIANT, frozenComb)
new HiveDrop(0.80, BeeDefinition.WINTRY, frozenComb).setIgnobleShare(0.5),
new HiveDrop(0.03, BeeDefinition.VALIANT, frozenComb)
);
ItemStack mossyComb = items.beeComb.get(EnumHoneyComb.MOSSY, 1);
hiveRegistry.addDrops(HiveType.SWAMP.getHiveName(),
new HiveDrop(80, BeeDefinition.MARSHY, mossyComb).setIgnobleShare(0.4f),
new HiveDrop(3, BeeDefinition.VALIANT, mossyComb)
new HiveDrop(0.80, BeeDefinition.MARSHY, mossyComb).setIgnobleShare(0.4),
new HiveDrop(0.03, BeeDefinition.VALIANT, mossyComb)
);
}
@@ -13,6 +13,7 @@ package forestry.apiculture.blocks;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.properties.PropertyEnum;
@@ -28,6 +29,9 @@ import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IHiveDrop;
import forestry.api.apiculture.hives.IHiveRegistry.HiveType;
import forestry.api.core.IItemModelRegister;
@@ -100,20 +104,28 @@ public class BlockBeehives extends BlockContainer implements IItemModelRegister
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<>();
List<ItemStack> drops = new ArrayList<>();
List<IHiveDrop> dropList = getDropsForHive(getMetaFromState(state));
Random random = world instanceof World ? ((World) world).rand : RANDOM;
List<IHiveDrop> hiveDrops = getDropsForHive(getMetaFromState(state));
Collections.shuffle(hiveDrops);
Collections.shuffle(dropList);
// Grab a princess
int tries = 0;
boolean hasPrincess = false;
while (tries <= 10 && !hasPrincess) {
tries++;
for (IHiveDrop drop : dropList) {
if (RANDOM.nextInt(100) < drop.getChance((World) world, pos)) {
ret.add(drop.getPrincess((World) world, pos, fortune));
for (IHiveDrop drop : hiveDrops) {
if (random.nextDouble() < drop.getChance(world, pos, fortune)) {
IBee bee = drop.getBeeType(world, pos);
if (random.nextFloat() < drop.getIgnobleChance(world, pos, fortune)) {
bee.setIsNatural(false);
}
ItemStack princess = BeeManager.beeRoot.getMemberStack(bee, EnumBeeType.PRINCESS.ordinal());
drops.add(princess);
hasPrincess = true;
break;
}
@@ -121,21 +133,24 @@ public class BlockBeehives extends BlockContainer implements IItemModelRegister
}
// Grab drones
for (IHiveDrop drop : dropList) {
if (RANDOM.nextInt(100) < drop.getChance((World) world, pos)) {
ret.addAll(drop.getDrones((World) world, pos, fortune));
break;
}
}
// Grab anything else on offer
for (IHiveDrop drop : dropList) {
if (RANDOM.nextInt(100) < drop.getChance((World) world, pos)) {
ret.addAll(drop.getAdditional((World) world, pos, fortune));
for (IHiveDrop drop : hiveDrops) {
if (random.nextDouble() < drop.getChance(world, pos, fortune)) {
IBee bee = drop.getBeeType(world, pos);
ItemStack drone = BeeManager.beeRoot.getMemberStack(bee, EnumBeeType.DRONE.ordinal());
drops.add(drone);
break;
}
}
return ret;
// Grab anything else on offer
for (IHiveDrop drop : hiveDrops) {
if (random.nextDouble() < drop.getChance(world, pos, fortune)) {
drops.addAll(drop.getExtraItems(world, pos, fortune));
break;
}
}
return drops;
}
// / CREATIVE INVENTORY
@@ -16,10 +16,8 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IHiveDrop;
@@ -27,40 +25,29 @@ public class HiveDrop implements IHiveDrop {
private final IBeeDefinition beeTemplate;
private final ArrayList<ItemStack> additional = new ArrayList<>();
private final int chance;
private float ignobleShare = 0.0f;
private final double chance;
private double ignobleShare = 0.0;
public HiveDrop(int chance, IBeeDefinition beeTemplate, ItemStack... bonus) {
public HiveDrop(double chance, IBeeDefinition beeTemplate, ItemStack... bonus) {
this.beeTemplate = beeTemplate;
this.chance = chance;
Collections.addAll(this.additional, bonus);
}
public HiveDrop setIgnobleShare(float share) {
public HiveDrop setIgnobleShare(double share) {
this.ignobleShare = share;
return this;
}
@Override
public ItemStack getPrincess(World world, BlockPos pos, int fortune) {
IBee bee = beeTemplate.getIndividual();
if (world.rand.nextFloat() < ignobleShare) {
bee.setIsNatural(false);
}
return BeeManager.beeRoot.getMemberStack(bee, EnumBeeType.PRINCESS.ordinal());
public IBee getBeeType(IBlockAccess world, BlockPos pos) {
return beeTemplate.getIndividual();
}
@Override
public List<ItemStack> getDrones(World world, BlockPos pos, int fortune) {
ItemStack drone = beeTemplate.getMemberStack(EnumBeeType.DRONE);
return Collections.singletonList(drone);
}
@Override
public ArrayList<ItemStack> getAdditional(World world, BlockPos pos, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<>();
public List<ItemStack> getExtraItems(IBlockAccess world, BlockPos pos, int fortune) {
List<ItemStack> ret = new ArrayList<>();
for (ItemStack stack : additional) {
ret.add(stack.copy());
}
@@ -69,8 +56,12 @@ public class HiveDrop implements IHiveDrop {
}
@Override
public int getChance(World world, BlockPos pos) {
public double getChance(IBlockAccess world, BlockPos pos, int fortune) {
return chance;
}
@Override
public double getIgnobleChance(IBlockAccess world, BlockPos pos, int fortune) {
return ignobleShare;
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.gui;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.HashMap;
@@ -36,12 +37,13 @@ import forestry.core.proxy.Proxies;
import forestry.core.utils.StringUtil;
public class GuiNaturalistInventory extends GuiForestry<Container, IPagedInventory> {
@Nonnull
private final ISpeciesRoot speciesRoot;
private final IBreedingTracker breedingTracker;
private final HashMap<String, ItemStack> iconStacks = new HashMap<>();
private final int pageCurrent, pageMax;
public GuiNaturalistInventory(ISpeciesRoot speciesRoot, EntityPlayer player, Container container, IPagedInventory inventory, int page, int maxPages) {
public GuiNaturalistInventory(@Nonnull ISpeciesRoot speciesRoot, EntityPlayer player, Container container, IPagedInventory inventory, int page, int maxPages) {
super(Constants.TEXTURE_PATH_GUI + "/apiaristinventory.png", container, inventory);
this.speciesRoot = speciesRoot;
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.storage.items;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -23,9 +25,10 @@ import forestry.storage.gui.ContainerNaturalistBackpack;
import forestry.storage.inventory.ItemInventoryBackpackPaged;
public class ItemBackpackNaturalist extends ItemBackpack {
@Nonnull
private final ISpeciesRoot speciesRoot;
public ItemBackpackNaturalist(ISpeciesRoot speciesRoot, IBackpackDefinition definition, EnumBackpackType type) {
public ItemBackpackNaturalist(@Nonnull ISpeciesRoot speciesRoot, IBackpackDefinition definition, EnumBackpackType type) {
super(definition, type);
this.speciesRoot = speciesRoot;
}