Search in sources :

Example 6 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class ItemMedicineBag method trySetEffect.

private EnumActionResult trySetEffect(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileTotemPole) {
        TotemEffect effect = ((TileTotemPole) tile).getEffect();
        if (effect != null) {
            if (!effect.isPortable()) {
                if (world.isRemote)
                    player.sendStatusMessage(new TextComponentTranslation("totemicmisc.effectNotPortable", new TextComponentTranslation(effect.getUnlocalizedName())), true);
                return EnumActionResult.FAIL;
            }
            ItemStack newStack = stack.copy();
            NBTTagCompound tag = ItemUtil.getOrCreateTag(newStack);
            tag.setString(MED_BAG_TOTEM_KEY, effect.getRegistryName().toString());
            if (tag.getInteger(MED_BAG_CHARGE_KEY) != -1)
                tag.setInteger(MED_BAG_CHARGE_KEY, 0);
            player.setHeldItem(hand, newStack);
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileTotemPole(pokefenn.totemic.tileentity.totem.TileTotemPole) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) StateTotemEffect(pokefenn.totemic.tileentity.totem.StateTotemEffect) ItemStack(net.minecraft.item.ItemStack)

Example 7 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class ItemTotemWhittlingKnife method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.isSneaking()) {
        player.setHeldItem(hand, changeIndex(stack, true));
        return EnumActionResult.SUCCESS;
    } else {
        IBlockState state = world.getBlockState(pos);
        WoodVariant wood = WoodVariant.fromLog(state);
        if (wood == null) {
            // Fall back to oak if it is an unrecognized log type
            if (state.getBlock().isWood(world, pos) && state.getBlock() != ModBlocks.stripped_cedar_log)
                wood = WoodVariant.OAK;
            else
                return EnumActionResult.FAIL;
        }
        TotemEffect effect = getCarvingEffect(stack);
        if (effect != null) {
            world.setBlockState(pos, ModBlocks.totem_pole.getDefaultState().withProperty(BlockTotemPole.WOOD, wood), 0);
            TileTotemPole tile = (TileTotemPole) world.getTileEntity(pos);
            tile.setEffect(effect);
            tile.markForUpdate();
        } else {
            world.setBlockState(pos, ModBlocks.totem_base.getDefaultState().withProperty(BlockTotemBase.WOOD, wood), 3);
        }
        state = world.getBlockState(pos);
        state.getBlock().onBlockPlacedBy(world, pos, state, player, stack);
        stack.damageItem(1, player);
        return EnumActionResult.SUCCESS;
    }
}
Also used : WoodVariant(pokefenn.totemic.lib.WoodVariant) TileTotemPole(pokefenn.totemic.tileentity.totem.TileTotemPole) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 8 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class StateTotemEffect method update.

@Override
public void update() {
    World world = tile.getWorld();
    for (Multiset.Entry<TotemEffect> entry : tile.getTotemEffectSet().entrySet()) {
        TotemEffect effect = entry.getElement();
        if (world.getTotalWorldTime() % effect.getInterval() == 0)
            effect.effect(world, tile.getPos(), tile, entry.getCount());
    }
    // Diminish melody over time, about 5 minutes to fully deplete
    if (musicAmount > 0 && world.getTotalWorldTime() % 47 == 0) {
        musicAmount--;
        tile.markDirty();
    }
    if (musicAdded && !world.isRemote && world.getTotalWorldTime() % 20 == 0) {
        NetworkHandler.sendAround(new PacketTotemEffectMusic(tile.getPos(), musicAmount), tile, 32);
        musicAdded = false;
    }
    if (world.isRemote && world.getTotalWorldTime() % 40 == 0)
        spawnParticles();
}
Also used : PacketTotemEffectMusic(pokefenn.totemic.network.server.PacketTotemEffectMusic) Multiset(com.google.common.collect.Multiset) World(net.minecraft.world.World) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 9 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class TileTotemBase method calculateTotemEffects.

private void calculateTotemEffects() {
    totemEffectList.clear();
    totemEffects.clear();
    for (int i = 0; i < MAX_POLE_SIZE; i++) {
        TileEntity tile = world.getTileEntity(pos.up(i + 1));
        if (tile instanceof TileTotemPole) {
            TotemEffect effect = ((TileTotemPole) tile).getEffect();
            totemEffectList.add(effect);
            if (effect != null)
                totemEffects.add(effect);
        } else
            break;
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 10 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class StateTotemEffect method tick.

@Override
public void tick() {
    Level world = tile.getLevel();
    long gameTime = world.getGameTime();
    if (gameTime % tile.getCommonTotemEffectInterval() == 0) {
        for (Multiset.Entry<TotemEffect> entry : tile.getTotemEffects().entrySet()) {
            TotemEffect effect = entry.getElement();
            if (gameTime % effect.getInterval() == 0) {
                effect.effect(world, tile.getBlockPos(), entry.getCount(), this);
            }
        }
    }
}
Also used : Level(net.minecraft.world.level.Level) Multiset(com.google.common.collect.Multiset) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Aggregations

TotemEffect (pokefenn.totemic.api.totem.TotemEffect)10 Multiset (com.google.common.collect.Multiset)3 ArrayList (java.util.ArrayList)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Level (net.minecraft.world.level.Level)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 TotemWoodType (pokefenn.totemic.api.TotemWoodType)2 TotemPoleBlock (pokefenn.totemic.block.totem.TotemPoleBlock)2 TileTotemPole (pokefenn.totemic.tileentity.totem.TileTotemPole)2 HashMultiset (com.google.common.collect.HashMultiset)1 IntMath (com.google.common.math.IntMath)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1