use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class MaterialInstance method readShorthand.
@Nullable
public static MaterialInstance readShorthand(String str) {
if (str.contains("#")) {
String[] parts = str.split("#");
ResourceLocation id = SilentGear.getIdWithDefaultNamespace(parts[0]);
IMaterial material = MaterialManager.get(id);
if (material != null) {
MaterialGrade grade = MaterialGrade.fromString(parts[1]);
return new MaterialInstance(material, grade);
}
return null;
}
ResourceLocation id = SilentGear.getIdWithDefaultNamespace(str);
IMaterial material = MaterialManager.get(id);
if (material != null) {
return new MaterialInstance(material);
}
return null;
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class CompoundPartItem method getName.
@Override
public Component getName(ItemStack stack) {
PartData part = PartData.from(stack);
MaterialInstance material = getPrimaryMaterial(stack);
if (part != null && material != null) {
TranslatableComponent nameText = new TranslatableComponent(this.getDescriptionId() + ".nameProper", material.getDisplayName(partType, ItemStack.EMPTY));
int nameColor = Color.blend(part.getColor(ItemStack.EMPTY), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
return TextUtil.withColor(nameText, nameColor);
}
return super.getName(stack);
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class TraitsCommand method getMaterialsWithTrait.
private static String getMaterialsWithTrait(ITrait trait) {
StringBuilder str = new StringBuilder();
boolean foundAny = false;
for (IMaterial material : MaterialManager.getValues(false)) {
MaterialInstance instance = MaterialInstance.of(material);
Collection<PartType> typesWithTrait = new ArrayList<>();
for (PartType partType : PartType.getValues()) {
Collection<TraitInstance> traits = instance.getTraits(partType);
for (TraitInstance inst : traits) {
if (inst.getTrait().equals(trait) && material.isVisible(partType)) {
typesWithTrait.add(partType);
break;
}
}
}
if (!typesWithTrait.isEmpty()) {
if (foundAny) {
str.append(", ");
}
foundAny = true;
str.append("**").append(instance.getDisplayName(PartType.MAIN).getString()).append("**").append(" _(").append(typesWithTrait.stream().map(pt -> pt.getDisplayName(0).getString()).collect(Collectors.joining(", "))).append(")_");
}
}
return str.toString();
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class PartMaterialIngredient method test.
@Override
public boolean test(@Nullable ItemStack stack) {
if (stack == null || stack.isEmpty())
return false;
MaterialInstance material = MaterialInstance.from(stack);
if (material == null)
return false;
int tier = material.getTier(this.partType);
return material.get().isCraftingAllowed(material, partType, gearType) && (categories.isEmpty() || material.hasAnyCategory(categories)) && tierMatches(tier);
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class CoatingSmithingRecipe method applyUpgrade.
@Override
protected ItemStack applyUpgrade(ItemStack gear, ItemStack upgradeItem) {
MaterialInstance material = MaterialInstance.from(upgradeItem);
if (material != null) {
GearType gearType = GearHelper.getType(gear);
if (gearType.isGear()) {
ItemStack result = gear.copy();
PartType.COATING.getCompoundPartItem(gearType).ifPresent(cpi -> {
ItemStack partItem = cpi.create(material, 1);
// Unfortunately this deletes the old part; can't get a player here
GearData.addOrReplacePart(result, Objects.requireNonNull(PartData.from(partItem)));
});
result.setDamageValue(0);
GearData.removeExcessParts(result, PartType.COATING);
// Crafting player is always null?
GearData.recalculateStats(result, ForgeHooks.getCraftingPlayer());
return result;
}
}
return ItemStack.EMPTY;
}
Aggregations