net.minecraft.util.WeightedRandom Java Examples
The following examples show how to use
net.minecraft.util.WeightedRandom.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeManipulatorResultHandler.java From Gadomancy with GNU Lesser General Public License v3.0 | 6 votes |
public static NodeManipulatorResult getRandomResult(World world, Random random, INode affectedNode, int percChance) { int resultPositiveChance = Math.round(((float) percChance) / 5F); List<NodeManipulatorResult> localResults = new ArrayList<NodeManipulatorResult>(); for(NodeManipulatorResult result : possibleResults) { if(result.canAffect(world, affectedNode)) { ResultType type = result.getResultType(); if(type == ResultType.NEGATIVE) { if(random.nextInt(100) < resultPositiveChance) continue; } localResults.add(result); } } if(localResults.isEmpty()) return null; return (NodeManipulatorResult) WeightedRandom.getRandomItem(random, localResults); }
Example #2
Source File: RecipeHandlerLaserDrill.java From NEI-Integration with MIT License | 6 votes |
@Override public void prepare() { laserOres = MFRRegistry.getLaserOres(); for (WeightedRandom.Item ore : laserOres) { totalWeight += ore.itemWeight; } laserPreferredOres = new HashMap<Integer, List<ItemStack>>(); for (int i = 0; i <= 15; i++) { List<ItemStack> preferredOres = MFRRegistry.getLaserPreferredOres(i); laserPreferredOres.put(i, preferredOres); } TileEntityLaserDrillPrecharger dummyPrecharger = new TileEntityLaserDrillPrecharger(); TileEntityLaserDrill dummyDrill = new TileEntityLaserDrill(); energyPerOperation = dummyPrecharger.getActivationEnergy() * dummyDrill.getWorkMax(); dummyPrecharger = null; dummyDrill = null; laserFocus = GameRegistry.findItem("MineFactoryReloaded", "laserfocus"); if (laserFocus == null) { laserFocus = GameRegistry.findItem("MineFactoryReloaded", "item.mfr.laserfocus"); } }
Example #3
Source File: RecipeHandlerLaserDrill.java From NEI-Integration with MIT License | 6 votes |
@Override public void loadAllRecipes() { for (WeightedRandom.Item drop : laserOres) { if (drop instanceof WeightedRandomItemStack) { ItemStack dropStack = ((WeightedRandomItemStack) drop).getStack(); for (int i : laserPreferredOres.keySet()) { List<ItemStack> preferredStacks = laserPreferredOres.get(i); if (preferredStacks != null) { for (ItemStack preferredStack : preferredStacks) { if (Utils.areStacksSameTypeCraftingSafe(preferredStack, dropStack)) { this.arecipes.add(new CachedLaserDrillRecipe(dropStack, drop.itemWeight, i)); } } } } } } }
Example #4
Source File: RecipeHandlerLaserDrill.java From NEI-Integration with MIT License | 6 votes |
@Override public void loadCraftingRecipes(ItemStack result) { for (WeightedRandom.Item drop : laserOres) { if (drop instanceof WeightedRandomItemStack) { if (Utils.areStacksSameTypeCraftingSafe(((WeightedRandomItemStack) drop).getStack(), result)) { ItemStack dropStack = ((WeightedRandomItemStack) drop).getStack(); for (int i : laserPreferredOres.keySet()) { List<ItemStack> preferredStacks = laserPreferredOres.get(i); if (preferredStacks != null) { for (ItemStack preferredStack : preferredStacks) { if (Utils.areStacksSameTypeCraftingSafe(preferredStack, dropStack)) { this.arecipes.add(new CachedLaserDrillRecipe(dropStack, drop.itemWeight, i)); } } } } } } } }
Example #5
Source File: RecipeHandlerLaserDrill.java From NEI-Integration with MIT License | 6 votes |
@Override public void loadUsageRecipes(ItemStack ingred) { int dmg = ingred.getItemDamage(); if (ingred.getItem() == laserFocus && dmg <= 15) { for (WeightedRandom.Item drop : laserOres) { if (drop instanceof WeightedRandomItemStack) { ItemStack dropStack = ((WeightedRandomItemStack) drop).getStack(); List<ItemStack> preferredStacks = laserPreferredOres.get(dmg); if (preferredStacks != null) { for (ItemStack preferredStack : preferredStacks) { if (Utils.areStacksSameTypeCraftingSafe(preferredStack, dropStack)) { this.arecipes.add(new CachedLaserDrillRecipe(dropStack, drop.itemWeight, dmg)); } } } } } } }
Example #6
Source File: GenLayerBiomePlanet.java From AdvancedRocketry with MIT License | 5 votes |
protected BiomeEntry getWeightedBiomeEntry() { if(biomeEntries == null || biomeEntries.isEmpty()) return new BiomeEntry(Biomes.OCEAN, 100); List<BiomeEntry> biomeList = biomeEntries; int totalWeight = WeightedRandom.getTotalWeight(biomeList); int weight = nextInt(totalWeight / 10) * 10; return (BiomeEntry)WeightedRandom.getRandomItem(biomeList, weight); }
Example #7
Source File: CustomSpawner.java From mocreaturesdev with GNU General Public License v3.0 | 5 votes |
/** * Gets a random custom mob for spawning based on XYZ coordinates */ public SpawnListEntry getRandomCustomMob(World worldObj, EnumCreatureType enumCreatureType, int pX, int pY, int pZ) { List list = getPossibleCustomCreatures(worldObj, enumCreatureType, pX, pY, pZ); if (list == null || list.isEmpty()) { //System.out.println("list = NULL!! for type " + enumCreatureType.name()); return null; } else { return (SpawnListEntry) WeightedRandom.getRandomItem(worldObj.rand, list); } }