本文整理匯總了Java中net.minecraft.util.WeightedRandom.getRandomItem方法的典型用法代碼示例。如果您正苦於以下問題:Java WeightedRandom.getRandomItem方法的具體用法?Java WeightedRandom.getRandomItem怎麽用?Java WeightedRandom.getRandomItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.util.WeightedRandom
的用法示例。
在下文中一共展示了WeightedRandom.getRandomItem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateChestContents
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
/** Generate chest contents */
public static void generateChestContents(Random random, List<WeightedRandomChestContent> listIn, TileEntityChest dispenser, int max)
{
for (int i = 0; i < max; ++i)
{
WeightedRandomChestContent weightedrandomchestcontent = WeightedRandom.getRandomItem(random, listIn);
int j = weightedrandomchestcontent.minStackSize + random.nextInt(weightedrandomchestcontent.maxStackSize - weightedrandomchestcontent.minStackSize + 1);
if (weightedrandomchestcontent.theItemId.getMaxStackSize() >= j)
{
ItemStack itemstack1 = weightedrandomchestcontent.theItemId.copy();
itemstack1.stackSize = j;
dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack1);
}
else
{
for (int k = 0; k < j; ++k)
{
ItemStack itemstack = weightedrandomchestcontent.theItemId.copy();
itemstack.stackSize = 1;
dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack);
}
}
}
}
示例2: getRandomPlanet
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
public PlanetType getRandomPlanet() {
this.rand.setSeed(this.x * 341873128712L + this.z * 132897987541L);
ArrayList<PlanetType> list = new ArrayList<PlanetType>();
list.addAll(types);
PlanetType type = (PlanetType) WeightedRandom.getRandomItem(this.rand, list);
if (type == STONE) {
list.clear();
list.addAll(stonetypes);
type = (PlanetType) WeightedRandom.getRandomItem(this.rand, list);
}
type.total += 1;
if (type.out == Blocks.stone)
STONE.total += 1;
return type;
}
示例3: getRandomResult
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
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);
}
示例4: getOreToPut
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
public static ItemStack getOreToPut() {
List<WeightedRandom.Item> values = new ArrayList<net.minecraft.util.WeightedRandom.Item>();
for (String s : oreNames.keySet())
values.add(new StringRandomItem(oreNames.get(s), s));
String ore = ((StringRandomItem) WeightedRandom.getRandomItem(new Random(), values)).s;
List<ItemStack> ores = OreDictionary.getOres(ore);
for (ItemStack stack : ores) {
Item item = stack.getItem();
String clname = item.getClass().getName();
if (clname.startsWith("gregtech") || clname.startsWith("gregapi")) {
continue;
}
return stack.copy();
}
return getOreToPut();
}
示例5: getBlockFromBlueprint
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
@Override
public BlockWithMeta getBlockFromBlueprint(ChunkCoordinates piecePos, int cellSize, int cellHeight, Random random,
CellIndexDirection cellIndexDirection) {
if (piecePos.posY == 0) {
return sandstone;
} else if (piecePos.posY == 1) {
return sand;
} else if (piecePos.posY == 2) {
return grass;
} else if (piecePos.posY == 3) {
if (piecePos.posX == cellSize / 2 && piecePos.posZ == cellSize / 2) {
return new BlockWithPalmTree();
} else {
return (BlockWithMeta) WeightedRandom.getRandomItem(random, flowers);
}
}
return air;
}
示例6: getBlockFromBlueprint
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
@Override
public BlockWithMeta getBlockFromBlueprint(ChunkCoordinates piecePos, int cellSize, int cellHeight, Random random,
CellIndexDirection cellIndexDirection) {
if (piecePos.posY == 0) {
return sandstone;
} else if (piecePos.posY == 1) {
return sand;
} else if (piecePos.posY == 2) {
if (isGrass(CellHelper.rotateCellTo(piecePos, cellSize, cellIndexDirection), cellSize, cellHeight, random)) {
return grass;
} else {
return sand;
}
} else if (piecePos.posY == 3) {
if (isGrass(CellHelper.rotateCellTo(piecePos, cellSize, cellIndexDirection), cellSize, cellHeight, random)) {
return (BlockWithMeta) WeightedRandom.getRandomItem(random, flowers);
} else {
return air;
}
}
return air;
}
示例7: getGrassSeed
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
public static ItemStack getGrassSeed(Random rand, int fortune)
{
SeedEntry entry = WeightedRandom.getRandomItem(rand, seedList);
if (entry == null || entry.seed == null)
{
return null;
}
return entry.getStack(rand, fortune);
}
示例8: getRandomDungeonMob
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
/**
* Gets a random mob name from the list.
* @param rand World generation random number generator
* @return The mob name
*/
public static String getRandomDungeonMob(Random rand)
{
DungeonMob mob = WeightedRandom.getRandomItem(rand, dungeonMobs);
if (mob == null)
{
return "";
}
return mob.type;
}
示例9: getSpawnListEntryForTypeAt
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
@Nullable
public Biome.SpawnListEntry getSpawnListEntryForTypeAt(EnumCreatureType creatureType, BlockPos pos)
{
List<Biome.SpawnListEntry> list = this.getChunkProvider().getPossibleCreatures(creatureType, pos);
list = net.minecraftforge.event.ForgeEventFactory.getPotentialSpawns(this, creatureType, pos, list);
return list != null && !list.isEmpty() ? (Biome.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
}
示例10: plantFlower
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
public void plantFlower(World world, Random rand, BlockPos pos)
{
FlowerEntry flower = (FlowerEntry)WeightedRandom.getRandomItem(rand, flowers);
if (flower == null || flower.state == null ||
(flower.state.getBlock() instanceof net.minecraft.block.BlockBush &&
!((net.minecraft.block.BlockBush)flower.state.getBlock()).canBlockStay(world, pos, flower.state)))
{
return;
}
world.setBlockState(pos, flower.state, 3);
}
示例11: getGrassSeed
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
public static ItemStack getGrassSeed(World world)
{
SeedEntry entry = (SeedEntry)WeightedRandom.getRandomItem(world.rand, seedList);
if (entry == null || entry.seed == null)
{
return null;
}
return entry.seed.copy();
}
示例12: getOneItem
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
/**
* Returns a single ItemStack from the possible items in this registry,
* Useful if you just want a quick and dirty random Item.
*
* @param rand A Random Number gen
* @return A single ItemStack, or null if it could not get one.
*/
public ItemStack getOneItem(Random rand)
{
WeightedRandomChestContent[] items = getItems(rand);
WeightedRandomChestContent item = (WeightedRandomChestContent)WeightedRandom.getRandomItem(rand, items);
ItemStack[] stacks = ChestGenHooks.generateStacks(rand, item.theItemId, item.theMinimumChanceToGenerateItem, item.theMaximumChanceToGenerateItem);
return (stacks.length > 0 ? stacks[0] : null);
}
示例13: getRandomDungeonMob
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
/**
* Gets a random mob name from the list.
* @param rand World generation random number generator
* @return The mob name
*/
public static String getRandomDungeonMob(Random rand)
{
DungeonMob mob = (DungeonMob)WeightedRandom.getRandomItem(rand, dungeonMobs);
if (mob == null)
{
return "";
}
return mob.type;
}
示例14: spawnRandomCreature
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
/**
* only spawns creatures allowed by the chunkProvider
*/
public BiomeGenBase.SpawnListEntry spawnRandomCreature(EnumCreatureType type, int x, int y, int z) {
@SuppressWarnings("unchecked")
List<SpawnListEntry> list = this.getChunkProvider().getPossibleCreatures(type, x, y, z);
list = ForgeEventFactory.getPotentialSpawns(this.thePlayerManager.getWorldServer(), type, x, y, z, list);
return list != null && !list.isEmpty()
? (BiomeGenBase.SpawnListEntry) WeightedRandom.getRandomItem(this.rand, list) : null;
}
示例15: getBlockFromBlueprint
import net.minecraft.util.WeightedRandom; //導入方法依賴的package包/類
@Override
public BlockWithMeta getBlockFromBlueprint(ChunkCoordinates piecePos, int cellSize, int cellHeight, Random random,
CellIndexDirection cellIndexDirection) {
if (piecePos.posY == 0) {
return sandstone;
} else if (piecePos.posY == 1) {
return sand;
} else if (piecePos.posY == 2) {
return grass;
} else if (piecePos.posY == 3) {
return (BlockWithMeta) WeightedRandom.getRandomItem(random, flowers);
}
return air;
}