38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
|
|
|
import com.thebrokenrail.energonrelics.util.WeightedList;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
class InfuserEntry {
|
|
public final long cost;
|
|
public final double successChance;
|
|
public final InfuserAction[] success;
|
|
public 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<InfuserAction> weightedList = new WeightedList<>();
|
|
for (InfuserAction action : list) {
|
|
weightedList.add(1, action);
|
|
}
|
|
|
|
weightedList.pick(world.random).run(world, pos);
|
|
}
|
|
}
|