use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ActionAddMixedMaterialRecipe method apply.
@Override
public void apply() {
// Add the real recipe.
IRecipe irecipe = new RecipeMixedMaterialItem(tier, toolItem, recipe);
irecipe.setRegistryName(new ResourceLocation("crafttweaker", calculateName()));
ForgeRegistries.RECIPES.register(irecipe);
// Also add example recipes.
List<EnumMaterialTier> tiers = new ArrayList<>();
if (tier == null) {
for (EnumMaterialTier t : EnumMaterialTier.values()) {
tiers.add(t);
}
} else {
tiers.add(tier);
}
List<String> recipeLines = new ArrayList<>();
int index = 0;
while (index < recipe.length && recipe[index] instanceof String) {
recipeLines.add((String) recipe[index++]);
}
List<Object> extraParams = new ArrayList<>();
for (; index < recipe.length; ++index) {
extraParams.add(recipe[index]);
}
EnumMaterialTier[] arrayTiers = tiers.toArray(new EnumMaterialTier[tiers.size()]);
String[] arrayLines = recipeLines.toArray(new String[recipeLines.size()]);
Object[] arrayExtraParams = extraParams.toArray();
if (toolItem instanceof ITool)
ToolHelper.addExampleRecipe(toolItem, arrayTiers, arrayLines, arrayExtraParams);
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class RecipeApplyToolSoul method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
ItemStack tool = StackHelper.empty();
ItemStack soul = StackHelper.empty();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack stack = inv.getStackInSlot(i);
// Found a tool or armor piece?
if (stack.getItem() instanceof ITool || stack.getItem() instanceof IArmor) {
if (StackHelper.isValid(tool)) {
return StackHelper.empty();
}
tool = stack;
} else // Found a soul?
if (stack.getItem() instanceof ItemToolSoul) {
if (StackHelper.isValid(soul)) {
return StackHelper.empty();
}
soul = stack;
}
}
if (StackHelper.isEmpty(tool) || StackHelper.isEmpty(soul)) {
return StackHelper.empty();
}
// Does tool already have a soul?
if (SoulManager.getSoul(tool) != null) {
return StackHelper.empty();
}
// Is the soul valid?
ToolSoul toolSoul = ModItems.toolSoul.getSoul(soul);
if (toolSoul == null) {
return StackHelper.empty();
}
ItemStack result = StackHelper.safeCopy(tool);
// Have to change UUID to prevent soul duping.
// result.getTagCompound().removeTag(ToolHelper.NBT_UUID);
SoulManager.setSoul(result, toolSoul, true);
// Apply name, if applicable.
if (soul.hasDisplayName()) {
String name = soul.getDisplayName();
toolSoul.setName(name);
result.setStackDisplayName(name);
}
// Recalculate stats and return.
ToolHelper.recalculateStats(result);
return result;
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class SoulManager method writeToolSoulsToNBT.
public static void writeToolSoulsToNBT(EntityPlayer player) {
// Find all the players tools. Find the matching souls in the map.
int count = 0;
for (ItemStack tool : PlayerHelper.getNonEmptyStacks(player, true, true, true, s -> s.getItem() instanceof ITool || s.getItem() instanceof IArmor)) {
// UUID uuid = getSoulUUID(tool);
// ToolSoul soul = toolSoulMap.get(uuid);
ToolSoul soul = getSoul(tool);
if (soul != null) {
setSoul(tool, soul, false);
++count;
}
}
// SilentGems.logHelper.debug("Saved " + count + " tool(s) for " + player.getName());
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class SoulSkill method selectSkillToLearn.
public static SoulSkill selectSkillToLearn(ToolSoul soul, ItemStack tool) {
// if (soul.getLevel() == 5) {
// return SUPER_SKILL;
// }
Map<SoulSkill, Double> candidates = new LinkedHashMap<>();
// Create list of candidates
for (SoulSkill skill : SKILL_LIST.values()) {
if (skill.canLearn(soul, tool)) {
boolean favorsElement = false;
// Select a weight based on favored elements.
double weight = skill.favoredElements.length < 1 ? 20 : 7;
for (EnumSoulElement elem : skill.favoredElements) {
if (elem == soul.getPrimaryElement()) {
weight = 20;
favorsElement = true;
break;
} else if (elem == soul.getSecondaryElement()) {
weight = 15;
favorsElement = true;
break;
}
}
// Favors certain tool types?
if (skill.favoredType != EnumToolType.NONE) {
EnumToolType toolType = tool.getItem() instanceof ITool ? ((ITool) tool.getItem()).getToolType() : tool.getItem() instanceof IArmor ? ((IArmor) tool.getItem()).getToolType() : EnumToolType.NONE;
if (toolType == skill.favoredType) {
weight += 5;
}
}
// If skill has a median level, apply that to the weight.
if (skill.medianXpLevel > 0) {
int diff = Math.abs(soul.level - skill.medianXpLevel);
if (diff > 6) {
diff = 6;
}
weight -= 0.75 * diff;
}
// If a lower level of the skill is already known, reduce the weight.
if (soul.skills.containsKey(skill)) {
weight -= 2.5 * soul.skills.get(skill);
}
// Base weight diff, favors multiplier
weight += skill.weightDiff;
if (favorsElement) {
weight *= skill.favorWeightMulti;
}
// Make sure weight is at least 1.
if (weight < 1) {
weight = 1;
}
candidates.put(skill, weight);
}
}
// Seed based on soul elements, level, and tool UUID.
Random rand = new Random(soul.getPrimaryElement().ordinal() + (soul.getSecondaryElement().ordinal() << 4) + (soul.getLevel() << 8) + (ToolHelper.getUUID(tool).getLeastSignificantBits() << 16));
// Weighted random selection.
SoulSkill selected = null;
double bestValue = Double.MIN_VALUE;
for (SoulSkill skill : candidates.keySet()) {
double value = -Math.log(rand.nextFloat() / candidates.get(skill));
SilentGems.logHelper.debug(skill.id, candidates.get(skill), value, bestValue);
if (value > bestValue) {
bestValue = value;
selected = skill;
}
}
return selected;
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolStats method calculate.
public ToolStats calculate() {
if (parts.length == 0)
return this;
Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
// Head (main) parts
for (int i = 0; i < parts.length; ++i) {
ToolPart part = parts[i];
EnumMaterialGrade grade = grades[i];
float multi = (100 + grade.bonusPercent) / 100f;
durability += part.getDurability() * multi;
harvestSpeed += part.getHarvestSpeed() * multi;
meleeDamage += part.getMeleeDamage() * multi;
magicDamage += part.getMagicDamage() * multi;
meleeSpeed += part.getMeleeSpeed() * multi;
enchantability += part.getEnchantability() * multi;
chargeSpeed += part.getChargeSpeed() * multi;
blockingPower += part.getProtection() / 16f * multi;
harvestLevel = Math.max(harvestLevel, part.getHarvestLevel());
uniqueParts.add(part);
}
// Variety bonus
int variety = MathHelper.clamp(uniqueParts.size(), 1, GemsConfig.VARIETY_CAP);
float bonus = 1.0f + GemsConfig.VARIETY_BONUS * (variety - 1);
// Average head parts
durability = bonus * durability / parts.length;
harvestSpeed = bonus * harvestSpeed / parts.length;
meleeDamage = bonus * meleeDamage / parts.length;
magicDamage = bonus * magicDamage / parts.length;
meleeSpeed = bonus * meleeSpeed / parts.length;
chargeSpeed = bonus * chargeSpeed / parts.length;
enchantability = bonus * enchantability / parts.length;
blockingPower = Math.max(bonus * blockingPower / parts.length, ItemGemShield.MIN_BLOCKING_POWER);
// Tool class multipliers
if (tool.getItem() instanceof ITool) {
ITool itool = (ITool) tool.getItem();
durability *= itool.getDurabilityMultiplier();
harvestSpeed *= itool.getHarvestSpeedMultiplier();
}
// Rod, tip, grip
ToolPart partRod = ToolHelper.getConstructionRod(tool);
ToolPart partTip = ToolHelper.getConstructionTip(tool);
ToolPart partGrip = ToolHelper.getPart(tool, EnumPartPosition.ROD_GRIP);
for (ToolPart part : Lists.newArrayList(partRod, partTip, partGrip)) {
if (part != null) {
part.applyStats(this);
}
}
return this;
}
Aggregations