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


Java WeightedRandom類代碼示例

本文整理匯總了Java中net.minecraft.util.WeightedRandom的典型用法代碼示例。如果您正苦於以下問題:Java WeightedRandom類的具體用法?Java WeightedRandom怎麽用?Java WeightedRandom使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WeightedRandom類屬於net.minecraft.util包,在下文中一共展示了WeightedRandom類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: innerUpdate

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
@Override
protected void innerUpdate() {
    if (this.world.isRemote) return;
    if (currentWork >= getMaxWork()) {
        List<ItemStackWeightedItem> items = new ArrayList<>();
        LaserDrillEntry.LASER_DRILL_ENTRIES.forEach(entry -> {
            int increase = 0;
            for (int i = 0; i < lensItems.getSlots(); ++i) {
                if (!lensItems.getStackInSlot(i).isEmpty() && lensItems.getStackInSlot(i).getMetadata() == entry.getLaserMeta() && lensItems.getStackInSlot(i).getItem() instanceof LaserLensItem) {
                    if (((LaserLensItem) lensItems.getStackInSlot(i).getItem()).isInverted())
                        increase -= BlockRegistry.laserBaseBlock.getLenseChanceIncrease();
                    else increase += BlockRegistry.laserBaseBlock.getLenseChanceIncrease();
                }
            }
            items.add(new ItemStackWeightedItem(entry.getStack(), entry.getWeight() + increase));
        });
        ItemStack stack = WeightedRandom.getRandomItem(this.world.rand, items).getStack().copy();
        if (ItemHandlerHelper.insertItem(outItems, stack, true).isEmpty()) {
            ItemHandlerHelper.insertItem(outItems, stack, false);
        }
        currentWork = 0;
    }
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:24,代碼來源:LaserBaseTile.java

示例2: resetTimer

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
private void resetTimer()
{
    if (this.maxSpawnDelay <= this.minSpawnDelay)
    {
        this.spawnDelay = this.minSpawnDelay;
    }
    else
    {
        int i = this.maxSpawnDelay - this.minSpawnDelay;
        this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(i);
    }

    if (this.minecartToSpawn.size() > 0)
    {
        this.setRandomEntity((MobSpawnerBaseLogic.WeightedRandomMinecart)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.minecartToSpawn));
    }

    this.func_98267_a(1);
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:20,代碼來源:MobSpawnerBaseLogic.java

示例3: resetTimer

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
private void resetTimer()
{
    if (this.maxSpawnDelay <= this.minSpawnDelay)
    {
        this.spawnDelay = this.minSpawnDelay;
    }
    else
    {
        int i = this.maxSpawnDelay - this.minSpawnDelay;
        this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(i);
    }

    if (!this.potentialSpawns.isEmpty())
    {
        this.setNextSpawnData((WeightedSpawnerEntity)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.potentialSpawns));
    }

    this.broadcastEvent(1);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:20,代碼來源:MobSpawnerBaseLogic.java

示例4: resetTimer

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
private void resetTimer()
{
    if (this.maxSpawnDelay <= this.minSpawnDelay)
    {
        this.spawnDelay = this.minSpawnDelay;
    }
    else
    {
        int i = this.maxSpawnDelay - this.minSpawnDelay;
        this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(i);
    }

    if (!this.minecartToSpawn.isEmpty())
    {
        this.setNextSpawnData((WeightedSpawnerEntity)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.minecartToSpawn));
    }

    this.broadcastEvent(1);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:20,代碼來源:MobSpawnerBaseLogic.java

示例5: getRandomFishable

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
public static ItemStack getRandomFishable(Random rand, float chance, int luck, int speed)
{
    float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
    float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
    junkChance = MathHelper.func_76131_a(junkChance, 0.0F, 1.0F);
    treasureChance = MathHelper.func_76131_a(treasureChance, 0.0F, 1.0F);

    if (chance < junkChance)
    {
        return ((WeightedRandomFishable)WeightedRandom.func_76271_a(rand, junk)).func_150708_a(rand);
    }

    chance -= junkChance;
    if (chance < treasureChance)
    {
        return ((WeightedRandomFishable)WeightedRandom.func_76271_a(rand, treasure)).func_150708_a(rand);
    }

    chance -= treasureChance;
    // this is done in EntityFishHook.func_146033_f. more loot types expected?
    {
        return ((WeightedRandomFishable)WeightedRandom.func_76271_a(rand, fish)).func_150708_a(rand);
    }
}
 
開發者ID:SchrodingersSpy,項目名稱:TRHS_Club_Mod_2016,代碼行數:25,代碼來源:FishingHooks.java

示例6: resetTimer

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
private void resetTimer()
{
    if (this.maxSpawnDelay <= this.minSpawnDelay)
    {
        this.spawnDelay = this.minSpawnDelay;
    }
    else
    {
        int i = this.maxSpawnDelay - this.minSpawnDelay;
        this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(i);
    }

    if (this.potentialEntitySpawns != null && this.potentialEntitySpawns.size() > 0)
    {
        this.setRandomEntity((MobSpawnerBaseLogic.WeightedRandomMinecart)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.potentialEntitySpawns));
    }

    this.func_98267_a(1);
}
 
開發者ID:jtrent238,項目名稱:PopularMMOS-EpicProportions-Mod,代碼行數:20,代碼來源:BombySpawnerBaseLogic.java

示例7: 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

示例8: 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

示例9: getRandomFishable

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
public static ItemStack getRandomFishable(Random rand, float chance, int luck, int speed)
{
    float junkChance = 0.1F - luck * 0.025F - speed * 0.01F;
    float treasureChance = 0.05F + luck * 0.01F - speed * 0.01F;
    junkChance = MathHelper.clamp_float(junkChance, 0.0F, 1.0F);
    treasureChance = MathHelper.clamp_float(treasureChance, 0.0F, 1.0F);

    if (chance < junkChance)
    {
        return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, junk)).func_150708_a(rand);
    }

    chance -= junkChance;
    if (chance < treasureChance)
    {
        return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, treasure)).func_150708_a(rand);
    }

    chance -= treasureChance;
    // this is done in EntityFishHook.func_146033_f. more loot types expected?
    {
        return ((WeightedRandomFishable)WeightedRandom.getRandomItem(rand, fish)).func_150708_a(rand);
    }
}
 
開發者ID:alexandrage,項目名稱:CauldronGit,代碼行數:25,代碼來源:FishingHooks.java

示例10: resetTimer

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
private void resetTimer()
{
    if (this.maxSpawnDelay <= this.minSpawnDelay)
    {
        this.spawnDelay = this.minSpawnDelay;
    }
    else
    {
        int var10003 = this.maxSpawnDelay - this.minSpawnDelay;
        this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(var10003);
    }

    if (this.minecartToSpawn != null && this.minecartToSpawn.size() > 0)
    {
        this.setRandomMinecart((MobSpawnerBaseLogic.WeightedRandomMinecart)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.minecartToSpawn));
    }

    this.func_98267_a(1);
}
 
開發者ID:MinecraftModdedClients,項目名稱:Resilience-Client-Source,代碼行數:20,代碼來源:MobSpawnerBaseLogic.java

示例11: 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

示例12: 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

示例13: prepare

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
@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");
    }
}
 
開發者ID:Tonius,項目名稱:NEI-Integration,代碼行數:25,代碼來源:RecipeHandlerLaserDrill.java

示例14: loadAllRecipes

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
@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));
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:Tonius,項目名稱:NEI-Integration,代碼行數:19,代碼來源:RecipeHandlerLaserDrill.java

示例15: loadCraftingRecipes

import net.minecraft.util.WeightedRandom; //導入依賴的package包/類
@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));
                            }
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:Tonius,項目名稱:NEI-Integration,代碼行數:21,代碼來源:RecipeHandlerLaserDrill.java


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