use of com.bewitchment.common.core.capability.divination.CapabilityDivination in project Bewitchment by Um-Mitternacht.
the class CommandFortuneActivator method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (sender instanceof EntityPlayer) {
CapabilityDivination dc = ((EntityPlayer) sender).getCapability(CapabilityDivination.CAPABILITY, null);
if (dc.getFortune() != null) {
if (dc.isActive()) {
throw new CommandException("commands.enable_fortune.error.already_active");
}
dc.setActive();
sender.sendMessage(new TextComponentTranslation("commands.enable_fortune.success"));
} else {
throw new CommandException("commands.enable_fortune.error.no_fortune");
}
} else {
throw new CommandException("commands.error.no_console");
}
}
use of com.bewitchment.common.core.capability.divination.CapabilityDivination in project Bewitchment by Um-Mitternacht.
the class FortuneShinies method onDig.
@SubscribeEvent
public void onDig(BreakEvent evt) {
CapabilityDivination cap = evt.getPlayer().getCapability(CapabilityDivination.CAPABILITY, null);
if (cap.getFortune() == this) {
if (cap.isActive()) {
Block block = evt.getState().getBlock();
if (block == Blocks.STONE || block == Blocks.SANDSTONE || block == Blocks.RED_SANDSTONE || block == Blocks.END_STONE || block == Blocks.NETHERRACK || block == Blocks.COBBLESTONE || block == Blocks.MOSSY_COBBLESTONE) {
LootTable lt = evt.getWorld().getLootTableManager().getLootTableFromLocation(ModLootTables.JEWELS);
LootContext lc = (new LootContext.Builder((WorldServer) evt.getWorld()).withLuck(evt.getPlayer().getLuck()).withPlayer(evt.getPlayer())).build();
List<ItemStack> spawn = lt.generateLootForPools(evt.getPlayer().getRNG(), lc);
spawn.forEach(s -> spawn(s, evt.getWorld(), evt.getPos()));
cap.setRemovable();
}
}
}
}
use of com.bewitchment.common.core.capability.divination.CapabilityDivination in project Bewitchment by Um-Mitternacht.
the class FortuneIron method onDig.
@SubscribeEvent
public void onDig(BreakEvent evt) {
CapabilityDivination cap = evt.getPlayer().getCapability(CapabilityDivination.CAPABILITY, null);
if (cap.getFortune() == this) {
if (cap.isActive()) {
Block block = evt.getState().getBlock();
if (block == Blocks.STONE || block == Blocks.SANDSTONE || block == Blocks.RED_SANDSTONE || block == Blocks.END_STONE || block == Blocks.NETHERRACK || block == Blocks.COBBLESTONE || block == Blocks.MOSSY_COBBLESTONE) {
LootTable lt = evt.getWorld().getLootTableManager().getLootTableFromLocation(ModLootTables.METALS);
LootContext lc = (new LootContext.Builder((WorldServer) evt.getWorld()).withLuck(evt.getPlayer().getLuck()).withPlayer(evt.getPlayer())).build();
List<ItemStack> spawn = lt.generateLootForPools(evt.getPlayer().getRNG(), lc);
spawn.forEach(s -> spawn(s, evt.getWorld(), evt.getPos()));
cap.setRemovable();
}
} else {
if (evt.getPlayer().getRNG().nextInt(100) == 0) {
// On average, enable after digging 100 blocks after getting the read
cap.setActive();
}
}
}
}
use of com.bewitchment.common.core.capability.divination.CapabilityDivination in project Bewitchment by Um-Mitternacht.
the class DivinationEvents method onLivingTick.
@SubscribeEvent
public void onLivingTick(PlayerTickEvent evt) {
if (!evt.player.world.isRemote && evt.phase == Phase.END) {
CapabilityDivination data = evt.player.getCapability(CapabilityDivination.CAPABILITY, null);
IFortune f = data.getFortune();
if (f != null) {
if (data.isRemovable()) {
data.setFortune(null);
} else {
if (f.canShouldBeAppliedNow(evt.player)) {
data.setActive();
}
if (data.isActive()) {
if (f.apply(evt.player))
data.setFortune(null);
}
}
}
}
}
use of com.bewitchment.common.core.capability.divination.CapabilityDivination in project Bewitchment by Um-Mitternacht.
the class FortuneTreasure method onDig.
@SubscribeEvent
public void onDig(BreakEvent evt) {
CapabilityDivination cap = evt.getPlayer().getCapability(CapabilityDivination.CAPABILITY, null);
if (cap.getFortune() == this) {
if (cap.isActive()) {
Block block = evt.getState().getBlock();
if (block == Blocks.DIRT || block == Blocks.GRASS || block == Blocks.SAND || block == Blocks.MYCELIUM || block == Blocks.GRAVEL || block == Blocks.SOUL_SAND) {
LootTable lt = evt.getWorld().getLootTableManager().getLootTableFromLocation(ModLootTables.METALS);
LootContext lc = (new LootContext.Builder((WorldServer) evt.getWorld()).withLuck(evt.getPlayer().getLuck()).withPlayer(evt.getPlayer())).build();
List<ItemStack> spawn = lt.generateLootForPools(evt.getPlayer().getRNG(), lc);
spawn.forEach(s -> spawn(s, evt.getWorld(), evt.getPos()));
cap.setRemovable();
}
}
}
}
Aggregations