use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
Greetings.greetPlayer(event.player);
SilentGems.instance.logHelper.info("Recalculating tool and armor stats for " + event.player.getDisplayNameString());
// Recalculate tool stats.
for (ItemStack stack : PlayerHelper.getNonEmptyStacks(event.player)) {
if (stack != null) {
if (stack.getItem() instanceof ITool)
ToolHelper.recalculateStats(stack);
if (stack.getItem() instanceof IArmor)
ArmorHelper.recalculateStats(stack);
}
}
}
use of net.silentchaos512.gems.api.IArmor 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.IArmor in project SilentGems by SilentChaos512.
the class RecipeDecorateArmor 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;
// Find armor 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 IArmor) {
tool = stack;
toolRow = row;
toolCol = col;
}
}
}
// Found armor piece?
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);
int validPartCount = (StackHelper.isEmpty(west) ? 0 : 1) + (StackHelper.isEmpty(north) ? 0 : 1) + (StackHelper.isEmpty(east) ? 0 : 1) + (StackHelper.isEmpty(south) ? 0 : 1);
if (!checkIsDecorationMaterial(west) || !checkIsDecorationMaterial(north) || !checkIsDecorationMaterial(east) || !checkIsDecorationMaterial(south)) {
return StackHelper.empty();
}
// Check for other pieces (invalid for armor) and get all repair values.
EnumMaterialTier toolTier = ArmorHelper.getArmorTier(tool);
ToolPart part;
int partsFound = 0;
for (i = 0; i < inv.getSizeInventory(); ++i) {
stack = inv.getStackInSlot(i);
if (StackHelper.isValid(stack) && !(stack.getItem() instanceof IArmor)) {
part = ToolPartRegistry.fromDecoStack(stack);
// Invalid part or not a part?
if (part == null || !(part instanceof ToolPartMain)) {
return StackHelper.empty();
}
// Found a part.
++partsFound;
// Add to total repair value.
repairValue += part.getRepairAmount(tool, stack);
}
}
// Make sure we got no other parts.
if (partsFound != validPartCount) {
return StackHelper.empty();
}
ItemStack result = ArmorHelper.decorateArmor(tool, west, north, east, south);
// Repair.
ItemHelper.attemptDamageItem(result, -repairValue, SilentGems.random);
// Recalculate stats.
ArmorHelper.recalculateStats(result);
ArmorHelper.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.IArmor 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.IArmor in project SilentGems by SilentChaos512.
the class ToolPartFlint method getColor.
@Override
public int getColor(ItemStack toolOrArmor, IPartPosition position, int animationFrame) {
Item item = toolOrArmor.getItem();
boolean isTextureUncolored = position == ToolPartPosition.ROD_DECO || item instanceof IArmor || item instanceof ItemGemBow || item instanceof ItemGemShield;
return isTextureUncolored || ToolHelper.isBroken(toolOrArmor) ? COLOR : 0xFFFFFF;
}
Aggregations