本文整理匯總了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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
}
示例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");
}
}
示例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));
}
}
}
}
}
}
}
示例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));
}
}
}
}
}
}
}
}