package com.thebrokenrail.energonrelics.block.entity.infuser; import com.thebrokenrail.energonrelics.util.WeightedList; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.util.ArrayList; import java.util.List; public class InfuserEntry { public final long cost; public final double successChance; private final InfuserAction[] success; private final InfuserAction[] fail; InfuserEntry(long cost, double successChance, InfuserAction[] success, InfuserAction[] fail) { this.cost = cost; this.successChance = successChance; this.success = success; this.fail = fail; } void run(World world, BlockPos pos) { boolean isSuccess = world.random.nextDouble() <= successChance; InfuserAction[] list; if (isSuccess) { list = success; } else { list = fail; } WeightedList weightedList = new WeightedList<>(); for (InfuserAction action : list) { weightedList.add(1, action); } weightedList.pick(world.random).run(world, pos); } @Environment(EnvType.CLIENT) public List getOutputItems(boolean isFail) { InfuserAction[] actionList = isFail ? fail : success; List list = new ArrayList<>(); for (InfuserAction action : actionList) { list.add(action.display()); } return list; } @Environment(EnvType.CLIENT) public double getSingleChance(boolean isFail) { return (1d / (double) (isFail ? fail.length : success.length)) * (isFail ? 1d - successChance : successChance); } }