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;
}
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;
}
}
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();
}
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;
}
}
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);
}
}
}
}
Aggregations