use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class CraftedMaterialItem method getColor.
@Override
public int getColor(ItemStack stack, int layer) {
IMaterialInstance material = getMaterial(stack);
IMaterialDisplay model = material.getDisplayProperties();
return model.getLayerColor(GearType.ALL, PartType.MAIN, material, layer);
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class RepairKitItem method addMaterial.
public boolean addMaterial(ItemStack repairKit, ItemStack materialStack) {
Tuple<IMaterialInstance, Float> tuple = getMaterialAndValue(materialStack);
if (tuple != null) {
IMaterialInstance mat = tuple.getA();
float value = tuple.getB();
if (getStoredMaterialAmount(repairKit) > getKitCapacity() - value) {
// Repair kit is full
return false;
}
String key = getShorthandKey(mat);
CompoundTag storageTag = repairKit.getOrCreateTagElement(NBT_STORAGE);
float current = storageTag.getFloat(key);
storageTag.putFloat(key, current + value);
return true;
}
return false;
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class SynergyUtils method getSynergy.
public static float getSynergy(PartType partType, List<? extends IMaterialInstance> materials, Collection<TraitInstance> traits) {
if (materials.isEmpty()) {
return 1;
}
// First, we add a bonus for the number of unique materials
double synergy = getBaseSynergy(materials);
// Second, reduce synergy for differences in certain properties
IMaterialInstance primary = materials.get(0);
final double primaryRarity = primary.getStat(partType, ItemStats.RARITY);
final double maxRarity = materials.stream().mapToDouble(m -> m.getStat(partType, ItemStats.RARITY)).max().orElse(0);
final int maxTier = materials.stream().mapToInt(m -> m.getTier(partType)).max().orElse(0);
for (IMaterialInstance material : getUniques(materials)) {
if (maxRarity > 0) {
float rarity = material.getStat(partType, ItemStats.RARITY);
synergy -= 0.005 * Math.abs(primaryRarity - rarity);
}
if (maxTier > 0) {
int tier = material.getTier(partType);
synergy -= 0.08 * Math.abs(maxTier - tier);
}
}
// Synergy traits
for (TraitInstance trait : traits) {
if (trait.getTrait() instanceof SynergyTrait) {
synergy = ((SynergyTrait) trait.getTrait()).apply(synergy, trait.getLevel());
}
}
return (float) Mth.clamp(synergy, MIN_VALUE, MAX_VALUE);
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class SGearJeiPlugin method registerItemSubtypes.
@Override
public void registerItemSubtypes(ISubtypeRegistration reg) {
reg.registerSubtypeInterpreter(ModItems.FRAGMENT.get(), (stack, context) -> {
IMaterialInstance material = FragmentItem.getMaterial(stack);
return material != null ? material.getId().toString() : "";
});
IIngredientSubtypeInterpreter<ItemStack> customMaterials = (stack, context) -> {
IMaterialInstance material = CustomMaterialItem.getMaterial(stack);
return material != null ? material.getId().toString() : "";
};
reg.registerSubtypeInterpreter(ModItems.CUSTOM_GEM.get(), customMaterials);
reg.registerSubtypeInterpreter(ModItems.CUSTOM_INGOT.get(), customMaterials);
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class CombineFragmentsRecipe method matches.
@Override
public boolean matches(CraftingContainer craftingInventory, Level world) {
// First, count the fragments. We want to fail fast.
int fragmentCount = 0;
for (int i = 0; i < craftingInventory.getContainerSize(); ++i) {
ItemStack stack = craftingInventory.getItem(i);
if (!stack.isEmpty()) {
if (stack.getItem() == ModItems.FRAGMENT.get()) {
++fragmentCount;
} else {
return false;
}
}
}
if (fragmentCount != 8) {
return false;
}
// Now, check that the fragments are all the same material.
IMaterialInstance first = null;
for (ItemStack stack : StackList.from(craftingInventory)) {
IMaterialInstance material = FragmentItem.getMaterial(stack);
if (material == null) {
return false;
}
if (first == null) {
first = material;
} else if (!InventoryUtils.canItemsStack(material.getItem(), first.getItem())) {
return false;
}
}
return first != null;
}
Aggregations