Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Some safety checks for the randomly generated weapons. Also no more s…
Browse files Browse the repository at this point in the history
…cythes and cleavers in bonus chests.
  • Loading branch information
bonii-xx committed Aug 23, 2014
1 parent 6363365 commit 41597fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Expand Up @@ -13,9 +13,9 @@ public class IguanaWorldGen {
public void init(FMLInitializationEvent event)
{
// add some a starting weapon to bonus chests!
ChestGenHooks.addItem(ChestGenHooks.BONUS_CHEST, new RandomWeaponChestContent(1,1, 10, 0,0, HarvestLevels._1_flint));
ChestGenHooks.addItem(ChestGenHooks.BONUS_CHEST, new RandomWeaponChestContent(0,1, 10, 0,0, HarvestLevels._1_flint, 3));

// awesome dungeon loot!
ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new RandomWeaponChestContent(0,1, 2, 1,2, HarvestLevels._5_diamond));
ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new RandomWeaponChestContent(0,1, 2, 1,2, HarvestLevels._5_diamond, 4));
}
}
Expand Up @@ -2,6 +2,7 @@

import iguanaman.iguanatweakstconstruct.leveling.RandomBonuses;
import iguanaman.iguanatweakstconstruct.util.Log;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -24,16 +25,18 @@ public class RandomWeaponChestContent extends WeightedRandomChestContent {
private int minModifiers;
private int maxModifiers;
private int maxQuality;
private int maxParts;
private List<Integer> materialIDs;

private List<ToolRecipe> weapons;

public RandomWeaponChestContent(int minCount, int maxCount, int weight, int minModifiers, int maxModifiers, int maxQuality) {
public RandomWeaponChestContent(int minCount, int maxCount, int weight, int minModifiers, int maxModifiers, int maxQuality, int maxParts) {
super(TinkerTools.broadsword, 0, minCount, maxCount, weight);

this.minModifiers = minModifiers;
this.maxModifiers = maxModifiers;
this.maxQuality = maxQuality;
this.maxParts = maxParts;

// determine all available weapons
weapons = new ArrayList<ToolRecipe>();
Expand All @@ -49,17 +52,28 @@ protected ItemStack[] generateChestContent(Random random, IInventory newInventor
int count = this.theMinimumChanceToGenerateItem + (random.nextInt(this.theMaximumChanceToGenerateItem - this.theMinimumChanceToGenerateItem + 1));
ItemStack[] ret = new ItemStack[count];

int endlessLoopPreventer = 9999;

while(count > 0) {
// this can only happen if the confis are derped so hard that it's basically impossible to create a weapon
if(endlessLoopPreventer-- <= 0)
return new ItemStack[]{new ItemStack(Items.stick)};

// determine type
ToolRecipe recipe = weapons.get(random.nextInt(weapons.size()));
ToolCore type = recipe.getType();

if(type.getPartAmount() > maxParts)
continue;

if(materialIDs == null)
prepareMaterials();;
prepareMaterials();

ItemStack weapon = null;
int tries = 0;
// try to build the weapon
do {
tries++;
// get components
ItemStack[] parts = new ItemStack[] {null,null,null,null};

Expand All @@ -82,7 +96,10 @@ protected ItemStack[] generateChestContent(Random random, IInventory newInventor
}
// build the tool
weapon = ToolBuilder.instance.buildTool(parts[0], parts[1], parts[2], parts[3], "");
} while(weapon == null);
} while(weapon == null && tries < 200);
// wasn't possible to build this weapon. try another one
if(weapon == null)
continue;

int modCount = minModifiers + (random.nextInt(maxModifiers - minModifiers + 1));
while(modCount-- > 0)
Expand Down

0 comments on commit 41597fb

Please sign in to comment.