use of net.silentchaos512.gems.api.tool.part.ToolPartRod in project SilentGems by SilentChaos512.
the class RecipeDecorateTool method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
int i;
int toolRow = 0;
int toolCol = 0;
ItemStack stack;
ItemStack tool = StackHelper.empty();
int repairValue = 0;
int ammoValue = 0;
// Find tool position
for (int row = 0; row < inv.getWidth(); ++row) {
for (int col = 0; col < inv.getHeight(); ++col) {
stack = inv.getStackInRowAndColumn(row, col);
if (StackHelper.isValid(stack) && stack.getItem() instanceof ITool) {
tool = stack;
toolRow = row;
toolCol = col;
}
}
}
// Found a tool?
if (StackHelper.isEmpty(tool)) {
return StackHelper.empty();
}
// Check adjacent materials
ItemStack west = inv.getStackInRowAndColumn(toolRow - 1, toolCol);
ItemStack north = inv.getStackInRowAndColumn(toolRow, toolCol - 1);
ItemStack east = inv.getStackInRowAndColumn(toolRow + 1, toolCol);
ItemStack south = inv.getStackInRowAndColumn(toolRow, toolCol + 1);
if (!checkIsDecorationMaterial(west) || !checkIsDecorationMaterial(north) || !checkIsDecorationMaterial(east) || !checkIsDecorationMaterial(south)) {
return StackHelper.empty();
}
// Check other materials and get all repair values.
List<ItemStack> otherMats = Lists.newArrayList();
EnumMaterialTier toolTier = ToolHelper.getToolTier(tool);
for (i = 0; i < inv.getSizeInventory(); ++i) {
stack = inv.getStackInSlot(i);
if (StackHelper.isValid(stack) && !(stack.getItem() instanceof ITool)) {
ToolPart part = ToolPartRegistry.fromDecoStack(stack);
// Invalid part or not a part?
if (part == null) {
return StackHelper.empty();
}
// Valid for tool tier?
if (!part.validForToolOfTier(toolTier) && !(part instanceof ToolPartMain)) {
return StackHelper.empty();
}
int repairAmount = part.getRepairAmount(tool, stack);
if (repairAmount > 0) {
repairValue += repairAmount;
++ammoValue;
}
otherMats.add(stack);
}
}
if (otherMats.isEmpty()) {
return StackHelper.empty();
}
ItemStack result = StackHelper.safeCopy(tool);
result = ToolHelper.decorateTool(tool, west, north, east, south);
boolean lockedStats = result.getTagCompound().getBoolean(ToolHelper.NBT_LOCK_STATS);
// Other materials
for (ItemStack other : otherMats) {
ToolPart part = ToolPartRegistry.fromDecoStack(other);
EnumMaterialGrade grade = EnumMaterialGrade.fromStack(other);
if (StackHelper.isValid(result) && part instanceof ToolPartRod) {
ToolHelper.setRenderPart(result, part, grade, ToolPartPosition.ROD);
} else if (part instanceof ToolPartTip) {
if (lockedStats) {
// Tips change stats, so using them with locked tools is not allowed.
return StackHelper.empty();
}
ToolHelper.setConstructionTip(result, part);
}
}
if (repairValue > 0) {
// Makes odd repair values line up better (2 polished stone on pickaxe makes a full repair, etc.)
repairValue += 1;
}
// Tool repair multiplier
repairValue *= ((ITool) tool.getItem()).getRepairMultiplier();
// Repair.
ItemHelper.attemptDamageItem(result, -repairValue, SilentGems.instance.random);
// Restore ammo.
if (result.getItem() instanceof IAmmoTool && ammoValue > 0) {
IAmmoTool ammoTool = (IAmmoTool) result.getItem();
ammoTool.addAmmo(result, ammoValue * GemsConfig.TOMAHAWK_AMMO_PER_MAT);
}
// Recalculate stats.
ToolHelper.recalculateStats(result);
ToolHelper.incrementStatRedecorated(result, 1);
// Change the UUID so that rendering cache updates immediately for recipe output.
result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Most");
result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Least");
ToolHelper.getUUID(result);
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPartRod in project SilentGems by SilentChaos512.
the class ToolHelper method decorate.
private static ItemStack decorate(ItemStack tool, ItemStack material, EnumDecoPos pos) {
if (// Something went wrong
StackHelper.isEmpty(tool))
return StackHelper.empty();
if (// No material in the slot is OK.
StackHelper.isEmpty(material))
return tool;
// South - 'Bottom' (head right or 2)
if (tool.getItem() instanceof ItemGemShield) {
// @formatter:off
if (pos == EnumDecoPos.NORTH)
pos = EnumDecoPos.SOUTH;
else if (pos == EnumDecoPos.EAST)
pos = EnumDecoPos.NORTH;
else if (pos == EnumDecoPos.SOUTH)
pos = EnumDecoPos.EAST;
}
// No deco bit on certain (mostly non-super) rods.
if (pos == EnumDecoPos.SOUTH && !(tool.getItem() instanceof ItemGemShield)) {
ToolPartRod partRod = (ToolPartRod) getConstructionRod(tool);
if (partRod == null || !partRod.supportsDecoration())
return tool;
}
// Get the tool part, making sure it exists.
ToolPart part = ToolPartRegistry.fromDecoStack(material);
if (part == null)
return null;
// Only main parts (like gems) work
if (!(part instanceof ToolPartMain))
return tool;
ItemStack result = StackHelper.safeCopy(tool);
setTagPart(result, pos.nbtKey, part, EnumMaterialGrade.fromStack(material));
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPartRod in project SilentGems by SilentChaos512.
the class GemsClientEvents method onTooltipForToolRod.
private void onTooltipForToolRod(ItemTooltipEvent event, ItemStack stack, ToolPart part, boolean ctrlDown, boolean shiftDown) {
int index = 1;
final String sep = loc.getMiscText("Tooltip.Separator");
List<String> list = event.getToolTip();
ToolPartRod.Stats stats = ((ToolPartRod) part).getStats();
// Tool Rod indicator
list.add(index++, loc.getMiscText("ToolPart.Rod"));
if (ctrlDown) {
// Compatible tiers
String line = "";
for (EnumMaterialTier tier : part.getCompatibleTiers()) {
if (!line.isEmpty())
line += ", ";
line += tier.getLocalizedName();
}
list.add(index++, loc.getMiscText("ToolPart.ValidTiers"));
list.add(index++, " " + line);
list.add(index++, sep);
TextFormatting color = TextFormatting.GOLD;
list.add(index++, color + TooltipHelper.getAsColoredPercentage("HarvestSpeed", stats.harvestSpeedMulti));
// list.add(index++, color + TooltipHelper.get("HarvestLevel", part.getHarvestLevel()));
color = TextFormatting.DARK_GREEN;
list.add(index++, color + TooltipHelper.getAsColoredPercentage("MeleeDamage", stats.meleeDamageMulti));
list.add(index++, color + TooltipHelper.getAsColoredPercentage("MagicDamage", stats.magicDamageMulti));
// list.add(index++, color + TooltipHelper.get("MeleeSpeed", (int) (part.getMeleeSpeed() * 100)));
color = TextFormatting.BLUE;
list.add(index++, color + TooltipHelper.getAsColoredPercentage("Durability", stats.durabilityMulti));
list.add(index++, color + TooltipHelper.getAsColoredPercentage("Enchantability", stats.enchantabilityMulti));
list.add(index++, sep);
// Debug info
if (shiftDown) {
list.add(index++, TextFormatting.DARK_GRAY + "* Part key: " + part.getKey());
}
} else {
list.add(index++, loc.getMiscText("PressCtrl"));
}
}
use of net.silentchaos512.gems.api.tool.part.ToolPartRod in project SilentGems by SilentChaos512.
the class GemsClientEvents method onTooltip.
@SubscribeEvent
public void onTooltip(ItemTooltipEvent event) {
boolean ctrlDown = KeyTracker.isControlDown();
boolean shiftDown = KeyTracker.isShiftDown();
ItemStack stack = event.getItemStack();
ToolPart part = StackHelper.isValid(stack) ? ToolPartRegistry.fromStack(stack) : null;
if (part != null && !part.isBlacklisted(stack)) {
if (part instanceof ToolPartRod) {
onTooltipForToolRod(event, stack, part, ctrlDown, shiftDown);
} else if (part instanceof ToolPartMain) {
onTooltipForToolMaterial(event, stack, part, ctrlDown, shiftDown);
} else if (part instanceof ArmorPartFrame) {
// TODO: Localization
event.getToolTip().add(TextFormatting.GOLD + "Armor Frame");
}
}
}
Aggregations