@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; } }
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); }
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); }
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); }
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); } }
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); }
/** 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); } } } }
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; }
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); } }
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); }
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); }
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(); }
@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"); } }
@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)); } } } } } } }
@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)); } } } } } } } }
@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)); } } } } } } }
/** * Sets the delay before a new spawn (base delay of 200 + random number up to 600). */ private void updateDelay() { if (this.maxSpawnDelay <= this.minSpawnDelay) { this.delay = this.minSpawnDelay; } else { this.delay = this.minSpawnDelay + this.worldObj.rand.nextInt(this.maxSpawnDelay - this.minSpawnDelay); } if (this.spawnList != null && this.spawnList.size() > 0) { this.spawnerTags = (TileEntityLimitedMobSpawnData) WeightedRandom.getRandomItem(this.worldObj.rand, this.spawnList); this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, 0); }
@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; }
@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; }
public static void func_76293_a(Random p_76293_0_, WeightedRandomChestContent[] p_76293_1_, IInventory p_76293_2_, int p_76293_3_) { for(int var4 = 0; var4 < p_76293_3_; ++var4) { WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.func_76274_a(p_76293_0_, p_76293_1_); int var6 = var5.field_76295_d + p_76293_0_.nextInt(var5.field_76296_e - var5.field_76295_d + 1); if(var5.field_76297_b.func_77976_d() >= var6) { ItemStack var7 = var5.field_76297_b.func_77946_l(); var7.field_77994_a = var6; p_76293_2_.func_70299_a(p_76293_0_.nextInt(p_76293_2_.func_70302_i_()), var7); } else { for(int var9 = 0; var9 < var6; ++var9) { ItemStack var8 = var5.field_76297_b.func_77946_l(); var8.field_77994_a = 1; p_76293_2_.func_70299_a(p_76293_0_.nextInt(p_76293_2_.func_70302_i_()), var8); } } } }
public static void func_76294_a(Random p_76294_0_, WeightedRandomChestContent[] p_76294_1_, TileEntityDispenser p_76294_2_, int p_76294_3_) { for(int var4 = 0; var4 < p_76294_3_; ++var4) { WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.func_76274_a(p_76294_0_, p_76294_1_); int var6 = var5.field_76295_d + p_76294_0_.nextInt(var5.field_76296_e - var5.field_76295_d + 1); if(var5.field_76297_b.func_77976_d() >= var6) { ItemStack var7 = var5.field_76297_b.func_77946_l(); var7.field_77994_a = var6; p_76294_2_.func_70299_a(p_76294_0_.nextInt(p_76294_2_.func_70302_i_()), var7); } else { for(int var9 = 0; var9 < var6; ++var9) { ItemStack var8 = var5.field_76297_b.func_77946_l(); var8.field_77994_a = 1; p_76294_2_.func_70299_a(p_76294_0_.nextInt(p_76294_2_.func_70302_i_()), var8); } } } }
private void func_98273_j() { 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 != null && this.minecartToSpawn.size() > 0) { this.setRandomMinecart((WeightedRandomMinecart)WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.minecartToSpawn)); } this.func_98267_a(1); }
private ItemStack getFishingResult() { float f = this.worldObj.rand.nextFloat(); int i = EnchantmentHelper.getLuckOfSeaModifier(this.angler); int j = EnchantmentHelper.getLureModifier(this.angler); float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F; float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F; f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F); f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F); if (f < f1) { this.angler.triggerAchievement(StatList.junkFishedStat); return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, JUNK)).getItemStack(this.rand); } else { f = f - f1; if (f < f2) { this.angler.triggerAchievement(StatList.treasureFishedStat); return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, TREASURE)).getItemStack(this.rand); } else { float f3 = f - f2; this.angler.triggerAchievement(StatList.fishCaughtStat); return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, FISH)).getItemStack(this.rand); } } }
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int p_77513_2_, boolean allowTreasure) { List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList(); Item item = itemStackIn.getItem(); int i = item.getItemEnchantability(); if (i <= 0) { return list; } else { p_77513_2_ = p_77513_2_ + 1 + randomIn.nextInt(i / 4 + 1) + randomIn.nextInt(i / 4 + 1); float f = (randomIn.nextFloat() + randomIn.nextFloat() - 1.0F) * 0.15F; p_77513_2_ = MathHelper.clamp(Math.round((float)p_77513_2_ + (float)p_77513_2_ * f), 1, Integer.MAX_VALUE); List<EnchantmentData> list1 = getEnchantmentDatas(p_77513_2_, itemStackIn, allowTreasure); if (!list1.isEmpty()) { list.add(WeightedRandom.getRandomItem(randomIn, list1)); while (randomIn.nextInt(50) <= p_77513_2_) { removeIncompatible(list1, (EnchantmentData)Util.getLastElement(list)); if (list1.isEmpty()) { break; } list.add(WeightedRandom.getRandomItem(randomIn, list1)); p_77513_2_ /= 2; } } return list; } }