use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class CompoundPartModelOverrideList method getOverrideModel.
private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
List<MaterialLayer> layers = new ArrayList<>();
PartData part = PartData.from(stack);
MaterialInstance primaryMaterial = CompoundPartItem.getPrimaryMaterial(stack);
if (part != null && primaryMaterial != null) {
addWithBlendedColor(layers, part, primaryMaterial, stack);
}
return model.bake(layers, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class SalvagerTileEntity method getSalvagedPartsWithChance.
private Collection<ItemStack> getSalvagedPartsWithChance(SalvagingRecipe recipe, ItemStack stack) {
double lossRate = getLossRate(stack);
SilentGear.LOGGER.debug("Loss rate for '{}': {}", stack, lossRate);
ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
for (ItemStack part : recipe.getPossibleResults(this)) {
ItemStack copy = part.copy();
int count = copy.getCount();
PartData partData = PartData.from(part);
double partLossRate = partData != null ? partData.get().getSalvageLossRate(partData, stack, lossRate) : lossRate;
for (int i = 0; i < count; ++i) {
if (MathUtils.tryPercentage(SilentGear.RANDOM, partLossRate)) {
copy.shrink(1);
}
}
if (!copy.isEmpty()) {
builder.add(copy);
}
}
return builder.build();
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method getBlendedColor.
@Deprecated
private static int getBlendedColor(ItemStack gear, List<PartData> parts) {
int[] componentSums = new int[3];
int maxColorSum = 0;
int colorCount = 0;
int partCount = parts.size();
for (int i = 0; i < partCount; ++i) {
PartData part = parts.get(i);
int color = part.get().getColor(part, gear, 0, 0);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
// Add earlier colors multiple times, to give them greater weight
int colorWeight = (partCount - i) * (partCount - i);
for (int j = 0; j < colorWeight; ++j) {
maxColorSum += Math.max(r, Math.max(g, b));
componentSums[0] += r;
componentSums[1] += g;
componentSums[2] += b;
++colorCount;
}
}
if (colorCount > 0) {
int r = componentSums[0] / colorCount;
int g = componentSums[1] / colorCount;
int b = componentSums[2] / colorCount;
float maxAverage = (float) maxColorSum / (float) colorCount;
float max = (float) Math.max(r, Math.max(g, b));
r = (int) ((float) r * maxAverage / max);
g = (int) ((float) g * maxAverage / max);
b = (int) ((float) b * maxAverage / max);
int finalColor = (r << 8) + g;
finalColor = (finalColor << 8) + b;
return finalColor;
}
return Color.VALUE_WHITE;
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method addUpgradePart.
/**
* Add an upgrade part to the gear item. Depending on the upgrade, this may replace an existing
* part.
* <p>
* TODO: Should we return something to indicate if the upgrade cannot be applied or replaces an
* existing upgrade?
*
* @param gear The gear item
* @param part The upgrade part
*/
public static void addUpgradePart(ItemStack gear, PartData part) {
if (!GearHelper.isGear(gear))
return;
PartDataList parts = getConstructionParts(gear);
// Make sure the upgrade is valid for the gear type
if (!part.get().canAddToGear(gear, part))
return;
// Only one allowed of this type? Remove existing if needed.
if (part.get().replacesExistingInPosition(part)) {
parts.removeIf(p -> p.getType() == part.getType());
}
// Allow the part to make additional changes if needed
part.onAddToGear(gear);
// Other upgrades allow no exact duplicates, but any number of total upgrades
for (PartData partInList : parts) {
if (partInList.get() == part.get()) {
return;
}
}
parts.add(part);
writeConstructionParts(gear, parts);
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method addPart.
public static void addPart(ItemStack gear, PartData part) {
PartDataList parts = getConstructionParts(gear);
parts.add(part);
writeConstructionParts(gear, parts);
part.onAddToGear(gear);
}
Aggregations