當前位置: 首頁>>代碼示例>>Java>>正文


Java WeightedRandom.getRandomItem方法代碼示例

本文整理匯總了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);
            }
        }
    }
}
 
開發者ID:sblectric,項目名稱:LightningCraft,代碼行數:26,代碼來源:WeightedRandomChestContent.java

示例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;
}
 
開發者ID:TeNNoX-Mods,項目名稱:Planetoids,代碼行數:22,代碼來源:Planet.java

示例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);
}
 
開發者ID:makeoo,項目名稱:Gadomancy,代碼行數:17,代碼來源:NodeManipulatorResultHandler.java

示例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();
}
 
開發者ID:AdlyTempleton,項目名稱:Aura-Cascade,代碼行數:23,代碼來源:OreDropManager.java

示例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;
}
 
開發者ID:soultek101,項目名稱:projectzulu1.7.10-pre-1.3a,代碼行數:19,代碼來源:BPOasisTreeGrass.java

示例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;
}
 
開發者ID:soultek101,項目名稱:projectzulu1.7.10-pre-1.3a,代碼行數:23,代碼來源:BPOasisEdge.java

示例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);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:10,代碼來源:ForgeHooks.java

示例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;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:15,代碼來源:DungeonHooks.java

示例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;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:8,代碼來源:WorldServer.java

示例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);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:13,代碼來源:Biome.java

示例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();
}
 
開發者ID:alexandrage,項目名稱:CauldronGit,代碼行數:10,代碼來源:ForgeHooks.java

示例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);
}
 
開發者ID:alexandrage,項目名稱:CauldronGit,代碼行數:15,代碼來源:ChestGenHooks.java

示例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;
}
 
開發者ID:alexandrage,項目名稱:CauldronGit,代碼行數:15,代碼來源:DungeonHooks.java

示例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;
}
 
開發者ID:OreCruncher,項目名稱:Jiffy,代碼行數:11,代碼來源:WorldServer.java

示例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;
}
 
開發者ID:soultek101,項目名稱:projectzulu1.7.10-pre-1.3a,代碼行數:15,代碼來源:BPOasisGrass.java


注:本文中的net.minecraft.util.WeightedRandom.getRandomItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。