public void setRepresentativeItem(ItemStack representativeItem) { if(representativeItem == null || representativeItem.isEmpty()) { this.representativeItem = ItemStack.EMPTY; } else if(matches(representativeItem).isPresent()) { this.representativeItem = representativeItem; } else { TinkerRegistry.log.warn("Itemstack {} cannot represent material {} since it is not associated with the material!", representativeItem.toString(), identifier); } }
protected Material getMaterial(ItemStack... stacks) { for(ItemStack stack : stacks) { if(stack.isEmpty()) { continue; } // material-item? if(stack.getItem() instanceof IMaterialItem) { return ((IMaterialItem) stack.getItem()).getMaterial(stack); } } // regular item, check if it belongs to a material for(Material material : TinkerRegistry.getAllMaterials()) { if(material.matches(stacks).isPresent()) { return material; } } // no material found return null; }
public void materialTooltip(ItemTooltipEvent event) { // check if the item belongs to a material for(Material material : TinkerRegistry.getAllMaterials()) { if(material.matches(event.getItemStack()).isPresent()) { event.getToolTip().add(TextFormatting.DARK_GRAY + material.getLocalizedName()); } } } }
public void setShard(@Nonnull ItemStack stack) { if(stack.isEmpty()) { this.shardItem = ItemStack.EMPTY; } else { Optional<RecipeMatch.Match> matchOptional = matches(stack); if(matchOptional.isPresent()) { RecipeMatch.Match match = matchOptional.get(); if(match.amount == VALUE_Shard) { this.shardItem = stack; if(representativeItem.isEmpty()) { this.setRepresentativeItem(shardItem.copy()); } } else { TinkerRegistry.log.warn("Itemstack {} cannot be shard of material {} since it does not have the correct value! (is {}, has to be {})", representativeItem.toString(), identifier, match.amount, VALUE_Shard); } } else { TinkerRegistry.log.warn("Itemstack {} cannot be shard of material {} since it is not associated with the material!", stack.toString(), identifier); } } }
protected int calculateRepairAmount(List<Material> materials, NonNullList<ItemStack> repairItems) { Set<Material> materialsMatched = Sets.newHashSet(); float durability = 0f; // try to match each material once for(int index : getRepairParts()) { Material material = materials.get(index); if(materialsMatched.contains(material)) { continue; } // custom repairing durability += repairCustom(material, repairItems) * getRepairModifierForPart(index); Optional<RecipeMatch.Match> matchOptional = material.matches(repairItems); if(matchOptional.isPresent()) { RecipeMatch.Match match = matchOptional.get(); HeadMaterialStats stats = material.getStats(MaterialTypes.HEAD); if(stats != null) { materialsMatched.add(material); durability += ((float) stats.durability * (float) match.amount * getRepairModifierForPart(index)) / 144f; RecipeMatch.removeMatch(repairItems, match); } } } durability *= 1f + ((float) materialsMatched.size() - 1) / 9f; return (int) durability; }
continue; Optional<RecipeMatch.Match> newMatch = material.matches(materialItems, part.getCost()); if(!newMatch.isPresent()) { continue;