This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/entity/infuser/InfuserEntry.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);
}
}