Search in sources :

Example 1 with CapabilityDivination

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");
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException)

Example 2 with CapabilityDivination

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();
            }
        }
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) LootContext(net.minecraft.world.storage.loot.LootContext) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with CapabilityDivination

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();
            }
        }
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) LootContext(net.minecraft.world.storage.loot.LootContext) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with CapabilityDivination

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);
                }
            }
        }
    }
}
Also used : CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) IFortune(com.bewitchment.api.divination.IFortune) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with CapabilityDivination

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();
            }
        }
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) LootContext(net.minecraft.world.storage.loot.LootContext) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CapabilityDivination (com.bewitchment.common.core.capability.divination.CapabilityDivination)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 Block (net.minecraft.block.Block)3 ItemStack (net.minecraft.item.ItemStack)3 LootContext (net.minecraft.world.storage.loot.LootContext)3 LootTable (net.minecraft.world.storage.loot.LootTable)3 IFortune (com.bewitchment.api.divination.IFortune)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 CommandException (net.minecraft.command.CommandException)1 ResourceLocation (net.minecraft.util.ResourceLocation)1