Search in sources :

Example 21 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SkillAreaMiner method breakExtraBlock.

public boolean breakExtraBlock(ItemStack tool, World world, BlockPos pos, EntityPlayer playerEntity, BlockPos refPos) {
    if (world.isAirBlock(pos))
        return false;
    if (!(playerEntity instanceof EntityPlayerMP)) {
        return false;
    }
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    EntityPlayerMP player = (EntityPlayerMP) playerEntity;
    if (!isToolEffective(tool, world, pos, state)) {
        return false;
    }
    IBlockState refState = world.getBlockState(refPos);
    // float refStrength = ForgeHooks.blockStrength(state, player, world, refPos); // Throws an exception in some cases.
    float refStrength = player.getDigSpeed(refState, refPos) / refState.getBlockHardness(world, refPos) / 30f;
    // But this one doesn't?
    float strength = ForgeHooks.blockStrength(state, player, world, pos);
    // LogHelper.list(Block.getIdFromBlock(refBlock), refStrength, strength, refStrength / strength);
    if (!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
        return false;
    }
    int xpDropped = ForgeHooks.onBlockBreakEvent(world, player.interactionManager.getGameType(), player, pos);
    boolean canceled = xpDropped == -1;
    if (canceled) {
        return false;
    }
    if (player.capabilities.isCreativeMode) {
        block.onBlockHarvested(world, pos, state, player);
        if (block.removedByPlayer(state, world, pos, player, false)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
        }
        if (!world.isRemote) {
            player.connection.sendPacket(new SPacketBlockChange(world, pos));
        }
        return true;
    }
    tool.onBlockDestroyed(world, state, pos, player);
    // Add soul XP
    ToolSoul soul = SoulManager.getSoul(tool);
    if (soul != null) {
        SoulManager.addSoulXp(soul.getXpForBlockHarvest(world, pos, state), tool, player);
    }
    if (!world.isRemote) {
        if (block.removedByPlayer(state, world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
            block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), tool);
            block.dropXpOnBlockBreak(world, pos, xpDropped);
        }
        player.connection.sendPacket(new SPacketBlockChange(world, pos));
    } else {
        int meta = block.getMetaFromState(state);
        world.playEvent(2001, pos, Block.getIdFromBlock(block) + (meta << 12));
        if (block.removedByPlayer(state, world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
        }
        tool.onBlockDestroyed(world, state, pos, player);
    // if (tool.stackSize == 0) {
    // PlayerHelper.removeItem(player, tool);
    // }
    }
    return true;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Example 22 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SkillLumberjack method activate.

@Override
public boolean activate(ItemStack tool, EntityPlayer player, BlockPos pos) {
    World world = player.world;
    IBlockState state = world.getBlockState(pos);
    // Must be an axe
    if (state == null || state.getBlock() == null) {
        return false;
    }
    // Must be super tool with special enabled.
    if (ToolHelper.getToolTier(tool).ordinal() < EnumMaterialTier.SUPER.ordinal() || !ToolHelper.isSpecialAbilityEnabled(tool)) {
        return false;
    }
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    if (state.getBlock().isWood(world, pos) || state.getMaterial() == Material.SPONGE) {
        if (detectTree(world, x, y, z, state.getBlock())) {
            // Don't allow in creative mode.
            if (player.capabilities.isCreativeMode) {
                return false;
            }
            // Does player have enough chaos?
            PlayerData data = PlayerDataHandler.get(player);
            int cost = getCost(tool, player, pos);
            if (data.chaos >= cost) {
                data.drainChaos(cost);
            } else {
                String msg = SilentGems.localizationHelper.getLocalizedString("skill", "all.insufficientChaos");
                ChatHelper.sendStatusMessage(player, msg, true);
                return false;
            }
            ToolSoul soul = SoulManager.getSoul(tool);
            TreeBreakResult result = new TreeBreakResult();
            result.soul = soul;
            breakTree(result, world, x, y, z, x, y, z, tool, state, player);
            ToolHelper.incrementStatBlocksMined(tool, result.blocksBroken);
            if (soul != null)
                soul.addXp(result.xpEarned, tool, player);
            return true;
        }
    }
    return false;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 23 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulManager method getSoul.

@Nullable
public static ToolSoul getSoul(ItemStack tool) {
    if (StackHelper.isEmpty(tool) || !(tool.getItem() instanceof ITool || tool.getItem() instanceof IArmor) || ToolHelper.isExampleItem(tool)) {
        return null;
    }
    UUID uuid = ToolHelper.getSoulUUID(tool);
    // Soul already in map?
    ToolSoul soul = map.get(uuid);
    if (soul != null) {
        return soul;
    }
    // Does soul exist in NBT?
    ToolHelper.initRootTag(tool);
    if (!tool.getTagCompound().hasKey(ToolHelper.NBT_ROOT_TOOL_SOUL)) {
        return null;
    }
    // Read from NBT, place in map for fast access.
    soul = ToolSoul.readFromNBT(ToolHelper.getRootTag(tool, ToolHelper.NBT_ROOT_TOOL_SOUL));
    if (uuid == null) {
        ToolHelper.setRandomSoulUUID(tool);
        uuid = ToolHelper.getSoulUUID(tool);
    }
    map.put(uuid, soul);
    // SilentGems.logHelper.debug("Put tool soul " + soul + " in the map! Total count: " + map.size());
    return soul;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) UUID(java.util.UUID) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) Nullable(javax.annotation.Nullable)

Example 24 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulManager method onPlayerTick.

@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
    // Max air is 300, so 30 per bubble
    if (!event.player.world.isRemote && event.player.getAir() < 5) {
        EntityPlayer player = event.player;
        ItemStack mainHand = player.getHeldItemMainhand();
        ItemStack offHand = player.getHeldItemOffhand();
        ToolSoul soulMain = getSoul(mainHand);
        ToolSoul soulOff = getSoul(offHand);
        // Get highest level of Aquatic on either main or off hand.
        int levelMain = soulMain == null ? 0 : soulMain.getSkillLevel(SoulSkill.AQUATIC);
        int levelOff = soulOff == null ? 0 : soulOff.getSkillLevel(SoulSkill.AQUATIC);
        ToolSoul soulToDrain = levelMain > levelOff ? soulMain : soulOff;
        int aquaticLevel = Math.max(levelMain, levelOff);
        if (aquaticLevel > 0) {
            int amountToRestore = 60 * aquaticLevel;
            player.setAir(player.getAir() + amountToRestore);
            player.world.playSound(null, player.getPosition(), SoundEvents.ENTITY_PLAYER_HURT_DROWN, SoundCategory.PLAYERS, 1f, 1f);
            soulToDrain.addActionPoints(-SoulSkill.AQUATIC.apCost);
        }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulManager method onGetBreakSpeed.

@SubscribeEvent
public void onGetBreakSpeed(PlayerEvent.BreakSpeed event) {
    EntityPlayer player = event.getEntityPlayer();
    ItemStack mainHand = player.getHeldItemMainhand();
    // Overridden by the Gravity enchantment.
    if (EnchantmentHelper.getEnchantmentLevel(ModEnchantments.gravity, mainHand) > 0)
        return;
    ToolSoul soul = getSoul(mainHand);
    if (soul != null) {
        // Aquatic or Aerial?
        int aquatic = soul.getSkillLevel(SoulSkill.AQUATIC);
        int aerial = soul.getSkillLevel(SoulSkill.AERIAL);
        if (aquatic > 0 && player.isInsideOfMaterial(Material.WATER))
            event.setNewSpeed(event.getNewSpeed() * (5f / (SoulSkill.AQUATIC.maxLevel - aquatic + 1)));
        else if (aerial > 0 && (!player.onGround || player.capabilities.isFlying))
            event.setNewSpeed(event.getNewSpeed() * (5f / (SoulSkill.AERIAL.maxLevel - aerial + 1)));
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)25 ItemStack (net.minecraft.item.ItemStack)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 IArmor (net.silentchaos512.gems.api.IArmor)5 ITool (net.silentchaos512.gems.api.ITool)5 UUID (java.util.UUID)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)4 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)3 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)3 SoulSkill (net.silentchaos512.gems.lib.soul.SoulSkill)3 LinkedHashMap (java.util.LinkedHashMap)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 ToolStats (net.silentchaos512.gems.api.tool.ToolStats)2 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)2