use of net.silentchaos512.gear.crafting.recipe.salvage.SalvagingRecipe 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.crafting.recipe.salvage.SalvagingRecipe in project Silent-Gear by SilentChaos512.
the class SalvagerTileEntity method tick.
public static void tick(Level level, BlockPos pos, BlockState state, SalvagerTileEntity blockEntity) {
ItemStack input = blockEntity.getItem(0);
SalvagingRecipe recipe = blockEntity.getRecipe();
if (recipe != null) {
if (blockEntity.progress < BASE_WORK_TIME) {
++blockEntity.progress;
}
if (blockEntity.progress >= BASE_WORK_TIME && blockEntity.areAllOutputSlotsFree()) {
for (ItemStack stack : blockEntity.getSalvagedPartsWithChance(recipe, input)) {
int slot = blockEntity.getFreeOutputSlot();
if (slot > 0) {
blockEntity.setItem(slot, stack);
} else {
SilentGear.LOGGER.warn("Item lost in salvager: {}", stack);
}
}
blockEntity.progress = 0;
input.shrink(1);
if (input.isEmpty()) {
blockEntity.setItem(0, ItemStack.EMPTY);
}
}
} else {
blockEntity.progress = 0;
}
}
Aggregations