use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolHelper method getUUID.
/**
* Gets the tool's or armor's UUID. If it currently does not have a UUID, one will be created if appropriate.
*
* @param tool
* The tool or armor stack. The stack's item must implement either ITool or IArmor.
* @return The UUID of the tool or armor, or null if the item is not allowed to have one.
*/
@Nullable
public static UUID getUUID(ItemStack tool) {
if (!(tool.getItem() instanceof ITool || tool.getItem() instanceof IArmor)) {
return null;
}
initRootTag(tool);
if (!tool.getTagCompound().hasUniqueId(NBT_UUID)) {
UUID uuid = UUID.randomUUID();
tool.getTagCompound().setUniqueId(NBT_UUID, uuid);
return uuid;
}
return tool.getTagCompound().getUniqueId(NBT_UUID);
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolRandomizer method randomizeArmor.
public ItemStack randomizeArmor(ItemStack armor, float superChance) {
if (!ToolHelper.hasNoConstruction(armor))
return armor;
IArmor itool = (IArmor) armor.getItem();
// Regular or super?
boolean superTier = SilentGems.random.nextFloat() < superChance;
// How many gems?
boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
boolean gem4 = gem3 && SilentGems.random.nextFloat() < FOURTH_GEM_CHANCE;
// Gem array
EnumGem[] gems;
if (gem4) {
gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
} else if (gem3) {
EnumGem g1 = EnumGem.getRandom();
gems = new EnumGem[] { g1, EnumGem.getRandom(), EnumGem.getRandom(), g1 };
} else if (gem2) {
EnumGem g1 = EnumGem.getRandom();
EnumGem g2 = EnumGem.getRandom();
gems = new EnumGem[] { g1, g2, g1, g2 };
} else {
EnumGem g1 = EnumGem.getRandom();
gems = new EnumGem[] { g1, g1, g1, g1 };
}
// Crafting stack array
ItemStack[] craftingStacks = new ItemStack[gems.length];
for (int i = 0; i < craftingStacks.length; ++i) {
craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
}
ItemStack frame = ModItems.armorFrame.getFrameForArmorPiece((ItemArmor) armor.getItem(), superTier ? EnumMaterialTier.SUPER : EnumMaterialTier.REGULAR);
ItemStack temp = ArmorHelper.constructArmor(armor.getItem(), frame, craftingStacks);
// Set name
String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
armor.setTagCompound(temp.getTagCompound());
return temp;
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolRandomizer method randomize.
public ItemStack randomize(ItemStack tool, float superChance) {
if (tool.getItem() instanceof IArmor)
return randomizeArmor(tool, superChance);
if (!(tool.getItem() instanceof ITool) || !ToolHelper.hasNoConstruction(tool))
return tool;
ITool itool = (ITool) tool.getItem();
// Regular or super?
boolean superTier = !itool.getValidTiers().contains(EnumMaterialTier.REGULAR) || (SilentGems.random.nextFloat() < superChance && itool.getValidTiers().contains(EnumMaterialTier.SUPER));
// How many gems?
boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
// Gem array
EnumGem[] gems;
if (gem3) {
// 3 gems
gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
} else if (gem2) {
// 2 gems (3rd = 1st)
EnumGem g1 = EnumGem.getRandom();
EnumGem g2 = EnumGem.getRandom();
if (tool.getItem() == ModItems.sword)
gems = new EnumGem[] { g1, g2 };
else
gems = new EnumGem[] { g1, g2, g1 };
} else {
// 1 gem
EnumGem g1 = EnumGem.getRandom();
gems = new EnumGem[] { g1, g1, g1 };
}
// Crafting stack array
ItemStack[] craftingStacks = new ItemStack[gems.length];
for (int i = 0; i < craftingStacks.length; ++i) {
craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
}
// Select rod
ItemStack rod;
if (superTier) {
ItemStack[] choices = new ItemStack[] { ModItems.craftingMaterial.toolRodGold, ModItems.craftingMaterial.toolRodSilver, ModItems.craftingMaterial.toolRodIron };
rod = choices[SilentGems.random.nextInt(choices.length)];
} else {
ItemStack[] choices = new ItemStack[] { new ItemStack(Items.STICK), new ItemStack(Items.BONE), ModItems.craftingMaterial.toolRodIron };
rod = choices[SilentGems.random.nextInt(choices.length)];
}
ItemStack temp = ToolHelper.constructTool(tool.getItem(), rod, craftingStacks);
if (temp.getItem() instanceof ItemGemKatana)
temp = ((ItemGemKatana) temp.getItem()).addDefaultGrip(temp);
// Set name
String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
tool.setTagCompound(temp.getTagCompound());
return temp;
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolRenderHelper method updateModelCache.
@Override
public void updateModelCache(ItemStack toolOrArmor) {
if (ToolHelper.hasUUID(toolOrArmor)) {
UUID uuid = ToolHelper.getUUID(toolOrArmor);
IModelData modelData = toolOrArmor.getItem() instanceof ITool ? new ToolModelData(toolOrArmor) : new ArmorModelData(toolOrArmor);
if (ToolHelper.isExampleItem(toolOrArmor)) {
modelCacheExamples.put(uuid, modelData);
} else {
modelCache.put(uuid, modelData);
}
}
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolPartMain method getRepairAmount.
@Override
public int getRepairAmount(ItemStack toolOrArmor, ItemStack partRep) {
if (isBlacklisted(partRep)) {
return 0;
}
if (GemsConfigHC.REPAIR_LOGIC != GemsConfigHC.EnumRepairLogic.CLASSIC) {
ToolPart repairPart = ToolPartRegistry.fromStack(partRep);
EnumMaterialGrade repairGrade = EnumMaterialGrade.fromStack(partRep);
float amount = repairPart.getDurability() * (100 + repairGrade.bonusPercent) / 100;
// Since armor has much lower durability per item, we'll adjust down for armor.
if (toolOrArmor.getItem() instanceof IArmor) {
amount /= 2f;
}
switch(GemsConfigHC.REPAIR_LOGIC) {
case HARD_MATERIAL_BASED:
return (int) (amount / 4f);
case MATERIAL_BASED:
return (int) (amount / 2f);
case NOT_ALLOWED:
return 0;
default:
break;
}
}
// Classic repair logic.
int max = toolOrArmor.getMaxDamage();
float scale = 0.0f;
EnumMaterialTier partTier = getTier();
EnumMaterialTier stackTier = toolOrArmor.getItem() instanceof ITool ? ToolHelper.getToolTier(toolOrArmor) : (toolOrArmor.getItem() instanceof IArmor ? ArmorHelper.getArmorTier(toolOrArmor) : null);
if (stackTier == null)
return 0;
int toolTierIndex = ToolHelper.getToolTier(toolOrArmor).ordinal();
int partTierIndex = partTier.ordinal();
scale = REPAIR_VALUES[toolTierIndex][partTierIndex];
return (int) (scale * max);
}
Aggregations